Skip to content

Commit 1832e4b

Browse files
committed
init tooltip visual test
1 parent 88783e3 commit 1832e4b

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

packages/floating-ui-svelte/src/components/floating-delay-group.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
timeoutMs?: number;
169169
}
170170
171-
export type { FloatingDelayGroupProps, UseDelayGroupOptions };
171+
export type { FloatingDelayGroupProps, UseDelayGroupOptions, Delay };
172172
export { useDelayGroup };
173173
</script>
174174

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<script lang="ts">
2+
import type { Placement } from "@floating-ui/utils";
3+
import {
4+
useDelayGroup,
5+
useDismiss,
6+
useFloating,
7+
useFocus,
8+
useHover,
9+
useInteractions,
10+
useRole,
11+
type Delay,
12+
} from "../../../../src/index.js";
13+
import type { Snippet } from "svelte";
14+
import { autoUpdate, flip, offset, shift } from "@floating-ui/dom";
15+
16+
let {
17+
label,
18+
placement = "top",
19+
delay = 0,
20+
children,
21+
}: {
22+
label: string;
23+
placement?: Placement;
24+
delay?: Delay;
25+
children?: Snippet;
26+
} = $props();
27+
28+
let open = $state(false);
29+
30+
const f = useFloating({
31+
open: () => open,
32+
onOpenChange: (v) => {
33+
open = v;
34+
},
35+
placement: () => placement,
36+
middleware: () => [offset(5), flip(), shift({ padding: 8 })],
37+
whileElementsMounted: autoUpdate,
38+
});
39+
40+
const delayGroup = useDelayGroup(f.context);
41+
42+
const ints = useInteractions([
43+
useHover(f.context, {
44+
delay: () => (delayGroup.delay === 0 ? delay : delayGroup.delay),
45+
move: false,
46+
}),
47+
useFocus(f.context),
48+
useRole(f.context, { role: "tooltip" }),
49+
useDismiss(f.context),
50+
]);
51+
</script>

0 commit comments

Comments
 (0)