Skip to content

Commit

Permalink
fix: tooltip & grace area (#521)
Browse files Browse the repository at this point in the history
  • Loading branch information
anatolzak authored Apr 28, 2024
1 parent dc54680 commit 74b2d5c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
1 change: 1 addition & 0 deletions packages/bits-ui/src/lib/bits/tooltip/tooltip.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ class TooltipContentState {
this.#id = props.id;
const contentNode = useNodeById(this.#id);
this.root.contentNode = contentNode;
this.root.contentId = this.#id;
$effect(() => {
console.log(contentNode.value);
});
Expand Down
30 changes: 12 additions & 18 deletions packages/bits-ui/src/lib/internal/useGraceArea.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,25 @@ export function useGraceArea(triggerId: ReadableBox<string>, contentId: Readable
}

$effect(() => {
const tNode = triggerNode;
let cNode = contentNode;
if (!tNode) return;
if (!cNode) {
cNode = document.getElementById(contentId.value);
if (!cNode) return;
contentNode = cNode;
}
contentNode = document.getElementById(contentId.value);
if (!triggerNode || !contentNode) return;

if (!triggerNode || !cNode) return;
const handleTriggerLeave = (e: PointerEvent) => handleCreateGraceArea(e, cNode!);
const handleContentLeave = () => handleRemoveGraceArea();
const handleTriggerLeave = (e: PointerEvent) => {
handleCreateGraceArea(e, contentNode!);
};

const unsub = executeCallbacks(
const handleContentLeave = (e: PointerEvent) => {
handleCreateGraceArea(e, triggerNode!);
};
return executeCallbacks(
addEventListener(triggerNode, "pointerleave", handleTriggerLeave),
addEventListener(cNode, "pointerleave", handleContentLeave)
addEventListener(contentNode, "pointerleave", handleContentLeave)
);

return unsub;
});

$effect(() => {
if (!pointerGraceArea) return;

function handleTrackPointerGrace(e: PointerEvent) {
if (!pointerGraceArea) return;
const target = e.target;
Expand All @@ -77,9 +73,7 @@ export function useGraceArea(triggerId: ReadableBox<string>, contentId: Readable
}
}

const unsub = addEventListener(document, "pointermove", handleTrackPointerGrace);

return unsub;
return addEventListener(document, "pointermove", handleTrackPointerGrace);
});

return {
Expand Down

0 comments on commit 74b2d5c

Please sign in to comment.