skip section navigation

Popover

Popover provides a floating surface while your app owns the trigger and expanded state. use it for a small set of local controls, not a modal task that needs a focus trap.

  • the balcony garden · unread
  • the garden after rain · read

usage

svelte
<script>
	import { Popover, Toggle } from '@ciabi/loafkit-ui';
	let expanded = $state(false);
	let unreadOnly = $state(false);
</script>

<button type="button" aria-expanded={expanded} aria-controls="reading-filter-popover"
	onclick={() => expanded = !expanded}>Reading filters</button>
<Popover id="reading-filter" {expanded} title="Show articles" onDismiss={() => expanded = false}>
	<Toggle label="Unread only" checked={unreadOnly} onclick={() => unreadOnly = !unreadOnly} />
</Popover>
<ul><li>the balcony garden · unread</li>{#if !unreadOnly}<li>the garden after rain · read</li>{/if}</ul>

composition

  • trigger + Popover
    • Popover
      • children

state and dismissal

onDismiss(reason) receives escape or outside, but your callback must actually set expanded to false. when Escape applies to this popover, focus returns to its associated trigger. outside dismissal leaves the clicked target’s focus alone.

layout and focus

Popover isn’t the browser Popover API and doesn’t choose an anchor position for you. it uses relative positioning, and your composition can add positioning when needed. collapsed content is inert and hidden from accessibility APIs.

opening doesn’t automatically move focus or trap it. keep the trigger and content in a sensible order. use DialogContainer for a modal task with native dialog focus handling.

API reference

Popover

Component
expanded

whether the surface is expanded.

id

base ID; the surface uses this value plus __popover. header uses this value plus __header

title

the visible heading.

description

supporting text for the component.

dismissible
Default: true

allows ordinary Escape and backdrop dismissal.

onDismiss

requests closing with escape or outside; update expanded in your handler.

class
Default: ''

extra classes on the component root.

style

inline styles on the component root.

children

custom content inside the component.