Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.

Commit d2d19f1

Browse files
committed
Fix show event no fire when <Float> enabled show
1 parent d00b998 commit d2d19f1

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

packages/react/test/unit/events.test.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,26 @@ describe('Events', () => {
5454
expect(onHide).toHaveBeenCalledTimes(2)
5555
})
5656

57+
// this test is failed because the <Transition>'s beforeEnter and
58+
// afterLeave event is can't correct fired in testing.
59+
it.skip('should fire show when <Float> enabled show', async () => {
60+
const onShow = vi.fn()
61+
62+
render(
63+
<Menu>
64+
<Float show onShow={() => onShow()}>
65+
<Menu.Button>button</Menu.Button>
66+
<Menu.Items static>content</Menu.Items>
67+
</Float>
68+
</Menu>
69+
)
70+
71+
await waitFor()
72+
73+
expect(screen.queryByRole('menu')).toBeInTheDocument()
74+
expect(onShow).toHaveBeenCalledTimes(1)
75+
})
76+
5777
// this test is failed because the <Transition>'s beforeEnter and
5878
// afterLeave event is can't correct fired in testing.
5979
it.skip('don\'t fire show & hide events on input <Combobox>', async () => {

packages/vue/src/float.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ export function useFloat<T extends ReferenceElement>(
452452
} else if (!show && oldShow) {
453453
emit('hide')
454454
}
455-
})
455+
}, { immediate: true })
456456

457457
function updateFloating() {
458458
if (isVisible.value) {

packages/vue/test/unit/events.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,26 @@ describe('Events', () => {
5555
expect(onHide).toHaveBeenCalledTimes(2)
5656
})
5757

58+
it('should fire show when <Float> enabled show', async () => {
59+
const onShow = vi.fn()
60+
61+
render(defineComponent({
62+
components: { Menu, MenuButton, MenuItem, MenuItems, Float },
63+
methods: { onShow },
64+
template: html`
65+
<Menu>
66+
<Float show @show="onShow">
67+
<MenuButton>button</MenuButton>
68+
<MenuItems static>content</MenuItems>
69+
</Float>
70+
</Menu>
71+
`,
72+
}))
73+
74+
expect(screen.queryByRole('menu')).toBeInTheDocument()
75+
expect(onShow).toHaveBeenCalledTimes(1)
76+
})
77+
5878
it('don\'t fire show & hide events on input <Combobox>', async () => {
5979
const onShow = vi.fn()
6080
const onHide = vi.fn()

0 commit comments

Comments
 (0)