Material-ui: Select doesn't respond to click event through code

Created on 15 Jan 2020  路  8Comments  路  Source: mui-org/material-ui


Hi, i'm trying to test my select component with puppeteer.

  • [x] The issue is present in the latest release.
  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 馃槸

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

Expected Behavior 馃

document.querySelector('[data-testid="my-select"] [role="button"]').click()
should trigger the click event on the select and open the component

Context 馃敠

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.

Your Environment 馃寧

| Tech | Version |
| ----------- | ------- |
| Material-UI | v4.8.3 |
| React | v16.8.5 |
| Jest | v24.8.0 |
| Puppeteer | v2.0.0 |
| etc. | |

bug 馃悰 Select good to take

Most helpful comment

@oliviertassinari , thank you! This is exactly I've suggested to implement. I'll do it

All 8 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

finaiized picture finaiized  路  3Comments

newoga picture newoga  路  3Comments

revskill10 picture revskill10  路  3Comments

ghost picture ghost  路  3Comments

mb-copart picture mb-copart  路  3Comments