useClick
Opens or closes the floating element when clicking the reference element.
import { useClick } from '@skeletonlabs/floating-ui-svelte';
Usage
<script lang="ts">
import { useFloating, useInteractions, useClick } from '@skeletonlabs/floating-ui-svelte';
const floating = useFloating();
const click = useClick(floating.context);
const interactions = useInteractions([click]);
</script>
<!-- Reference Element -->
<button bind:this={floating.elements.reference} {...interactions.getReferenceProps()}>
Reference
</button>
<!-- Floating Element -->
<div
bind:this={floating.elements.floating}
style={floating.floatingStyles}
{...interactions.getFloatingProps()}
>
Tooltip
</div>
Options
enabled | Whether the Hook is enabled, including all internal Effects and event handlers. |
event | The type of event to use to determine a "click" with mouse input. Keyboard clicks work as normal. |
toggle | Whether to toggle the open state with repeated clicks. |
ignoreMouse | Whether to ignore the logic for mouse input (for example, if `useHover()` is also being used). When `useHover()` and `useClick()` are used together, clicking the reference element after hovering it will keep the floating element open even once the cursor leaves. This may not be desirable in some cases. |
keyboardHandlers | Whether to add keyboard handlers (Enter and Space key functionality) for non-button elements (to open/close the floating element via keyboard "click"). |
Compare
Compare to Floating UI React.