From 61c3abf44ad6879702d138fd53853906bea71491 Mon Sep 17 00:00:00 2001 From: MomoPoppy <125256456+MomoPoppy@users.noreply.github.com> Date: Fri, 26 Jul 2024 17:18:03 +0800 Subject: [PATCH] fix(auto-tip): [auto-tip] Fix the issue where the placement configuration always has old values (#1774) --- packages/renderless/src/tooltip/vue.ts | 18 +++++++++++++++--- packages/vue-directive/src/auto-tip.ts | 1 + 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/renderless/src/tooltip/vue.ts b/packages/renderless/src/tooltip/vue.ts index 6e76adf33..f4f931be9 100644 --- a/packages/renderless/src/tooltip/vue.ts +++ b/packages/renderless/src/tooltip/vue.ts @@ -48,12 +48,13 @@ export const api = [ 'focusHandler' ] -const initState = ({ reactive, showPopper, popperElm, referenceElm, props, inject, popperJS }) => +const initState = ({ reactive, showPopper, popperElm, referenceElm, props, inject, popperJS, currentPlacement }) => reactive({ popperJS, showPopper, popperElm, referenceElm, + currentPlacement, timeout: null, focusing: false, expectedState: undefined, @@ -85,8 +86,19 @@ export const renderless = ( Object.assign(popperParam, { slots, onBeforeUnmount, onDeactivated, watch }) - const { showPopper, updatePopper, popperElm, referenceElm, doDestroy, popperJS } = userPopper(popperParam as any) - const state: ITooltipState = initState({ reactive, showPopper, popperElm, referenceElm, props, inject, popperJS }) + const { showPopper, updatePopper, popperElm, referenceElm, doDestroy, popperJS, currentPlacement } = userPopper( + popperParam as any + ) + const state: ITooltipState = initState({ + reactive, + showPopper, + popperElm, + referenceElm, + props, + inject, + popperJS, + currentPlacement + }) Object.assign(api, { state, diff --git a/packages/vue-directive/src/auto-tip.ts b/packages/vue-directive/src/auto-tip.ts index 923070bc6..b5b7ad453 100644 --- a/packages/vue-directive/src/auto-tip.ts +++ b/packages/vue-directive/src/auto-tip.ts @@ -67,6 +67,7 @@ const mouseenterHandler = (e) => { tooltipContent.value = currentTarget.boundingValue?.content || currentTarget.textContent tooltip.state.referenceElm = currentTarget + tooltip.state.currentPlacement = getPlacement(currentTarget) if (popperElm) { popperElm.classList.replace(