Skip to content

Commit ea9390a

Browse files
committed
fix: add and check menuRef to allow interacting with custom elements on touch devices (#6071)
1 parent 052e864 commit ea9390a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

packages/react-select/src/Select.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,10 @@ export default class Select<
671671
getFocusedOptionRef: RefCallback<HTMLDivElement> = (ref) => {
672672
this.focusedOptionRef = ref;
673673
};
674+
menuRef: HTMLDivElement | null = null;
675+
getMenuRef: RefCallback<HTMLDivElement> = (ref) => {
676+
this.menuRef = ref;
677+
};
674678
menuListRef: HTMLDivElement | null = null;
675679
getMenuListRef: RefCallback<HTMLDivElement> = (ref) => {
676680
this.menuListRef = ref;
@@ -1463,6 +1467,8 @@ export default class Select<
14631467
if (
14641468
this.controlRef &&
14651469
!this.controlRef.contains(event.target as Node) &&
1470+
this.menuRef &&
1471+
!this.menuRef.contains(event.target as Node) &&
14661472
this.menuListRef &&
14671473
!this.menuListRef.contains(event.target as Node)
14681474
) {
@@ -2076,7 +2082,10 @@ export default class Select<
20762082
<Menu
20772083
{...commonProps}
20782084
{...menuPlacementProps}
2079-
innerRef={ref}
2085+
innerRef={(instance) => {
2086+
ref.current = instance;
2087+
this.getMenuRef(instance);
2088+
}}
20802089
innerProps={{
20812090
onMouseDown: this.onMenuMouseDown,
20822091
onMouseMove: this.onMenuMouseMove,

packages/react-select/src/components/Menu.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import {
33
createContext,
44
JSX,
5+
MutableRefObject,
56
ReactElement,
67
ReactNode,
78
Ref,
@@ -255,7 +256,7 @@ interface PlacerProps {
255256
}
256257

257258
interface ChildrenProps {
258-
ref: Ref<HTMLDivElement>;
259+
ref: MutableRefObject<HTMLDivElement | null>;
259260
placerProps: PlacerProps;
260261
}
261262

0 commit comments

Comments
 (0)