-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix incorrect tooltip position after window resize
This commit fixes an issue where the tooltip position becomes inaccurate after resizing the window. The solution uses `autoUpdate` functionality of `floating-ui` to update the position automatically on resize events. This function depends on browser APIs: `IntersectionObserver` and `ResizeObserver`. The official documentation recommends polyfilling those to support old browsers. Polyfilling `ResizeObserver` is already part of the codebase, used by `SizeObserver.vue`. This commit refactors polyfill logic to be reusable across different components, and reuses it on `TooltipWrapper.vue`. Polyfilling `IntersectionObserver` is ignored due to this API being older and more widely supported.
- Loading branch information
1 parent
f4a74f0
commit f8e5f1a
Showing
3 changed files
with
40 additions
and
14 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/presentation/components/Shared/Hooks/UseResizeObserverPolyfill.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { onMounted } from 'vue'; | ||
import { AsyncLazy } from '@/infrastructure/Threading/AsyncLazy'; | ||
|
||
// AsyncLazy ensures single load of the ResizeObserver polyfill, | ||
// even when multiple calls are made simultaneously. | ||
const polyfillLoader = new AsyncLazy(async () => { | ||
if ('ResizeObserver' in window) { | ||
return window.ResizeObserver; | ||
} | ||
const module = await import('@juggle/resize-observer'); | ||
globalThis.window.ResizeObserver = module.ResizeObserver; | ||
return module.ResizeObserver; | ||
}); | ||
|
||
async function polyfillResizeObserver(): Promise<typeof ResizeObserver> { | ||
return polyfillLoader.getValue(); | ||
} | ||
|
||
export function useResizeObserverPolyfill() { | ||
const resizeObserverReady = new Promise<void>((resolve) => { | ||
onMounted(async () => { | ||
await polyfillResizeObserver(); | ||
resolve(); | ||
}); | ||
}); | ||
return { resizeObserverReady }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters