From 3e734549c78e1e5b1517537541b4105ae2c39774 Mon Sep 17 00:00:00 2001 From: Felix Kling Date: Tue, 13 Aug 2024 15:39:35 +0200 Subject: [PATCH] fix(svelte): Fix tooltip in hovercards (#64443) Fixes srch-744 It seems that the code for testing whether the target element is part of the layout didn't work in hovercards because it (possibly?) runs before the hovercard is rendered. Moving the logic to `onMount` + `await tick()` seem to work, although that might still be a coincidence. ## Test plan Hovering over the 'precise' badge shows the corresponding tooltip. --- client/web-sveltekit/src/lib/Tooltip.svelte | 27 ++++++++++++++++----- client/web-sveltekit/src/lib/dom.ts | 18 +++++++++++--- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/client/web-sveltekit/src/lib/Tooltip.svelte b/client/web-sveltekit/src/lib/Tooltip.svelte index 0cfe18ed2c3..c5b41f45bd8 100644 --- a/client/web-sveltekit/src/lib/Tooltip.svelte +++ b/client/web-sveltekit/src/lib/Tooltip.svelte @@ -5,7 +5,9 @@ diff --git a/client/web-sveltekit/src/lib/dom.ts b/client/web-sveltekit/src/lib/dom.ts index d2d2fcd0abf..f7cda8aaf21 100644 --- a/client/web-sveltekit/src/lib/dom.ts +++ b/client/web-sveltekit/src/lib/dom.ts @@ -126,7 +126,7 @@ export const onClickOutside: Action< } } -interface PopoverOptions { +export interface PopoverOptions { /** * The placement of the popover relative to the reference element. */ @@ -146,6 +146,11 @@ interface PopoverOptions { * The middleware is always enabled. */ flip?: FlipOptions + /** + * A callback to set the available width of the popover. The default behavior is + * to set the elements `maxWidth` and `maxHeight` style properties. + */ + onSize?: (element: HTMLElement, size: { availableWidth: number; availableHeight: number }) => void } /** @@ -166,10 +171,15 @@ export const popover: Action