Skip to content
TopClass UI

Popover

An anchored panel for a link, a field or an action. It flips and shrinks to the room it has instead of overflowing.

client - size not measured yet

Popover

client - size not measured yet

An anchored panel for a link, a field or an action. It flips and shrinks to the room it has instead of overflowing.

Install

Try it

placement
delay
closeDelay

The code

popover.tsx
import { Button } from 'topclassui/button'
import { PopoverDescription, PopoverPopup, PopoverRoot, PopoverTitle, PopoverTrigger } from 'topclassui/popover'

<PopoverRoot>
  <PopoverTrigger openOnHover render={<Button variant="outline">Share</Button>} />
  <PopoverPopup>
    <PopoverTitle>Share this page</PopoverTitle>
    <PopoverDescription>Anyone with the link can read it. Only your team can edit.</PopoverDescription>
    <Button size="sm" className="self-start">Copy link</Button>
  </PopoverPopup>
</PopoverRoot>

A tooltip is plain text only: its children are typed as text. Anything with a link or a control is a Popover.

Every state

5 states

Import from the package

topclassui/popover
import { PopoverRoot, PopoverClose, PopoverDescription, PopoverPopup, PopoverTitle, PopoverTrigger } from 'topclassui/popover'

Install once:npm i topclassui@beta zod

Examples

  • Six flat parts and no bare Popover: PopoverRoot, PopoverTrigger, PopoverPopup, PopoverTitle, PopoverDescription and PopoverClose.
  • placement on PopoverPopup: twelve values, bottom by default. It opens on the other side when its own has no room, and stays 8 px inside the screen.
  • The popup is 280 px wide and never taller than the room it has; past that it scrolls inside itself. For another width, pass a class.
  • A PopoverClose with nothing in it is the x, and you place it.
  • openOnHover on the trigger lets the pointer open it too, after delay (300 ms) and until closeDelay (0 ms), both clamped to 0 to 10000.
  • Put a form inside PopoverPopup, never render={<form />} on it, and give it an action or an onSubmit.
basic
with-close
hover
with-form
modal
placements
long-content
In Arabic, right to left

Props

PopoverRoot

The props of PopoverRoot
PropTypeDefaultLimitsDescription
childrenReactNode--The trigger and the popup. With no trigger, hold open in a client file.

PopoverClose

No props of its own: it takes the attributes of the element it renders.

PopoverDescription

No props of its own: it takes the attributes of the element it renders.

PopoverPopup

The props of PopoverPopup
PropTypeDefaultLimitsDescription
placementtop | top-start | top-end | bottom | bottom-start | bottom-end | start | start-top | start-bottom | end | end-top | end-bottom"bottom"-PopoverPopup: the side and alignment it opens at; start and end mirror in Arabic.

PopoverTitle

No props of its own: it takes the attributes of the element it renders.

PopoverTrigger

The props of PopoverTrigger
PropTypeDefaultLimitsDescription
closeDelaynumber, min 0, max 100000min 0, max 10000PopoverTrigger, with openOnHover: milliseconds it stays open after the pointer leaves, clamped.
delaynumber, min 0, max 10000300min 0, max 10000PopoverTrigger, with openOnHover: milliseconds of hover before it opens, clamped.

Keyboard and accessibility

The keyboard of Popover
KeysWhat it does
EnterSpaceOn the trigger, opens the popover. Focus lands on the first control, or on the popup.
TabPast the last control, closes the popover and goes on down the page.
Shift+TabFrom the first control, goes back to the trigger.
EscapeCloses a tooltip open inside first, then the popover. Focus returns to the trigger.
  • PopoverTitle names the popover and PopoverDescription describes it. With no title, pass aria-label to PopoverPopup.
  • A touch screen reader has no Escape key: give a popover with more than a line of text a PopoverClose.
  • While the popup scrolls it is a tab stop, so the keyboard reaches a long text with no control in it.

Right to left

start opens on the right and end on the left, and bottom-start lines up the right edges. The popup takes its direction from the nearest TopClassProvider.

Server and client

A client component: it renders on the server and hydrates in the browser.

Files: index.tsx, client.tsx.

On the chip: client - size not measured yet.