Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TreeView] Add new utility function isEventTargetInDescendants #13982

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]');
};