Skip to content

Commit

Permalink
fix: use internal member to check if control onMouseDown should act
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mdo2 committed Jan 22, 2024
1 parent 06e3488 commit c64801c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/react-select/src/Select.tsx
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

0 comments on commit c64801c

Please sign in to comment.