Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select behaves inconsistently when receiving a mousedown event with defaultPrevented #5833

Open
AndrewOCC opened this issue Dec 20, 2023 · 0 comments · May be fixed by #5842 or #5851
Open

Select behaves inconsistently when receiving a mousedown event with defaultPrevented #5833

AndrewOCC opened this issue Dec 20, 2023 · 0 comments · May be fixed by #5842 or #5851
Labels
issue/bug-unconfirmed Issues that describe a bug that hasn't been confirmed by a maintainer yet

Comments

@AndrewOCC
Copy link

Summary

In version 5.3 of react-select, a check for defaultPrevented was added to the onMouseDown event for the Select control, in order to prevent double events when clicking on the dropdown button or other interactive elements inside the Select: #5134.

This has prevented double events, but as a side-effect, it changed how Select responds to preventDefault. Now, if an onMouseDown event has default prevented before it reaches Select, the component behaves inconsistently. If the user presses on the dropdown, it still opens the select - but if the user presses the container, it doesn't.

This manifests most noticeably when a parent element calls preventDefault during the capture phase; an example of a library that does this is react-beautiful-dnd.

This may be in the realm of undefined behaviour, but an alternate approach to preventing duplicate events would provide more consistent behaviour for Select, and avoid edge cases like this where part of a select is interactive, but not others.

Steps to reproduce

Minimal reproduction: https://codesandbox.io/p/sandbox/reproduction-select-with-a-preventdefault-parent-656c4l?file=%2Findex.tsx%3A57%2C28

Try pressing the selects, on the input, on the dropdown button, and on the main container. I've included a minimal example, as well as an example of the component inside react-beautiful-dnd

Related issues

This issue triggered another consumer of react-select and RBD to refactor: grafana/grafana#50025

@AndrewOCC AndrewOCC added the issue/bug-unconfirmed Issues that describe a bug that hasn't been confirmed by a maintainer yet label Dec 20, 2023
@AndrewOCC AndrewOCC changed the title Select behaves inconsistently when receiving event with defaultPrevented Select behaves inconsistently when receiving a mousedown event with defaultPrevented Dec 20, 2023
@itsdouges itsdouges linked a pull request Jan 9, 2024 that will close this issue
2 tasks
mdo2 added a commit to mdo2/react-select that referenced this issue Jan 22, 2024
This is intended to be a temporal fix, as I think a better solution must be developed.

Referenced issues: JedWatson#5833, JedWatson#5176

Another PRs abaout this: JedWatson#5842
@mdo2 mdo2 linked a pull request Jan 22, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue/bug-unconfirmed Issues that describe a bug that hasn't been confirmed by a maintainer yet
Projects
None yet
1 participant