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

[ISSUE-6350] - allow onSelect to prevent the default behavior of toggling node collapse #6351

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -23,7 +23,7 @@ export interface TreeViewListItemProps {
defaultExpanded?: boolean;
/** Child nodes of a tree view item */
children?: React.ReactNode;
/** Callback for item selection */
/** Callback for item selection. Note: calling event.preventDefault() will prevent the node from toggling. */
onSelect?: (event: React.MouseEvent, item: TreeViewDataItem, parent: TreeViewDataItem) => void;
/** Callback for item checkbox selection */
onCheck?: (event: React.ChangeEvent, item: TreeViewDataItem, parent: TreeViewDataItem) => void;
Expand Down Expand Up @@ -186,10 +186,10 @@ export const TreeViewListItem: React.FunctionComponent<TreeViewListItemProps> =
)}
onClick={(evt: React.MouseEvent) => {
if (!hasCheck) {
if (children) {
onSelect && onSelect(evt, itemData, parentItem);
if (children && evt.isDefaultPrevented() !== true) {
steverhoades marked this conversation as resolved.
Show resolved Hide resolved
setIsExpanded(!internalIsExpanded);
}
onSelect && onSelect(evt, itemData, parentItem);
}
}}
{...(!children && { role: 'treeitem' })}
Expand Down