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] Allow to customize the indentation of nested items #13225

Merged
merged 13 commits into from
May 28, 2024

Conversation

flaviendelangle
Copy link
Member

@flaviendelangle flaviendelangle commented May 23, 2024

Extracted from #12213
Follow up on #13126

@flaviendelangle flaviendelangle self-assigned this May 23, 2024
@flaviendelangle flaviendelangle added the component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! label May 23, 2024
pathname: '/x/react-tree-view/common-features',
subheader: 'Common features',
children: [
{ pathname: '/x/react-tree-view/tree-item-customization', title: 'Item customization' },
Copy link
Member Author

@flaviendelangle flaviendelangle May 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took the opportunity to create this page we were talking about
It will also host all the doc about useTreeItem2 usage and TreeItem2 slot usage.

Should we also move Accessibility here?

Would you put it below or above the components?
On the charts and pickers it's below so I did the same here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the Accessibility page should definitely be in common features 🤔
And having this section above somehow makes more sense to me - but I'm flexible on this one


{{"demo": "ItemChildrenIndentationPxProp.js"}}

:::success
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was super explicit with those :::success
This one will be simplified in v8 once we drop the experimental feature and the other one will just disappear with all the doc around the experimental feature.

@mui-bot
Copy link

mui-bot commented May 23, 2024

@flaviendelangle flaviendelangle marked this pull request as ready for review May 23, 2024 16:50
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.

Nice addition 🎉 Leaving a few comments 👇

pathname: '/x/react-tree-view/common-features',
subheader: 'Common features',
children: [
{ pathname: '/x/react-tree-view/tree-item-customization', title: 'Item customization' },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the Accessibility page should definitely be in common features 🤔
And having this section above somehow makes more sense to me - but I'm flexible on this one

* Indentation in pixels between two an item and its children.
* @default 12
*/
itemChildrenIndentationPx: PropTypes.number,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this should always be in px 🤔
How would we support other units? Would we have a prop for each? I think having this prop called itemChildrenIndentation and allowing for different units as well (with a fallback to px) is a far better dx - but maybe I'm missing something in terms of feasibility

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one place in the drag & drop where we need to use the value in pixels:

      if (validActions['move-to-parent'] && cursorX < params.itemChildrenIndentationPx) {
        action = 'move-to-parent';
      }

If we can convert the value it's fine, but it would be hard to support all units I guess.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how we could handle this, because I do agree with you that forcing the usage of pixels it not optimal

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can convert the value it's fine

Oh, I see. 🤔 There is a way using a temporary element and getComputedStyle but it's kind of hacky IMO 🙈
We can go with the px value for now I think

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's kind of hacky

And for stuff like % or em it would still be problematic 😬

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, true 🙈

packages/x-tree-view/src/TreeView/TreeView.tsx Outdated Show resolved Hide resolved
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.

Nice addition 🎉

* Indentation in pixels between two an item and its children.
* @default 12
*/
itemChildrenIndentationPx: PropTypes.number,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can convert the value it's fine

Oh, I see. 🤔 There is a way using a temporary element and getComputedStyle but it's kind of hacky IMO 🙈
We can go with the px value for now I think

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.

Looking good 👌 🎉 Small comment about the description of the prop

@flaviendelangle flaviendelangle merged commit d6c8a60 into mui:master May 28, 2024
17 checks passed
@flaviendelangle flaviendelangle deleted the custom-indentation branch May 28, 2024 12:58
@flaviendelangle flaviendelangle mentioned this pull request May 30, 2024
13 tasks
DungTiger pushed a commit to DungTiger/mui-x that referenced this pull request Jul 23, 2024
thomasmoon pushed a commit to thomasmoon/mui-x that referenced this pull request Sep 9, 2024
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!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants