Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changeset/selfish-timers-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'react-select': patch
---

Use an internal member to check if control onMouseDown should act and remove logic to bail out from an event if someone else listening to the event (usually in a capture phase) has called preventDefault().

This change was initiated to fix the interop between react-select and react-beautiful-dnd.
But has meaning on its own because it is pretty clear that using the `defaultPrevented` event property for custom logic is a really bad practice.
So, another way to filter when we want to trigger control onMouseDown normal logic has to be better defined and developed.

Nothing to update from the consumers.
9 changes: 7 additions & 2 deletions packages/react-select/src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ export default class Select<
scrollToFocusedOptionOnUpdate = false;
userIsDragging?: boolean;
isAppleDevice = isAppleDevice();
mouseDownTriggeredBeyondControl = false;

// Refs
// ------------------------------
Expand Down Expand Up @@ -1293,8 +1294,9 @@ export default class Select<
onControlMouseDown = (
event: React.MouseEvent<HTMLDivElement> | React.TouchEvent<HTMLDivElement>
) => {
// Event captured by dropdown indicator
if (event.defaultPrevented) {
// Event captured somewhere deeper in the DOM
if (this.mouseDownTriggeredBeyondControl) {
this.mouseDownTriggeredBeyondControl = false;
return;
}
const { openMenuOnClick } = this.props;
Expand Down Expand Up @@ -1342,6 +1344,7 @@ export default class Select<
} else {
this.openMenu('first');
}
this.mouseDownTriggeredBeyondControl = true;
event.preventDefault();
};
onClearIndicatorMouseDown = (
Expand All @@ -1356,6 +1359,7 @@ export default class Select<
return;
}
this.clearValue();
this.mouseDownTriggeredBeyondControl = true;
event.preventDefault();
this.openAfterFocus = false;
if (event.type === 'touchend') {
Expand Down Expand Up @@ -1835,6 +1839,7 @@ export default class Select<
onClick: () => this.removeValue(opt),
onTouchEnd: () => this.removeValue(opt),
onMouseDown: (e) => {
this.mouseDownTriggeredBeyondControl = true;
e.preventDefault();
},
}}
Expand Down