Skip to content

Commit 7b8cd17

Browse files
authored
fix(core): keep last known position of popover on dismiss (#215)
1 parent 66ea745 commit 7b8cd17

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

packages/core/src/client/webcomponents/components/FloatingPopover.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const FloatingPopoverComponent = defineComponent({
5353
)
5454

5555
let previousContent: VNode | undefined
56+
let previousStyle: Record<string, string> = {}
5657

5758
return () => {
5859
// Force re-render to update the position
@@ -62,6 +63,23 @@ const FloatingPopoverComponent = defineComponent({
6263
if (!el.value)
6364
return null
6465

66+
// When dismissing (item is null), keep the last known position
67+
// so the popover fades out in place instead of jumping
68+
if (!props.item) {
69+
return h(
70+
'div',
71+
{
72+
ref: 'panel',
73+
class: [
74+
'fixed z-floating-tooltip text-xs transition-all duration-300 w-max bg-glass color-base border border-base rounded px2 p1',
75+
'op0 pointer-events-none',
76+
],
77+
style: previousStyle,
78+
},
79+
previousContent,
80+
)
81+
}
82+
6583
const rect = el.value.getBoundingClientRect()
6684

6785
// guess alignment of the tooltip based on viewport position
@@ -116,6 +134,8 @@ const FloatingPopoverComponent = defineComponent({
116134
}
117135
}
118136

137+
previousStyle = style
138+
119139
const content = (
120140
typeof props.item?.content === 'string'
121141
? h('span', props.item?.content)

0 commit comments

Comments
 (0)