fix(components): [popconfirm] fallthrough virtual-ref & virtual-triggering (#22843)

* fix(components): [popconfirm] pass through virtualRef/virtualTriggering

* test: add test
This commit is contained in:
rzzf
2025-11-19 11:54:02 +08:00
committed by GitHub
parent 669585fc43
commit 976ec490e0
2 changed files with 55 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
import { nextTick } from 'vue'
import { nextTick, ref } from 'vue'
import { mount } from '@vue/test-utils'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { rAF } from '@element-plus/test-utils/tick'
@@ -69,6 +69,58 @@ describe('Popconfirm.vue', () => {
)
})
it('should work with virtualTriggering and virtualRef', async () => {
const wrapper = mount({
setup() {
const visible = ref(false)
const virtualRef = ref()
const handleClick = () => {
virtualRef.value = {
getBoundingClientRect: () => {
return {
x: 0,
y: 0,
top: 0,
left: 0,
width: 100,
height: 100,
right: 100,
bottom: 100,
}
},
}
visible.value = true
}
return () => (
<>
<button data-testid="testid" onClick={handleClick}>
test
</button>
<Popconfirm
v-model:visible={visible.value}
virtualRef={virtualRef.value}
virtualTriggering
/>
</>
)
},
})
await nextTick()
const popperEl = document.querySelector(selector)!
expect(popperEl.getAttribute('style')).toContain('display: none')
const button = wrapper.find('button[data-testid="testid"]')
await button.trigger('click')
await nextTick()
await rAF()
const style = popperEl.getAttribute('style')
expect(style).not.toContain('display: none')
expect(style).toContain('transform: translate(0px, 112px)')
})
describe('teleported API', () => {
it('should mount on popper container', async () => {
expect(document.body.innerHTML).toBe('')

View File

@@ -4,6 +4,8 @@
trigger="click"
:effect="effect"
v-bind="$attrs"
:virtual-triggering="virtualTriggering"
:virtual-ref="virtualRef"
:popper-class="`${ns.namespace.value}-popover`"
:popper-style="style"
:teleported="teleported"