Skip to content

Commit

Permalink
[TreeView] Add new utility function isEventTargetInDescendants (#13982
Browse files Browse the repository at this point in the history
)
  • Loading branch information
flaviendelangle authored Jul 26, 2024
1 parent 7660e16 commit ad605ff
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/x-tree-view/src/internals/utils/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,14 @@ export const getAllNavigableItems = (

return navigableItems;
};

/**
* Checks if the target is in a descendant of this item.
* This can prevent from firing some logic on the ancestors on the interacted item when the event handler is on the root.
* @param {HTMLElement} target The target to check
* @param {HTMLElement | null} itemRoot The root of the item to check if the event target is in its descendants
* @returns {boolean} Whether the target is in a descendant of this item
*/
export const isTargetInDescendants = (target: HTMLElement, itemRoot: HTMLElement | null) => {
return itemRoot !== target.closest('*[role="treeitem"]');
};

0 comments on commit ad605ff

Please sign in to comment.