Skip to content

Popover ​

A headless, accessible Popover component for React. Composed of multiple subcomponents for flexible usage.

Features ​

  • Accessible (keyboard navigation, ARIA attributes)
  • Headless (no styles, fully customizable)
  • Composable API (Popover, PopoverTrigger, PopoverPanel)
  • Context-powered hooks

Installation ​

bash
npm install react-headless-ui-kit

Usage ​

tsx
import {
  Popover,
  PopoverTrigger,
  PopoverPanel,
  usePopover,
} from "react-headless-ui-kit";

function ExamplePopover() {
  return (
    <Popover>
      <PopoverTrigger
        id="popover-trigger"
        style={{
          padding: "0.5rem 1rem",
          border: "1px solid #ccc",
          borderRadius: 4,
          background: "#f9f9f9",
          cursor: "pointer",
        }}
      >
        Open Popover
      </PopoverTrigger>
      <PopoverPanel
        style={{
          marginTop: "1px",
          background: "white",
          border: "1px solid #ddd",
          borderRadius: 4,
          padding: "0.5rem",
          boxShadow: "0 2px 6px rgba(0,0,0,0.15)",
          width: "150px",
        }}
      >
        <ul style={{ listStyle: "none", margin: 0, padding: 0 }}>
          <li>Profile</li>
          <li>Settings</li>
          <li>Logout</li>
        </ul>
      </PopoverPanel>
    </Popover>
  );
}

API Reference ​

<Popover /> ​

PropTypeDescription
childrenReactNodePopover content

<PopoverTrigger /> ​

Button to open/close the popover.

PropTypeDescription
childrenReactNodeTrigger content

<PopoverPanel /> ​

Popover panel container. Handles ARIA attributes and visibility.

PropTypeDescription
childrenReactNodePanel content

usePopover() ​

Hook to access popover context values inside subcomponents.

Return valueDescription
openPopover open state
setOpenSetter for open
triggerRefRef to trigger button
panelRefRef to panel element

Accessibility ​

  • Pressing Escape closes the popover.
  • ARIA attributes are set for screen readers.
  • Click outside closes the popover.

Customization ​

All components are unstyled. Use your own styles via className or style props.