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
| Prop | Type | Required | Description |
|---|---|---|---|
isPresented | boolean | Yes | Controls visibility. |
anchorRef | RefObject<HTMLElement | null> | Yes | Anchor element used to position the popover. |
onDismiss | () => void | No | Called when the popover should close. |
arrowEdge | 'top' | 'bottom' | 'leading' | 'trailing' | No | Edge where the arrow points toward the anchor. Default: 'top' |
matchAnchorWidth | boolean | No | Match 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
anchorRefto position the popover relative to a trigger. arrowEdgecontrols which side of the anchor the popover appears on.- The popover dismisses on outside click or
Escape.