Svelte actions for working with floating ui
npm install svelte-floating-ui



!license
Floating UI for Svelte with actions. No wrapper components or component bindings required!
``bash`
npm install svelte-floating-ui`bash`
pnpm install svelte-floating-ui`bash`
yarn add svelte-floating-ui
createFloatingActions takes an optional options object for configuring the content placement. The content action also takes an optional options object for updating the options of the content placement.
createFloatingActions also returns an update method as it's third value which can be used to manually update the content position.
`svelte
onmouseenter={() => showTooltip = true}
onmouseleave={() => showTooltip = false}
use:floatingRef
>Hover me
{#if showTooltip}
API
$3
Floating UI options can be set statically when creating the actions, or dynamically on the content action.
If both are set, then the dynamic options will be merged with the initial options.
`svelte
`$3
The content element's position can be manually updated by using the third value returned by
createFloatingActions. This method takes an optional options object which will be merged with the initial options.`svelte
`$3
You can use autoUpdate options directly in initOptions for createFloatingActions or floatingContent, but not in update
`svelte
`What values can autoUpdate have?
Partial<Options>
`ts
/**
* false: Don't initialize autoUpdate;
* true: Standard autoUpdate values from the documentation;
* object: All as in the autoUpdate documentation. Your parameters are added to the default ones;
* @default true
*/
autoUpdate?: boolean | Partial
`$3
Svelte Floating UI allows you to use the
floatingRef (reference node) like VirtualElementThis is an example of creating a tooltip that runs behind the mouse cursor:
`svelte
Magic
`$3
To apply styles manually, you can pass the
onComputed option to createFloatingActions. This is a function that recieves a ComputePositionReturn. This function is called every time the tooltip's position is computed.See Arrow Middleware for an example on it's usage.
Arrow Middleware
For convenience, a custom Arrow middleware is provided. Rather than accepting an
HTMLElement, this takes a Writable (createArrowRef). Otherwise, this middleware works exactly as the regular Floating UI one, including needing to manually set the arrow styles.onComputed option. The below implementation is copied from the Floating UI Tutorial.`svelte
onmouseenter={() => (showTooltip = true)}
onmouseleave={() => (showTooltip = false)}
use:floatingRef>Hover me >
{#if showTooltip}
Tooltip this is some longer text than the button
^
{/if}
``_Thanks to TehNut/svelte-floating-ui for the foundation for this package_