Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2e0ce2a

Browse files
committed
fix(tooltip): correct the opposite shift direction
1 parent 3210ee7 commit 2e0ce2a

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

components/tooltip/tooltip.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,23 @@ export default defineComponent({
119119
const popper = ref<PopperExposed>()
120120
const popperEl = computed(() => popper.value?.wrapper)
121121
const arrow = ref<HTMLElement>()
122-
const shift = computed<{ mainAxis?: boolean, crossAxis?: boolean }>(() => {
122+
const shift = computed<{ mainAxis: boolean, crossAxis: boolean }>(() => {
123123
if (!props.shift) {
124-
return { mainAxis: false }
124+
return { mainAxis: false, crossAxis: false }
125125
}
126126

127127
if (props.shift === true || props.shift === 'both') {
128-
return { crossAxis: true }
128+
return { mainAxis: true, crossAxis: true }
129129
}
130130

131-
return props.shift === 'horizontal' ? { mainAxis: false, crossAxis: true } : {}
131+
const side = placement.value.split('-')[0]
132+
133+
return props.shift === (side === 'top' || side === 'bottom' ? 'vertical' : 'horizontal')
134+
? { mainAxis: false, crossAxis: true }
135+
: {
136+
mainAxis: true,
137+
crossAxis: false,
138+
}
132139
})
133140
const { transferTo, updatePopper } = usePopper({
134141
placement,

docs/en-US/component/tooltip.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,16 @@ type TooltipShift = 'horizontal' | 'vertical' | 'both'
107107

108108
type TooltipVirtual =
109109
| {
110-
getBoundingClientRect: () => DOMRect
110+
getBoundingClientRect: () => DOMRect,
111111
}
112112
| {
113113
$el: {
114-
getBoundingClientRect: () => DOMRect
115-
}
114+
getBoundingClientRect: () => DOMRect,
115+
},
116116
}
117117
| {
118118
x: number,
119-
y: number
119+
y: number,
120120
}
121121
```
122122

docs/zh-CN/component/tooltip.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,16 @@ type TooltipShift = 'horizontal' | 'vertical' | 'both'
107107

108108
type TooltipVirtual =
109109
| {
110-
getBoundingClientRect: () => DOMRect
110+
getBoundingClientRect: () => DOMRect,
111111
}
112112
| {
113113
$el: {
114-
getBoundingClientRect: () => DOMRect
115-
}
114+
getBoundingClientRect: () => DOMRect,
115+
},
116116
}
117117
| {
118118
x: number,
119-
y: number
119+
y: number,
120120
}
121121
```
122122

0 commit comments

Comments
 (0)