Skip to content

Commit

Permalink
Merge branch 'master' into infra/test-vite
Browse files Browse the repository at this point in the history
  • Loading branch information
mj12albert authored Jan 3, 2025
2 parents 4b8a17e + f8db0db commit bed9194
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/react/src/select/item/useSelectItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,28 @@ export function useSelectItem(params: useSelectItem.Parameters): useSelectItem.R
prevPopupHeightRef.current = popupRef.current.offsetHeight;
}
},
onMouseLeave() {
onMouseLeave(event) {
const popup = popupRef.current;
if (!popup || !open) {
return;
}

const targetRect = event.currentTarget.getBoundingClientRect();

// Safari randomly fires `mouseleave` incorrectly when the item is
// aligned to the trigger. This is a workaround to prevent the highlight
// from being removed while the cursor is still within the bounds of the item.
// https://github.com/mui/base-ui/issues/869
const isWithinBounds =
targetRect.top + 1 <= event.clientY &&
event.clientY <= targetRect.bottom - 1 &&
targetRect.left + 1 <= event.clientX &&
event.clientX <= targetRect.right - 1;

if (isWithinBounds) {
return;
}

// With `alignItemToTrigger`, avoid re-rendering the root due to `onMouseLeave`
// firing and causing a performance issue when expanding the popup.
if (popup.offsetHeight === prevPopupHeightRef.current) {
Expand Down

0 comments on commit bed9194

Please sign in to comment.