Popover

Popovers are containers used to display transient content such as options and actions.

import {Popover} from "@qualcomm-ui/react/popover"

Examples

Simple

Basic popover using the simple API with a label and child content.

<Popover
  label="Label"
  trigger={<Button emphasis="primary">Show Popover</Button>}
>
  Popover content
</Popover>

Composite

Build with the composite API for granular control. This API requires you to provide each subcomponent, but gives you full control over the structure and layout.

<Popover.Root>
  <Popover.Anchor>
    <Popover.Trigger>
      <Button emphasis="primary">Show Popover</Button>
    </Popover.Trigger>
  </Popover.Anchor>

  <Portal>
    <Popover.Positioner>
      <Popover.Content>
        <Popover.Arrow />
        <Popover.Label>Label</Popover.Label>
        <Popover.Description>Description</Popover.Description>
      </Popover.Content>
    </Popover.Positioner>
  </Portal>
</Popover.Root>

Accessibility

  • The anchor element is automatically associated with the popover:
  • When the popover is visible, the anchor element receives the aria-controls and aria-expanded attributes.
  • The anchor element's aria-haspopup is always set to 'true'.
  • When the Popover.Label component is supplied, the overlay panel's aria-labelledby attribute is set to the id of the label.
  • When the Popover.Description component is supplied, the overlay panel's aria-describedby attribute is set to the id of the label.

NOTE

Don't worry about supplying id's to the label, description or popover. If these aren't provided, they'll be generated automatically.

API

<Popover>

The Popover extends the Popover.Root with the following props:

PropTypeDefault
Render Prop. The popover trigger event handlers and attributes are applied to this element. It must forward its ref
Props applied to the anchor component.
PopoverAnchorProps
Props applied to the arrow component.
PopoverArrowProps
Props applied to the content component.
PopoverContentProps
Optional description text for the popover.
Props applied to the description component.
PopoverDescriptionProps
Whether to hide the arrow.
boolean
false
Optional label text for the popover.
Props applied to the label component.
Props applied to the portal component.
{
container?:
| HTMLElement
| RefObject<HTMLElement>
disabled?: boolean
}
Props applied to the positioner component.
PopoverPositionerProps
Description
Render Prop. The popover trigger event handlers and attributes are applied to this element. It must forward its ref
Type
PopoverAnchorProps
Description
Props applied to the anchor component.
Type
PopoverArrowProps
Description
Props applied to the arrow component.
Type
PopoverContentProps
Description
Props applied to the content component.
Description
Optional description text for the popover.
Type
PopoverDescriptionProps
Description
Props applied to the description component.
Type
boolean
Description
Whether to hide the arrow.
Description
Optional label text for the popover.
Description
Props applied to the label component.
Type
{
container?:
| HTMLElement
| RefObject<HTMLElement>
disabled?: boolean
}
Description
Props applied to the portal component.
Type
PopoverPositionerProps
Description
Props applied to the positioner component.

Composite API

<Popover.Root>

