-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 prop onItemClick
on the Tree View components
#14018
Conversation
@@ -272,8 +272,11 @@ export const useTreeViewItems: TreeViewPlugin<UseTreeViewItemsSignature> = ({ | |||
areItemUpdatesPrevented, | |||
}, | |||
contextValue: { | |||
disabledItemsFocusable: params.disabledItemsFocusable, | |||
indentationAtItemLevel: experimentalFeatures.indentationAtItemLevel ?? false, | |||
items: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost all the contextValue
properties are now scoped by plugin.
This is not a BC, the context is never directly exposed.
@@ -40,10 +40,9 @@ export interface UseTreeViewFocusInstance extends UseTreeViewFocusPublicAPI { | |||
|
|||
export interface UseTreeViewFocusParameters { | |||
/** | |||
* Callback fired when tree items are focused. | |||
* Callback fired when a given tree item is focused. | |||
* @param {React.SyntheticEvent} event The DOM event that triggered the change. **Warning**: This is a generic event not a focus event. | |||
* @param {string} itemId The id of the focused item. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea where this value
came from but it was wrong
da9fef1
to
b7aeded
Compare
@@ -82,6 +81,8 @@ export const useTreeItem2 = < | |||
const createContentHandleClick = | |||
(otherHandlers: EventHandlers) => (event: React.MouseEvent & MuiCancellableEvent) => { | |||
otherHandlers.onClick?.(event); | |||
onItemClick?.(event, itemId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another advantage of firing onItemClick
here, people can easily use event.defaultMuiPrevented
to prevent some built in logic.
onItemClick
on the Tree View componentsonItemClick
on the Tree View components
@@ -96,6 +97,7 @@ export function useTreeItemState(itemId: string) { | |||
handleExpansion, | |||
handleSelection, | |||
handleCheckboxSelection, | |||
handleContentClick: onItemClick, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This hook will be removed in v8 since it's only used on the legacy component
So I just returned onItemClick
to give a way for people using ContentComponent
to handle the new prop, but I don't expect it to be widely used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👌 Thanks for tackling this so fast ⚡
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, very cool addition ! 🚀
Just one question: is it of any interest to make onClick
explicitly unsupported as it is done for onFocus
?
I don't think so |
Closes #12839
I think I'll add a similar doc for
onItemFocus
because we don't have any...