Skip to content

Commit

Permalink
Fix Firefox close on mousedown
Browse files Browse the repository at this point in the history
  • Loading branch information
atomiks committed Oct 20, 2024
1 parent 857f476 commit 852bd3d
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions packages/mui-base/src/Select/Trigger/useSelectTrigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ export function useSelectTrigger(
setOpen,
setTriggerElement,
selectionRef,
popupRef,
value,
getValidationProps,
commitValidation,
setTouchModality,
positionerElement,
} = useSelectRootContext();

const { labelId, setTouched } = useFieldRootContext();
Expand All @@ -49,12 +49,12 @@ export function useSelectTrigger(

React.useEffect(() => {
if (open) {
timeoutRef.current = window.setTimeout(() => {
const timeoutId = window.setTimeout(() => {
selectionRef.current.allowMouseUp = true;
}, 400);

return () => {
window.clearTimeout(timeoutRef.current);
clearTimeout(timeoutId);
};
}

Expand All @@ -63,6 +63,8 @@ export function useSelectTrigger(
allowSelect: true,
};

clearTimeout(timeoutRef.current);

return undefined;
}, [open, selectionRef]);

Expand Down Expand Up @@ -108,7 +110,7 @@ export function useSelectTrigger(

if (
isInsideTrigger ||
contains(popupRef.current, mouseUpTarget) ||
contains(positionerElement, mouseUpTarget) ||
contains(triggerRef.current, mouseUpTarget)
) {
return;
Expand All @@ -117,7 +119,10 @@ export function useSelectTrigger(
setOpen(false, mouseEvent);
}

doc.addEventListener('mouseup', handleMouseUp, { once: true });
// Firefox can fire this upon mousedown
timeoutRef.current = window.setTimeout(() => {
doc.addEventListener('mouseup', handleMouseUp, { once: true });
});
},
},
getButtonProps(),
Expand All @@ -133,7 +138,7 @@ export function useSelectTrigger(
value,
setTouchModality,
open,
popupRef,
positionerElement,
setOpen,
],
);
Expand Down

0 comments on commit 852bd3d

Please sign in to comment.