Hi, i'm trying to test my select component with puppeteer.
i'm trying this:
document.querySelector('[data-testid="my-select"] [role="button"]').click()
and it seems to do nothing.
it worked before in version 4.6.1
also it seems that since that version right click on Select also open the component what didn't happened in the version 4.6.1
document.querySelector('[data-testid="my-select"] [role="button"]').click()
should trigger the click event on the select and open the component
this issue effecting on all my tests (unit tests, ui tests).
because i can't find a way to trigger click event on the select through code.
| Tech | Version |
| ----------- | ------- |
| Material-UI | v4.8.3 |
| React | v16.8.5 |
| Jest | v24.8.0 |
| Puppeteer | v2.0.0 |
| etc. | |
See #18655.
also it seems that since that version right-click on Select also open the component what didn't happen in the version
Interesting.
also it seems that since that version right click on Select also open the component what didn't happened in the version 4.6.1
This is indeed a bug. The native select does not open if the right mouse button is down. Probably only responds to left mouse button down.
i'm not using react-testing library so i didn't understood how #18655 can help me.
what do you think i can do to trigger the click event?
@dudif Trigger a mouse down.
also it seems that since that version right-click on Select also open the component what didn't happen in the version
Interesting.
In PR https://github.com/mui-org/material-ui/pull/17978 onClick event listerner has been replaced by onMouseDown event listerner. But onMouseDown is fired on any mouse button click. onClick was fired on left (primary) button click (See https://www.w3schools.com/jsref/event_onmousedown.asp).
To resolve, I may suggest to check if primary button clicked in the onMouseDown event handler
@oliviertassinari , thank you! This is exactly I've suggested to implement. I'll do it
Most helpful comment
@oliviertassinari , thank you! This is exactly I've suggested to implement. I'll do it