Skip to main content
196

Search Lumen

Find components, APIs, guides, and recipes.

GitHub
Web docs
Overlays and menus

usePopover

Manages popover disclosure — toggle, outside click close, Escape key dismiss, and arrow key navigation through focusable panel items.

Live component preview · Astro

Explore Popover

Try the component this hook connects to. The preview uses the Astro adapter; the React example below uses usePopover.

React usage

Import from @santi020k/lumen-react and spread the controller props onto the matching components.

tsxusePopover example
import { Button, Popover, PopoverTrigger, PopoverPanel } from '@santi020k/lumen-react'
import { usePopover } from '@santi020k/lumen-react'

export function NotificationsPopover() {
  const popover = usePopover()

  return (
    <Popover {...popover.rootProps}>
      <PopoverTrigger {...popover.triggerProps}>Notifications</PopoverTrigger>
      <PopoverPanel {...popover.panelProps}>
        <p>No new notifications.</p>
      </PopoverPanel>
    </Popover>
  )
}
import { Button, Popover, PopoverTrigger, PopoverPanel } from '@santi020k/lumen-react'
import { usePopover } from '@santi020k/lumen-react'

export function NotificationsPopover() {
  const popover = usePopover()

  return (
    <Popover {...popover.rootProps}>
      <PopoverTrigger {...popover.triggerProps}>Notifications</PopoverTrigger>
      <PopoverPanel {...popover.panelProps}>
        <p>No new notifications.</p>
      </PopoverPanel>
    </Popover>
  )
}

Load @santi020k/lumen-react/styles.css once in your application. With React Server Components, put 'use client' at the top of the module that calls the hook. Follow the React setup guide for the framework boundary.

Options

PropertyTypeDefaultDescription
defaultOpenbooleanfalseInitial open state for uncontrolled usage.
openboolean-Controlled open state.
onOpenChange(open: boolean) => void-Callback fired when the open state changes.
idstringautoExplicit id for the panel element.

Controller return values

PropertyTypeDescription
rootPropsLumenProps<"div">Spread onto the root wrapper element.
triggerPropsLumenProps<"button">Spread onto the trigger button. Binds click, ArrowDown, Enter, and Space key handlers.
panelPropsLumenProps<"div">Spread onto the popover panel. Includes Escape, arrow, Home, and End key handlers.
rootRefRefObject<HTMLElement>Ref to the root wrapper.
triggerRefRefObject<HTMLElement>Ref to the trigger element.
panelRefRefObject<HTMLElement>Ref to the panel element.
openbooleanCurrent open state.
close() => voidClose the popover.
toggle() => voidToggle the popover.
setOpenDispatch<SetStateAction<boolean>>State setter for controlled usage.
Web docsFull catalog