File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed
packages/react-core/src/components/TreeView Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -186,9 +186,7 @@ const TreeViewListItemBase: React.FunctionComponent<TreeViewListItemProps> = ({
186
186
< >
187
187
{ hasBadge && children && (
188
188
< span className = { css ( styles . treeViewNodeCount ) } >
189
- < Badge { ...badgeProps } >
190
- { customBadgeContent ? customBadgeContent : ( children as React . ReactElement < any > ) . props . data . length }
191
- </ Badge >
189
+ < Badge { ...badgeProps } > { customBadgeContent ?? ( children as React . ReactElement < any > ) . props . data . length } </ Badge >
192
190
</ span >
193
191
) }
194
192
{ hasBadge && ! children && customBadgeContent !== undefined && (
Original file line number Diff line number Diff line change @@ -264,6 +264,16 @@ test('Renders badge with customBadgeContent when hasBadge and children are passe
264
264
expect ( screen . getByText ( requiredProps . name ) . nextElementSibling ) . toHaveTextContent ( 'Custom badge' ) ;
265
265
} ) ;
266
266
267
+ test ( 'Renders badge with customBadgeContent being number 0 when hasBadge and children are passed' , ( ) => {
268
+ render (
269
+ < TreeViewListItem hasBadge customBadgeContent = { 0 } { ...requiredProps } >
270
+ < TreeView data = { [ { name : 'Parent name 1' } , { name : 'Parent name 2' } ] } />
271
+ </ TreeViewListItem >
272
+ ) ;
273
+
274
+ expect ( screen . getByText ( requiredProps . name ) . nextElementSibling ) . toHaveTextContent ( '0' ) ;
275
+ } ) ;
276
+
267
277
test ( 'Renders badge with customBadgeContent when hasBadge is passed and children are not passed' , ( ) => {
268
278
render ( < TreeViewListItem hasBadge customBadgeContent = "Custom badge" { ...requiredProps } /> ) ;
269
279
You can’t perform that action at this time.
0 commit comments