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 prop onItemClick on the Tree View components #14018

Merged
merged 6 commits into from
Jul 30, 2024

Conversation

flaviendelangle
Copy link
Member

@flaviendelangle flaviendelangle commented Jul 29, 2024

Closes #12839

I think I'll add a similar doc for onItemFocus because we don't have any...

@flaviendelangle flaviendelangle self-assigned this Jul 29, 2024
@flaviendelangle flaviendelangle added the component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! label Jul 29, 2024
@@ -272,8 +272,11 @@ export const useTreeViewItems: TreeViewPlugin<UseTreeViewItemsSignature> = ({
areItemUpdatesPrevented,
},
contextValue: {
disabledItemsFocusable: params.disabledItemsFocusable,
indentationAtItemLevel: experimentalFeatures.indentationAtItemLevel ?? false,
items: {
Copy link
Member Author

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.
Copy link
Member Author

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

@@ -82,6 +81,8 @@ export const useTreeItem2 = <
const createContentHandleClick =
(otherHandlers: EventHandlers) => (event: React.MouseEvent & MuiCancellableEvent) => {
otherHandlers.onClick?.(event);
onItemClick?.(event, itemId);
Copy link
Member Author

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.

@mui-bot
Copy link

mui-bot commented Jul 29, 2024

@LukasTy LukasTy changed the title [pickers] Add new prop onItemClick on the Tree View components [TreeView] Add new prop onItemClick on the Tree View components Jul 29, 2024
@flaviendelangle flaviendelangle marked this pull request as ready for review July 29, 2024 12:51
@@ -96,6 +97,7 @@ export function useTreeItemState(itemId: string) {
handleExpansion,
handleSelection,
handleCheckboxSelection,
handleContentClick: onItemClick,
Copy link
Member Author

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.

Copy link
Contributor

@noraleonte noraleonte left a 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 ⚡

@LukasTy LukasTy added the enhancement This is not a bug, nor a new feature label Jul 29, 2024
Copy link
Member

@arthurbalduini arthurbalduini left a 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?

@flaviendelangle
Copy link
Member Author

Just one question: is it of any interest to make onClick explicitly unsupported as it is done for onFocus?

I don't think so
For onFocus it made sense because until a few months ago the focus remained on the Tree View item and the item was just visually focused.
Now that the focus is on the item, I would even remove this warning and support the onFocus prop.

@flaviendelangle flaviendelangle merged commit acfcb3b into mui:master Jul 30, 2024
17 checks passed
@flaviendelangle flaviendelangle deleted the onItemClick branch July 30, 2024 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! enhancement This is not a bug, nor a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[TreeView] onClick on RichTreeView component is invoked twice
5 participants