Popover
View as MarkdownAn accessible popup anchored to a button.
Features
Permalink to heading "Features"- Focus is managed and can be trapped within the popover
- Supports modal and non-modal modes
- Supports custom positioning with placement options
- Pressing
Escapecloses the popover - Automatically adjusts position to stay in viewport
<primitives:popover.root>
<primitives:popover.trigger />
<primitives:popover.positioner>
<primitives:popover.content>
<primitives:popover.arrow />
<primitives:popover.closeTrigger />
<primitives:popover.title />
<primitives:popover.description />
</primitives:popover.content>
</primitives:popover.positioner>
</primitives:popover.root>
Installation
Permalink to heading "Installation"typo3 ui:add popover
Please copy the files manually from GitHub into your project.
Read more about installing Components and Primitives.
Examples
Permalink to heading "Examples"Add a close button
Permalink to heading "Add a close button"Set showCloseButton on popover.content to add a close button in the corner.
Change the placement
Permalink to heading "Change the placement"Pass placement through the positioning prop. The popover below opens to the right of its trigger.
Make it modal
Permalink to heading "Make it modal"Set modal to trap focus and block interaction with the rest of the page while the popover is open.
Translate the close button
Permalink to heading "Translate the close button"The label of the close button comes from the library's language file and follows the site language. Override it per template with the translations prop:
<ui:popover.root
translations="{
closeTriggerLabel: f:translate(key: 'LLL:EXT:my_extension/Resources/Private/Language/locallang.xlf:popover.close')
}"
>
...
</ui:popover.root>
API Reference
Permalink to heading "API Reference"The following tables cover the available props of the Fluid Primitives. For a full list of available client side props and methods, see the Zag.js Machine API.
popover.root
Permalink to heading "popover.root"Provides popover state and context for the composed parts. Renders no wrapper element.
| Name | Description | Required | Default |
|---|---|---|---|
modal | booleanWhether the popover should be modal. | No | false |
portalled | booleanWhether the popover is portalled and proxies tabbing behavior regardless of DOM position. | No | true |
autoFocus | booleanWhether to automatically set focus on the first focusable content within the popover when opened. | No | true |
restoreFocus | booleanWhether to restore focus to the element that had focus before the popover was opened. | No | true |
closeOnInteractOutside | booleanWhether to close the popover when the user clicks outside of the popover. | No | true |
closeOnEscape | booleanWhether to close the popover when the escape key is pressed. | No | true |
positioning | arrayThe user provided options used to position the popover content. | No | - |
defaultOpen | booleanThe initial open state of the popover when rendered. Use when you don't need to control the open state of the popover. | No | false |
translations | arrayLocalized popover labels. Use `f:translate` for per-template localization overrides when needed. | No | - |
rootId | stringThe root ID of the component, used for hydration and identification. | No | - |
ids | arrayThe IDs of of the component parts for composition. | No | [] |
autoMount | booleanWhether the client initializes the component on its own. Set it to false to mount it yourself with `mount()` | No | true |
popover.trigger
Permalink to heading "popover.trigger"Opens and closes the popover. Renders a <button> element.
| Name | Description | Required | Default |
|---|---|---|---|
value | string | No | - |
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-popover-trigger | <uid> |
data-placement | The placement of the trigger |
data-side | The side of the trigger that the trigger is positioned on |
data-value | The value of the item |
data-current | Present when current |
data-state | "open" | "closed" |
popover.positioner
Permalink to heading "popover.positioner"Positions the popover content relative to the trigger. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-popover-positioner | <uid> |
data-nested | Present when the positioner is nested within another {{widget}} |
data-has-nested | Present when the positioner has nested {{widget}}s |
popover.content
Permalink to heading "popover.content"Contains the popover panel content. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-popover-content | <uid> |
data-state | "open" | "closed" |
data-expanded | Present when expanded |
data-placement | The placement of the content |
data-side | The side of the trigger that the content is positioned on |
data-nested | popover |
data-has-nested | popover |
popover.arrow
Permalink to heading "popover.arrow"Displays a decorative arrow for the popover. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
popover.indicator
Permalink to heading "popover.indicator"Displays a decorative state indicator. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-popover-indicator | <uid> |
data-state | "open" | "closed" |
popover.title
Permalink to heading "popover.title"Provides the accessible title for the popover. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
popover.description
Permalink to heading "popover.description"Provides supporting descriptive text for the popover. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
popover.closeTrigger
Permalink to heading "popover.closeTrigger"Closes the popover when activated. Renders a <button> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Machine JavaScript API
Permalink to heading "Machine JavaScript API"| Name | Type | Description |
|---|---|---|
open | boolean | Whether the popover is open |
setOpen | (open: boolean) => void | Function to open or close the popover |
triggerValue | string | null | The trigger value |
setTriggerValue | (value: string | null) => void | Function to set the trigger value |
reposition | (options?: Partial<PositioningOptions>) => void | Function to reposition the popover |
getTriggerState | (props?: TriggerProps) => TriggerState | Returns the state of a specific trigger, including whether it's the currently active one |
getPositionerState | () => PositionerState | Returns the state of the positioner |
getContentState | () => ContentState | Returns the state of the content |
Accessibility
Permalink to heading "Accessibility"| Key | Description |
|---|---|
Space | Opens/closes the popover. |
Enter | Opens/closes the popover. |
Tab | Moves focus to the next focusable element within the content. Note: If there are no focusable elements, focus is moved to the next focusable element after the trigger. |
Shift + Tab | Moves focus to the previous focusable element within the content Note: If there are no focusable elements, focus is moved to the trigger. |
Esc | Closes the popover and moves focus to the trigger. |