Menu trigger does not work in tests #1921
Unanswered
bohdanbirdie
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Current workaround is to use |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
🐛 Bug report
Originally coming from the use of ParkUI, but I narrowed down the bug to
zag
.When using Menu component and running tests on it, specifically calling
userEvent.click()
on trigger -preventDefault
is causing the menu not to open.Exact source:
zag/packages/machines/menu/src/menu.connect.ts
Line 197 in a58f2d0
If I manually remove
preventDetault()
call innode_modules
then it works all right.As an experiment, I created a plain button in React and added
onPointerDown
andonClick
events. When click is triggered withuserEvent.click
theonPointerDown
is called first and thenonClick
after it. But preventing default forcesonClick
to never be called.I doubt that issue is on the side of
react-testing-library
as it works fine with plain HTML buttons. They simulate the click the same was it's done by user. If you add eventsonClick={console.log} onPointerDown={console.log}
to theMenu.Trigger
you will see that both events were triggered by manually clicking the button.💥 Steps to reproduce
npm install
npm run test
npx patch-package
to apply patch on the source codenpm run test
💻 Link to reproduction
Whore repro project:
https://github.com/bohdanbirdie/zag-events
Specific test:
https://github.com/bohdanbirdie/zag-events/blob/main/src/App.test.tsx
🧐 Expected behavior
ProinterDown even is not prevented on default behavior.
🧭 Possible Solution
Remove prevent default call.
🌍 System information
[email protected] /Users/bohdanptyts/dev/repos/zag-events/zag-events
├─┬ @ark-ui/[email protected]
│ └── @zag-js/[email protected]
└─┬ @park-ui/[email protected]
└─┬ @ark-ui/[email protected]
└── @zag-js/[email protected]
Beta Was this translation helpful? Give feedback.
All reactions