Anchored Overlay
A foundational positioning primitive that anchors a floating overlay to a trigger element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | required | The unique identifier for the component container. |
anchor | Snippet<[{ close, isOpen, open, toggle }]> | required | Snippet for the anchor trigger element. Receives { isOpen, open, close, toggle }. |
overlay | Snippet<[{ close }]> | required | Snippet for the floating overlay content. Receives { close }. |
isOpen | boolean | false | Controls the visibility of the floating overlay. Supports $bindable. |
position | AnchoredOverlayPosition | 'bottom-start' | The placement position of the overlay relative to the anchor. |
autoFlip | boolean | true | Whether to automatically flip overlay placement if it would collide with viewport edges. |
closeOnClickOutside | boolean | true | Whether clicking outside the overlay automatically closes it. |
closeOnEscape | boolean | true | Whether pressing Escape automatically closes the overlay. |
transitionFunction | function | fade | Svelte transition function for the floating overlay. |
transitionParameters | object | { duration: 150 } | Parameters for the transition function. |
variant | string | '' | User-defined variant name, added to the root element. Style it with a CSS rule that starts from the root. |
Samples
Anchored Overlay Samples
A foundational positioning primitive that anchors a floating overlay to a trigger element.
1. Click Trigger
Toggles the floating overlay on click and closes on outside clicks or Escape.
<script> import { AnchoredOverlay } from 'fluid-ui-svelte/components'; import { Button, Text } from 'fluid-ui-svelte/base';</script> <AnchoredOverlay id="click-overlay-demo" triggerMode="click" position="bottom-start"> {#snippet anchor()} <Button class="fluid-button-primary">Click to Toggle</Button> {/snippet} {#snippet overlay({ close })} <div class="flex flex-col gap-2 p-2"> <Text type="strong">Floating Overlay</Text> <Text class="text-sm">Opened via click trigger.</Text> <Button onclick={async () => close()} class="fluid-button-secondary text-xs">Close</Button> </div> {/snippet}</AnchoredOverlay>2. Hover Trigger
Opens the floating overlay when hovering the anchor element. Wire onmouseenter/onmouseleave to open/close directly on the anchor.
<script> import { AnchoredOverlay } from 'fluid-ui-svelte/components'; import { Text } from 'fluid-ui-svelte/base';</script> <AnchoredOverlay id="hover-overlay-demo" triggerMode="hover" position="top"> {#snippet anchor()} <span class="inline-flex cursor-pointer rounded-lg bg-neutral-100 px-3 py-1.5 text-sm font-medium dark:bg-neutral-800"> Hover Over Me </span> {/snippet} {#snippet overlay()} <div class="px-2 py-1 text-xs"> <Text>Opened via hover trigger.</Text> </div> {/snippet}</AnchoredOverlay>