-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Fix event handling with react-beautiful-dnd #5842
base: master
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 16b4be7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 16b4be7:
|
@@ -1293,10 +1293,6 @@ export default class Select< | |||
onControlMouseDown = ( | |||
event: React.MouseEvent<HTMLDivElement> | React.TouchEvent<HTMLDivElement> | |||
) => { | |||
// Event captured by dropdown indicator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a test for this particular use case - dropdown indicator preventing default event (
react-select/packages/react-select/src/Select.tsx
Line 1345 in 06e3488
event.preventDefault(); |
Also, not quite clear why stopPropagation
is not a case, onMenuMouseDown
uses it (uses both) for example.
This code was added here for a reason, and I can see other pieces relying on this one. Basically - all .preventDefault
in this file.
What if we try to change the game rules and just rely on a different information source?
const createEventTracker = () => {
const tracker = new WeakSet();
return {
mark: (event) => {
tracker.add(event.target);
Promise.resolve().then(() => tracker.delete(event.target);
},
isMarked: (event) => tracker.has(event.target);
}
}
/// ....
const mouseDownTracker = createEventTracker();
onDropdownIndicatorMouseDown = (e) => {
// ...
mouseDownTracker.mark(e);
}
onControlMouseDown = (event) => {
// Event captured by dropdown indicator
if (mouseDownTracker.isMarked(event)) {
return;
}
}
Might be a little too much code to support a single line, but this code will keep the old behavior and unlock our usecase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This prevent default was added in #5134 — I can't imagine anything in Select is leaning on it?
We can definitely change the rules like you said if the behaviour is needed. I'm just not sure it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The failing tests might point to it being needed I suppose ;).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, and you added tests for #5050 case, and they are passing. May be something else in between, including changes in DatePicker resolved the problem in the meanwhile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah you're right, which is what the tests are showing now. I'll dig in soon.
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
This pull request removes logic to bail out from an event if someone else listening to the event (usually in a capture phase) has called
preventDefault()
. This fixes interop betweenreact-select
andreact-beautiful-dnd
.To ensure things don't regress, and to ensure to not contradict what was solved in #5134 I've added four e2e tests covering the various flows in both:
All tests pass, the same behaviour remains, hopefully we're good to go.
TODO
Closes #5833