mui / mui-x

MUI X: Build complex and data-rich applications using a growing list of advanced React components, like the Data Grid, Date and Time Pickers, Charts, and more!
https://mui.com/x/
3.79k stars 1.12k forks source link

[tree view] allow expanding nodes that are empty #12818

Closed ericandoh closed 2 weeks ago

ericandoh commented 2 weeks ago

Summary

in v6 of treeview, you could pass in [] as children to a TreeView component (say, an empty folder) and it'd render a row that was expandable, but on expand, it would show no children.

in v7, with [] passed to the children, the node no longer becomes expandable. you can see this in the file explorer example: https://mui.com/x/react-tree-view/rich-tree-view/customization/#file-explorer (Personal is a folder but not expandable)

Wondering if being able to pass in empty children to a node will be supported in future or if this is a design decision to not make nodes expandable that have explicitly no children.

Thanks!

Examples

https://mui.com/x/react-tree-view/rich-tree-view/customization/#file-explorer

Motivation

The use case for us is showing folders as different from files, but allowing expanding folders even if empty.

Search keywords: treeview empty expand

michelengelen commented 2 weeks ago

@flaviendelangle this is a good question. Do we plan to allow for that? Maybe have a disabled toggle or something?

flaviendelangle commented 2 weeks ago

The change comes from #11963

I think the change we made to the default behavior made sense, the item are expandable when they have some children. One of the benefit is that now we are sure that if an item is expandable, we can take it's first children without fear of crashes (before this change it would have been super easy to access the 1st children of an empty but expandable item and have a crash in our codebase).

The use case for us is showing folders as different from files, but allowing expanding folders even if empty.

But if the folder is empty, expanding it will do nothing, right?


Side note, in the future we need to support children lazy loading (#9687) to the RichTreeView component. This will require us to add a property like isNodeExpandable or doesNodeHaveChildren (not great names tbh). But this is not your use-case either...

ericandoh commented 2 weeks ago

Thanks, and yep we're also using this partially for lazy loading (we have a custom implementation currently) but we'll move to your implementation once its built. Thanks for the thought out response.

github-actions[bot] commented 2 weeks ago

:warning: This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue. Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

@ericandoh: How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.