SwiftUI.js
Components

Popover

Popover presents lightweight content anchored to another control. It aligns with SwiftUI's `popover` presentation while keeping web-friendly dialog semantics.

Popover presents lightweight content anchored to another control. It aligns with SwiftUI's `popover` presentation while keeping web-friendly dialog semantics.

Examples

Default

Preview unavailable for this example in the static docs build.

Show code
function DefaultPopover() {
  const [isPresented, setIsPresented] = useState(false)
  const anchorRef = useRef<ComponentRef<'button'>>(null)

  return (
    <>
      <button ref={anchorRef} className="sw-button" onClick={() => setIsPresented((value) => !value)} type="button">
        Show Popover
      </button>
      <Popover anchorRef={anchorRef} isPresented={isPresented} onDismiss={() => setIsPresented(false)}>
        <VStack spacing="sm">
          <Text>Quick actions</Text>
          <Text style={{ color: 'var(--sw-color-label-secondary)' }}>
            Popovers stay anchored to the triggering control.
          </Text>
        </VStack>
      </Popover>
    </>
  )
}

API

PropTypeRequiredDescription
isPresentedbooleanYesControls visibility.
anchorRefRefObject<HTMLElement | null>YesAnchor element used to position the popover.
onDismiss() => voidNoCalled when the popover should close.
arrowEdge'top' | 'bottom' | 'leading' | 'trailing'NoEdge where the arrow points toward the anchor. Default: 'top'
matchAnchorWidthbooleanNoMatch the anchor width. Default: false

Inherits additional props from IBaseComponent.

Overview

Popover presents lightweight content anchored to another control. It aligns with SwiftUI's popover presentation while keeping web-friendly dialog semantics.

Notes

  • Use anchorRef to position the popover relative to a trigger.
  • arrowEdge controls which side of the anchor the popover appears on.
  • The popover dismisses on outside click or Escape.

On this page