Skip to Content
Neshel-UI
Components

Popover

Anchored, non-modal floating content with collision handling.

Client component ("use client")

Purpose

Popover shows rich content next to a trigger — details, small forms, pickers. It is non-modal: the page stays interactive.

Import

import.tsx
import {
  Popover,
  PopoverAnchor,
  PopoverClose,
  PopoverContent,
  PopoverTrigger,
} from "@neshel-ui/components";

Usage

Preview: popover-basic
Preview theme
popover-basic.tsx
import {
  Button,
  Popover,
  PopoverClose,
  PopoverContent,
  PopoverTrigger,
} from "@neshel-ui/components";
import { Stack } from "@neshel-ui/layout";
import { Heading, Paragraph } from "@neshel-ui/typography";

export default function PopoverBasic() {
  return (
    <Popover>
      <PopoverTrigger asChild>
        <Button variant="outline">Plan details</Button>
      </PopoverTrigger>
      <PopoverContent side="bottom" align="start">
        <Stack space="3" className="max-w-64">
          <Heading as="h3" size="base">
            Team plan
          </Heading>
          <Paragraph size="sm" tone="muted">
            Ten seats, shared themes and priority support.
          </Paragraph>
          <PopoverClose asChild>
            <Button size="sm">Got it</Button>
          </PopoverClose>
        </Stack>
      </PopoverContent>
    </Popover>
  );
}

API

PopoverProps

Also accepts the props of: @radix-ui/react-popover.

PopoverContentProps

PopoverContentProps
PropTypeDefaultDescription
containerHTMLElement | nulldocument.bodyPortal target (default document.body, wrapped with the trigger's theme).
refRef<HTMLDivElement>——

Also accepts the props of: @radix-ui/react-dismissable-layer, @radix-ui/react-popover, @radix-ui/react-popper, @radix-ui/react-primitive, React DOM attributes.

PopoverTriggerProps

PopoverTriggerProps
PropTypeDefaultDescription
refRef<HTMLButtonElement>——

Also accepts the props of: @radix-ui/react-primitive, React DOM attributes.

PopoverAnchorProps

PopoverAnchorProps
PropTypeDefaultDescription
refRef<HTMLDivElement>——

Also accepts the props of: @radix-ui/react-popper, @radix-ui/react-primitive, React DOM attributes.

PopoverCloseProps

PopoverCloseProps
PropTypeDefaultDescription
refRef<HTMLButtonElement>——

Also accepts the props of: @radix-ui/react-primitive, React DOM attributes.

PopoverContent positioning: side, align, sideOffset (default 6) and the collision props. PopoverAnchor positions the content against another element than the trigger.

Selection inside a Popover

A Combobox (or Select) inside a Popover renders its listbox inside the popover. Escape closes the listbox first, then the popover; choosing an option keeps the popover open.

Preview: popover-combobox
Preview theme
popover-combobox.tsx
"use client";
import {
  Button,
  Combobox,
  Label,
  Popover,
  PopoverContent,
  PopoverTrigger,
} from "@neshel-ui/components";
import { Stack } from "@neshel-ui/layout";
import { useState } from "react";

const assignees = [
  { value: "ana", label: "Ana Rojas" },
  { value: "luis", label: "Luis Mora" },
  { value: "mei", label: "Mei Tanaka" },
  { value: "sam", label: "Sam Ortiz" },
];

/** A Combobox inside a Popover: Escape closes the listbox first, then the popover. */
export default function PopoverCombobox() {
  const [assignee, setAssignee] = useState<string | null>(null);
  const name = assignees.find((item) => item.value === assignee)?.label;
  return (
    <Popover>
      <PopoverTrigger asChild>
        <Button variant="outline">{name ? `Assigned to ${name}` : "Assign"}</Button>
      </PopoverTrigger>
      <PopoverContent align="start">
        <Stack space="2" className="w-64">
          <Label htmlFor="popover-assignee">Assignee</Label>
          <Combobox
            id="popover-assignee"
            items={assignees}
            value={assignee}
            onValueChange={setAssignee}
            placeholder="Search people"
          />
        </Stack>
      </PopoverContent>
    </Popover>
  );
}

Accessibility

The trigger exposes aria-expanded and aria-controls. Focus moves into the content on open and returns to the trigger on close. Give the content a heading or label when it is more than a sentence.

Keyboard

KeyAction
Enter / SpaceOpen from the trigger
TabMove through the content
EscapeClose (innermost layer)

Common mistakes

  • Using a Popover for a short hint on hover: use a Tooltip.
  • Using it for a menu of commands: use a DropdownMenu.
Edit on GitHub

On this page