Skip to content

Commit 3223398

Browse files
committed
fix(FloatingUi): correctly remove from dom floating elements being quickly shown/hidden before css transitions can start
1 parent 07d4b82 commit 3223398

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

packages/core/src/helpers/FloatingUi.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,14 @@ const parent = computed(() => props.teleportTo ?? toValue(injectedParent));
6969
7070
const internalHidden = ref(props.hidden);
7171
const opacity = ref(props.hidden ? 0 : 1);
72+
const isVisible = ref(false);
7273
7374
watch(() => props.hidden, (hidden) => {
7475
if (hidden) {
7576
opacity.value = 0;
77+
if (!isVisible.value) {
78+
internalHidden.value = true;
79+
}
7680
} else if (internalHidden.value) {
7781
internalHidden.value = false;
7882
} else {
@@ -152,7 +156,7 @@ function floatingElement() {
152156
153157
const onElementMounted = (el: unknown) => {
154158
htmlElement.value = el instanceof HTMLElement ? el : null;
155-
opacity.value = props.hidden ? 0 : 1;
159+
opacity.value = 1;
156160
};
157161
158162
return withDirectives(cloneVNode(children[0], {
@@ -165,10 +169,16 @@ function floatingElement() {
165169
transition: `opacity ${props.animationDuration}ms cubic-bezier(.54, 1.5, .38, 1.11)`,
166170
zIndex: props.zIndex,
167171
},
172+
onTransitionstart: (e: TransitionEvent) => {
173+
if (e.propertyName === 'opacity' && opacity.value > 0) {
174+
isVisible.value = true;
175+
}
176+
},
168177
onTransitionend: (e: TransitionEvent) => {
169178
if (e.propertyName === 'opacity') {
170179
if (!opacity.value) {
171180
internalHidden.value = true;
181+
isVisible.value = false;
172182
emit('hidden');
173183
} else {
174184
emit('shown');

0 commit comments

Comments
 (0)