Skip to content

Commit

Permalink
fix: update selector to ensure correct portalled element
Browse files Browse the repository at this point in the history
  • Loading branch information
mgadewoll committed Nov 13, 2024
1 parent f954160 commit badbb7d
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,24 @@ export const DraggableColumn: FunctionComponent<{
const { setFocusedCell } = useContext(DataGridFocusContext);
const handleOnMouseDown: MouseEventHandler = useCallback(
(e) => {
const openFocusTrap = document.querySelector(
const openFocusTraps = document.querySelectorAll(
'[data-focus-lock-disabled="false"]'
);
if (
!!openFocusTrap && // If a focus trap is open somewhere on the page
!openFocusTrap.contains(e.target as Node) && // & the focus trap doesn't belong to this header
e.target !== actionsPopoverToggle // & we're not closing the actions popover toggle
) {
const validOpenFocusTraps = [...openFocusTraps].filter(
(focusTrap) =>
!focusTrap.querySelector('.euiModal') && // if it's not a modal
!focusTrap.contains(e.target as Node) // & if it doesn't contain the target
);

const shouldDispatchEvent = validOpenFocusTraps.some(
(focusTrap) =>
!!focusTrap && // If there is a focus trap is open
e.target !== actionsPopoverToggle // & we're not closing the actions popover toggle
);

if (shouldDispatchEvent) {
// Trick the focus trap lib into registering an outside click -
// the drag/drop lib otherwise otherwise prevents the event 💀
// the drag/drop lib otherwise prevents the event 💀
document.dispatchEvent(new MouseEvent('mousedown'));
}
setTimeout(() => {
Expand Down

0 comments on commit badbb7d

Please sign in to comment.