@@ -105,6 +105,7 @@ export default function JSONNestedNode(props: Props) {
105
105
expandable,
106
106
getItemString,
107
107
hideRoot,
108
+ hideRootExpand,
108
109
isCircular,
109
110
keyPath,
110
111
labelRenderer,
@@ -114,14 +115,20 @@ export default function JSONNestedNode(props: Props) {
114
115
shouldExpandNodeInitially,
115
116
} = props ;
116
117
118
+ const isRoot = keyPath [ 0 ] === "root" ;
119
+ const showExpand = hideRootExpand
120
+ ? expandable && ! isRoot && hideRootExpand
121
+ : expandable ;
122
+ const isNodeExpandable = expandable && showExpand ;
123
+
117
124
const [ expanded , setExpanded ] = useState < boolean > (
118
125
// calculate individual node expansion if necessary
119
126
isCircular ? false : shouldExpandNodeInitially ( keyPath , data , level ) ,
120
127
) ;
121
128
122
129
const handleClick = useCallback ( ( ) => {
123
- if ( expandable ) setExpanded ( ! expanded ) ;
124
- } , [ expandable , expanded ] ) ;
130
+ if ( isNodeExpandable ) setExpanded ( ! expanded ) ;
131
+ } , [ isNodeExpandable , expanded ] ) ;
125
132
126
133
const renderedChildren =
127
134
expanded || ( hideRoot && level === 0 )
@@ -142,11 +149,11 @@ export default function JSONNestedNode(props: Props) {
142
149
createItemString ( data , collectionLimit ) ,
143
150
keyPath ,
144
151
) ;
145
- const stylingArgs = [ keyPath , nodeType , expanded , expandable ] as const ;
152
+ const stylingArgs = [ keyPath , nodeType , expanded , isNodeExpandable ] as const ;
146
153
147
154
return hideRoot ? (
148
155
< NodeListItem
149
- expandable = { expandable }
156
+ expandable = { isNodeExpandable }
150
157
expanded = { expanded }
151
158
nodeType = { nodeType }
152
159
keyPath = { keyPath }
@@ -156,14 +163,14 @@ export default function JSONNestedNode(props: Props) {
156
163
</ NodeListItem >
157
164
) : (
158
165
< NodeListItem
159
- expandable = { expandable }
166
+ expandable = { isNodeExpandable }
160
167
expanded = { expanded }
161
168
nodeType = { nodeType }
162
169
keyPath = { keyPath }
163
- className = { `${ styles . nestedNode } ${ expanded ? styles . nestedNodeExpanded : "" } ${ expandable ? styles . nestedNodeExpandable : "" } ` }
170
+ className = { `${ styles . nestedNode } ${ expanded ? styles . nestedNodeExpanded : "" } ${ isNodeExpandable ? styles . nestedNodeExpandable : "" } ` }
164
171
>
165
172
< span className = { styles . nestedNodeLabelWrap } >
166
- { expandable && (
173
+ { showExpand && (
167
174
< JSONArrow
168
175
nodeType = { nodeType }
169
176
expanded = { expanded }
@@ -173,7 +180,7 @@ export default function JSONNestedNode(props: Props) {
173
180
< span
174
181
data-nodetype = { nodeType }
175
182
data-keypath = { keyPath [ 0 ] }
176
- className = { `${ styles . nestedNodeLabel } ${ expanded ? styles . nestedNodeLabelExpanded : "" } ${ expandable ? styles . nestedNodeLabelExpandable : "" } ` }
183
+ className = { `${ styles . nestedNodeLabel } ${ expanded ? styles . nestedNodeLabelExpanded : "" } ${ isNodeExpandable ? styles . nestedNodeLabelExpandable : "" } ` }
177
184
onClick = { handleClick }
178
185
>
179
186
{ labelRenderer ( ...stylingArgs ) }
0 commit comments