@@ -44,23 +44,26 @@ function App() {
4444 renderItemArrow= {({ item, context }) =>
4545 item .isFolder ? < span {... context .arrowProps }> {context .isExpanded ? ' v ' : ' > ' }< / span> : null
4646 }
47- renderItem= {({ title, arrow, depth, context, children }) => (
48- < li
49- {... context .itemContainerWithChildrenProps }
50- style= {{
51- margin: 0 ,
52- display: ' flex' ,
53- flexDirection: ' column' ,
54- alignItems: ' flex-start' ,
55- }}
56- >
57- < button {... context .itemContainerWithoutChildrenProps } {... context .interactiveElementProps }>
58- {arrow}
59- {title}
60- < / button>
61- {children}
62- < / li>
63- )}
47+ renderItem= {({ title, arrow, depth, context, children }) => {
48+ const InteractiveComponent = context .isRenaming ? ' div' : ' button' ;
49+ return (
50+ < li
51+ {... context .itemContainerWithChildrenProps }
52+ style= {{
53+ margin: 0 ,
54+ display: ' flex' ,
55+ flexDirection: ' column' ,
56+ alignItems: ' flex-start' ,
57+ }}
58+ >
59+ < InteractiveComponent {... context .itemContainerWithoutChildrenProps } {... context .interactiveElementProps }>
60+ {arrow}
61+ {title}
62+ < / InteractiveComponent>
63+ {children}
64+ < / li>
65+ );
66+ }}
6467 renderTreeContainer= {({ children, containerProps }) => < div {... containerProps}> {children}< / div> }
6568 renderItemsContainer= {({ children, containerProps }) => < ul {... containerProps}> {children}< / ul> }
6669 >
@@ -105,22 +108,25 @@ for example because you want to implement a virtualized list, you can do so by r
105108item container:
106109
107110``` jsx
108- renderItem= {({ title, arrow, depth, context, children }) => (
109- <>
110- < li
111- {... context .itemContainerWithChildrenProps }
112- >
113- < button
114- {... context .itemContainerWithoutChildrenProps }
115- {... context .interactiveElementProps }
111+ renderItem= {({ title, arrow, depth, context, children }) => {
112+ const InteractiveComponent = context .isRenaming ? ' div' : ' button' ;
113+ return (
114+ <>
115+ < li
116+ {... context .itemContainerWithChildrenProps }
116117 >
117- { arrow }
118- { title }
119- < / button>
120- < / li>
121- {children}
122- < / >
123- )}
118+ < button
119+ {... context .itemContainerWithoutChildrenProps }
120+ {... context .interactiveElementProps }
121+ >
122+ { arrow }
123+ { title }
124+ < / button>
125+ < / li>
126+ {children}
127+ < / >
128+ );
129+ }}
124130```
125131
126132Make sure to provide the props-objects ` context.itemContainerWithoutChildrenProps ` and
@@ -138,3 +144,11 @@ Note that, if you want to customize the way how mouse clicks interact with the t
138144clicking on a parent node should expand it or just focus it) should not be changed by providing custom
139145DOM hooks, but by choosing a different interaction mode.
140146[ Read more on interaction modes here] ( /docs/guides/interaction-modes ) .
147+
148+ :::caution
149+
150+ The ` InteractiveComponent = context.isRenaming ? 'div' : 'button' ` is important in case you want to
151+ support renaming items. If the tree item is always rendered as button, it's focusing behavior will
152+ cause a blur event when the rename starts, and revert the item back to the non-renaming state.
153+
154+ :::
0 commit comments