-
-
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] Do not re-render every Tree Item when the Rich Tree View re-renders (introduce selectors) #14210
[TreeView] Do not re-render every Tree Item when the Rich Tree View re-renders (introduce selectors) #14210
Changes from all commits
f0c8ac1
a47c95e
e8a385c
0518706
9ea8ab2
2abe440
9e302d2
2307a65
479274f
eb00e1e
e9bbb6d
4b6ae73
99f3f07
a70d3dd
87d1992
3cdc8f2
1181d38
79228ef
4cef1db
66fde8c
4987b9a
451bac2
9302614
3b63a9d
01879e5
f834dca
efae98d
ab57913
d9f5dc9
7492a5e
da44f3a
315c107
f3d1fda
59518ea
96e4287
909ed67
3412fea
41967f2
ad27780
bf00041
bb27ecb
86662f6
608757e
095c407
c0871e3
fb0c67d
2e8eec2
93a8d0f
43d7d3f
21b820c
aaa6c7d
5172348
d10fcc9
5933ee6
7fdd27d
4c37ec2
4d125f6
fa353bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ import { | |
import { TreeItemIcon } from '@mui/x-tree-view/TreeItemIcon'; | ||
import { TreeItemProvider } from '@mui/x-tree-view/TreeItemProvider'; | ||
import { TreeItemDragAndDropOverlay } from '@mui/x-tree-view/TreeItemDragAndDropOverlay'; | ||
import { useTreeItemModel } from '@mui/x-tree-view/hooks'; | ||
|
||
const ITEMS = [ | ||
{ | ||
|
@@ -178,13 +179,6 @@ function CustomLabel({ icon: Icon, expandable, children, ...other }) { | |
); | ||
} | ||
|
||
const isExpandable = (reactChildren) => { | ||
if (Array.isArray(reactChildren)) { | ||
return reactChildren.length > 0 && reactChildren.some(isExpandable); | ||
} | ||
return Boolean(reactChildren); | ||
}; | ||
|
||
const getIconFromFileType = (fileType) => { | ||
switch (fileType) { | ||
case 'image': | ||
|
@@ -210,6 +204,7 @@ const CustomTreeItem = React.forwardRef(function CustomTreeItem(props, ref) { | |
const { id, itemId, label, disabled, children, ...other } = props; | ||
|
||
const { | ||
getContextProviderProps, | ||
getRootProps, | ||
getContentProps, | ||
getIconContainerProps, | ||
|
@@ -218,20 +213,19 @@ const CustomTreeItem = React.forwardRef(function CustomTreeItem(props, ref) { | |
getGroupTransitionProps, | ||
getDragAndDropOverlayProps, | ||
status, | ||
publicAPI, | ||
} = useTreeItem({ id, itemId, children, label, disabled, rootRef: ref }); | ||
|
||
const item = publicAPI.getItem(itemId); | ||
const expandable = isExpandable(children); | ||
const item = useTreeItemModel(itemId); | ||
|
||
let icon; | ||
if (expandable) { | ||
if (status.expandable) { | ||
icon = FolderRounded; | ||
} else if (item.fileType) { | ||
icon = getIconFromFileType(item.fileType); | ||
} | ||
|
||
return ( | ||
<TreeItemProvider itemId={itemId}> | ||
<TreeItemProvider {...getContextProviderProps()}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a very dumb BC... Why? I should have created |
||
<StyledTreeItemRoot {...getRootProps(other)}> | ||
<CustomTreeItemContent | ||
{...getContentProps({ | ||
|
@@ -248,7 +242,10 @@ const CustomTreeItem = React.forwardRef(function CustomTreeItem(props, ref) { | |
</TreeItemIconContainer> | ||
<TreeItemCheckbox {...getCheckboxProps()} /> | ||
<CustomLabel | ||
{...getLabelProps({ icon, expandable: expandable && status.expanded })} | ||
{...getLabelProps({ | ||
icon, | ||
expandable: status.expandable && status.expanded, | ||
})} | ||
/> | ||
<TreeItemDragAndDropOverlay {...getDragAndDropOverlayProps()} /> | ||
</CustomTreeItemContent> | ||
|
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 looks like a typo, shouldn't it be
per the rest of the API conversion? We could add this to https://mui.com/material-ui/guides/api/.
Off-topic: Seeing "public" in the name feels a bit strange, it feels a bit like a tautology: if it's documented, it's public.
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.
Both remark are totally valid.
It's
publicAPI
( /publicApi
) internally, but when exposed it should probably beapi