Skip to content

Commit

Permalink
fix: cleanup correctly floating ui autoUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
ubermanu committed Jun 2, 2023
1 parent dd99c60 commit c23086b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/routes/(docs)/component/tooltip/example/Help.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { HelpCircle } from 'lucide-svelte'
import { createTooltip } from '$lib'
import { onMount } from 'svelte'
import { onDestroy, onMount } from 'svelte'
import { browser } from '$app/environment'
import { computePosition, autoUpdate, type Placement } from '@floating-ui/dom'
Expand All @@ -13,14 +13,20 @@
let floatingEl: HTMLElement
let position = { x: 0, y: 0 }
let cleanup
if (browser) {
onMount(() => {
autoUpdate(referenceEl, floatingEl, () => {
cleanup = autoUpdate(referenceEl, floatingEl, () => {
computePosition(referenceEl, floatingEl, { placement }).then(
({ x, y }) => (position = { x, y })
)
})
})
onDestroy(() => {
cleanup?.()
})
}
</script>

Expand Down

0 comments on commit c23086b

Please sign in to comment.