PropTypeDefault
Whether to automatically set focus on the first focusable content within the popover when opened.
boolean
true
React children prop.
Whether to close the popover when the escape key is pressed.
boolean
true
Whether to close the popover when the user clicks outside the popover.
boolean
true
The initial open state of the popover when rendered. Use when you don't need to control the open state of the popover.
boolean
The document's text/writing direction.
'ltr' | 'rtl'
'ltr'
A root node to correctly resolve document in custom environments. i.e., Iframes, Electron.
    () =>
    | Node
    | ShadowRoot
    | Document
    The ids of the popover elements. These will be automatically generated if omitted.
    Partial<{
    anchor: string
    arrow: string
    closeTrigger: string
    content: string
    description: string
    positioner: string
    title: string
    trigger: string
    }>
    Whether to synchronize the present change immediately or defer it to the next frame
    boolean
    The element to focus on when the popover is opened.
      () => HTMLElement
      When true, the component will not be rendered in the DOM until it becomes visible or active.
      boolean
      false
      
      Whether the popover should be modal. When set to true:
      - interaction with outside elements will be disabled
      - only popover content will be visible to screen readers
      - scrolling is blocked
      - focus is trapped within the popover
      boolean
      false
      
      Function called when the escape key is pressed
        (
        event: KeyboardEvent,
        ) => void
        Function called when the animation ends in the closed state
        VoidFunction
        Function called when the focus is moved outside the component
          (
          event: FocusOutsideEvent,
          ) => void
          Function called when an interaction happens outside the component
            (
            event: InteractOutsideEvent,
            ) => void
            Function invoked when the popover opens or closes
            • openThe next value of the open state.
            (
            open: boolean,
            ) => void
            Function called when the pointer is pressed down outside the component
              (
              event: PointerDownOutsideEvent,
              ) => void
              Function called when this layer is closed due to a parent layer being closed
                (
                event: CustomEvent<{
                originalIndex: number
                originalLayer: HTMLElement
                targetIndex: number
                targetLayer: HTMLElement
                }>,
                ) => void
                The controlled open state of the popover
                boolean
                Returns the persistent elements that:
                - should not have pointer-events disabled
                - should not trigger the dismiss event
                Array<
                () => Element
                >
                Whether the popover is portalled. This will proxy the tabbing behavior regardless of the DOM position of the popover content.
                boolean
                true
                
                The options used to position the popover content.
                Whether the node is present (controlled by the user)
                boolean
                On close, restore focus to the element that triggered the open event.
                boolean
                true
                
                Whether to allow the initial presence animation.
                boolean
                false
                
                When true, the component will be completely removed from the DOM when it becomes inactive or hidden, rather than just being hidden with CSS.
                boolean
                false
                
                Type
                boolean
                Description
                Whether to automatically set focus on the first focusable content within the popover when opened.
                Description
                React children prop.
                Type
                boolean
                Description
                Whether to close the popover when the escape key is pressed.
                Type
                boolean
                Description
                Whether to close the popover when the user clicks outside the popover.
                Type
                boolean
                Description
                The initial open state of the popover when rendered. Use when you don't need to control the open state of the popover.
                Type
                'ltr' | 'rtl'
                Description
                The document's text/writing direction.
                Type
                () =>
                | Node
                | ShadowRoot
                | Document
                Description
                A root node to correctly resolve document in custom environments. i.e., Iframes, Electron.
                  Type
                  Partial<{
                  anchor: string
                  arrow: string
                  closeTrigger: string
                  content: string
                  description: string
                  positioner: string
                  title: string
                  trigger: string
                  }>
                  Description
                  The ids of the popover elements. These will be automatically generated if omitted.
                  Type
                  boolean
                  Description
                  Whether to synchronize the present change immediately or defer it to the next frame
                  Type
                  () => HTMLElement
                  Description
                  The element to focus on when the popover is opened.
                    Type
                    boolean
                    Description
                    When true, the component will not be rendered in the DOM until it becomes visible or active.
                    Type
                    boolean
                    Description
                    Whether the popover should be modal. When set to true:
                    - interaction with outside elements will be disabled
                    - only popover content will be visible to screen readers
                    - scrolling is blocked
                    - focus is trapped within the popover
                    Type
                    (
                    event: KeyboardEvent,
                    ) => void
                    Description
                    Function called when the escape key is pressed
                      Type
                      VoidFunction
                      Description
                      Function called when the animation ends in the closed state
                      Type
                      (
                      event: FocusOutsideEvent,
                      ) => void
                      Description
                      Function called when the focus is moved outside the component
                        Type
                        (
                        event: InteractOutsideEvent,
                        ) => void
                        Description
                        Function called when an interaction happens outside the component
                          Type
                          (
                          open: boolean,
                          ) => void
                          Description
                          Function invoked when the popover opens or closes
                          • openThe next value of the open state.
                          Type
                          (
                          event: PointerDownOutsideEvent,
                          ) => void
                          Description
                          Function called when the pointer is pressed down outside the component
                            Type
                            (
                            event: CustomEvent<{
                            originalIndex: number
                            originalLayer: HTMLElement
                            targetIndex: number
                            targetLayer: HTMLElement
                            }>,
                            ) => void
                            Description
                            Function called when this layer is closed due to a parent layer being closed
                              Type
                              boolean
                              Description
                              The controlled open state of the popover
                              Type
                              Array<
                              () => Element
                              >
                              Description
                              Returns the persistent elements that:
                              - should not have pointer-events disabled
                              - should not trigger the dismiss event
                              Type
                              boolean
                              Description
                              Whether the popover is portalled. This will proxy the tabbing behavior regardless of the DOM position of the popover content.
                              Description
                              The options used to position the popover content.
                              Type
                              boolean
                              Description
                              Whether the node is present (controlled by the user)
                              Type
                              boolean
                              Description
                              On close, restore focus to the element that triggered the open event.
                              Type
                              boolean
                              Description
                              Whether to allow the initial presence animation.
                              Type
                              boolean
                              Description
                              When true, the component will be completely removed from the DOM when it becomes inactive or hidden, rather than just being hidden with CSS.

                              This section describes the elements of the Popover's composite API.

                              <Popover.Label>

                              PropType
                              React children prop.
                              id attribute. If omitted, a unique identifier will be automatically generated for accessibility.
                              string
                              Allows you to replace the component's HTML element with a different tag or component. Learn more
                              | ReactElement
                              | ((
                              props: object,
                              ) => ReactElement)
                              Description
                              React children prop.
                              Type
                              string
                              Description
                              id attribute. If omitted, a unique identifier will be automatically generated for accessibility.
                              Type
                              | ReactElement
                              | ((
                              props: object,
                              ) => ReactElement)
                              Description
                              Allows you to replace the component's HTML element with a different tag or component. Learn more

                              Data Structures

                              PopoverPositioningOptions

                              PropTypeDefault
                              The minimum padding between the arrow and the floating element's corner.
                              number
                              4
                              
                              The overflow boundary of the reference element
                                () =>
                                | 'clippingAncestors'
                                | Element
                                | Array<Element>
                                | {
                                height: number
                                width: number
                                x: number
                                y: number
                                }
                                Whether the popover should fit the viewport.
                                boolean
                                Whether to flip the placement when the floating element overflows the boundary.
                                | boolean
                                | Array<
                                | 'bottom'
                                | 'bottom-end'
                                | 'bottom-start'
                                | 'left'
                                | 'left-end'
                                | 'left-start'
                                | 'right'
                                | 'right-end'
                                | 'right-start'
                                | 'top'
                                | 'top-end'
                                | 'top-start'
                                >
                                true
                                
                                Function that returns the anchor rect
                                  (
                                  element:
                                  | HTMLElement
                                  | VirtualElement,
                                  ) => {
                                  height?: number
                                  width?: number
                                  x?: number
                                  y?: number
                                  }
                                  The main axis offset or gap between the reference and floating element
                                  number
                                  8
                                  
                                  Whether the popover should be hidden when the reference element is detached
                                  boolean
                                  Options to activate auto-update listeners
                                  | boolean
                                  | {
                                  ancestorResize?: boolean
                                  ancestorScroll?: boolean
                                  animationFrame?: boolean
                                  elementResize?: boolean
                                  layoutShift?: boolean
                                  }
                                  true
                                  
                                  The offset of the floating element
                                  {
                                  crossAxis?: number
                                  mainAxis?: number
                                  }
                                  Function called when the placement is computed
                                    (
                                    data: ComputePositionReturn,
                                    ) => void
                                    Function called when the floating element is positioned or not
                                      (data: {
                                      placed: boolean
                                      }) => void
                                      The virtual padding around the viewport edges to check for overflow
                                      number
                                      Whether the floating element can overlap the reference element
                                      boolean
                                      false
                                      
                                      The initial placement of the floating element
                                      | 'bottom'
                                      | 'bottom-end'
                                      | 'bottom-start'
                                      | 'left'
                                      | 'left-end'
                                      | 'left-start'
                                      | 'right'
                                      | 'right-end'
                                      | 'right-start'
                                      | 'top'
                                      | 'top-end'
                                      | 'top-start'
                                      'top'
                                      
                                      Whether to make the floating element same width as the reference element
                                      boolean
                                      The secondary axis offset or gap between the reference and floating elements
                                      number
                                      Whether the popover should slide when it overflows.
                                      boolean
                                      The strategy to use for positioning
                                      | 'absolute'
                                      | 'fixed'
                                      'absolute'
                                      
                                      A callback that will be called when the popover needs to calculate its position.
                                        (data: {
                                        updatePosition: () => Promise<void>
                                        }) => void | Promise<void>
                                        Type
                                        number
                                        Description
                                        The minimum padding between the arrow and the floating element's corner.
                                        Type
                                        () =>
                                        | 'clippingAncestors'
                                        | Element
                                        | Array<Element>
                                        | {
                                        height: number
                                        width: number
                                        x: number
                                        y: number
                                        }
                                        Description
                                        The overflow boundary of the reference element
                                          Type
                                          boolean
                                          Description
                                          Whether the popover should fit the viewport.
                                          Type
                                          | boolean
                                          | Array<
                                          | 'bottom'
                                          | 'bottom-end'
                                          | 'bottom-start'
                                          | 'left'
                                          | 'left-end'
                                          | 'left-start'
                                          | 'right'
                                          | 'right-end'
                                          | 'right-start'
                                          | 'top'
                                          | 'top-end'
                                          | 'top-start'
                                          >
                                          Description
                                          Whether to flip the placement when the floating element overflows the boundary.
                                          Type
                                          (
                                          element:
                                          | HTMLElement
                                          | VirtualElement,
                                          ) => {
                                          height?: number
                                          width?: number
                                          x?: number
                                          y?: number
                                          }
                                          Description
                                          Function that returns the anchor rect
                                            Type
                                            number
                                            Description
                                            The main axis offset or gap between the reference and floating element
                                            Type
                                            boolean
                                            Description
                                            Whether the popover should be hidden when the reference element is detached
                                            Type
                                            | boolean
                                            | {
                                            ancestorResize?: boolean
                                            ancestorScroll?: boolean
                                            animationFrame?: boolean
                                            elementResize?: boolean
                                            layoutShift?: boolean
                                            }
                                            Description
                                            Options to activate auto-update listeners
                                            Type
                                            {
                                            crossAxis?: number
                                            mainAxis?: number
                                            }
                                            Description
                                            The offset of the floating element
                                            Type
                                            (
                                            data: ComputePositionReturn,
                                            ) => void
                                            Description
                                            Function called when the placement is computed
                                              Type
                                              (data: {
                                              placed: boolean
                                              }) => void
                                              Description
                                              Function called when the floating element is positioned or not
                                                Type
                                                number
                                                Description
                                                The virtual padding around the viewport edges to check for overflow
                                                Type
                                                boolean
                                                Description
                                                Whether the floating element can overlap the reference element
                                                Type
                                                | 'bottom'
                                                | 'bottom-end'
                                                | 'bottom-start'
                                                | 'left'
                                                | 'left-end'
                                                | 'left-start'
                                                | 'right'
                                                | 'right-end'
                                                | 'right-start'
                                                | 'top'
                                                | 'top-end'
                                                | 'top-start'
                                                Description
                                                The initial placement of the floating element
                                                Type
                                                boolean
                                                Description
                                                Whether to make the floating element same width as the reference element
                                                Type
                                                number
                                                Description
                                                The secondary axis offset or gap between the reference and floating elements
                                                Type
                                                boolean
                                                Description
                                                Whether the popover should slide when it overflows.
                                                Type
                                                | 'absolute'
                                                | 'fixed'
                                                Description
                                                The strategy to use for positioning
                                                Type
                                                (data: {
                                                updatePosition: () => Promise<void>
                                                }) => void | Promise<void>
                                                Description
                                                A callback that will be called when the popover needs to calculate its position.