@@ -200,6 +200,8 @@ const resizeObserverEntryWidth = (entry) => {
200
200
return entry . target . getBoundingClientRect ( ) . width ;
201
201
} ;
202
202
203
+ type ReactKeyWithoutBigInt = string | number ;
204
+
203
205
const useStyles = createUseStyles ( styles , { name : 'FilterBar' } ) ;
204
206
/**
205
207
* The `FilterBar` displays filters in a user-friendly manner to populate values for a query. It consists of a row containing the `VariantManagement` or a title, the related buttons, and an area underneath displaying the filters. The filters are arranged in a logical row that is divided depending on the space available and the width of the filters. The area containing the filters can be hidden or shown using the "Hide FilterBar / Show FilterBar" button, the "Filters" button shows the filter dialog.
@@ -279,12 +281,13 @@ const FilterBar = forwardRef<HTMLDivElement, FilterBarPropTypes>((props, ref) =>
279
281
useEffect ( ( ) => {
280
282
Children . toArray ( children ) . forEach ( ( item ) => {
281
283
if ( isValidElement ( item ) ) {
284
+ const key = item . key as ReactKeyWithoutBigInt ;
282
285
setToggledFilters ( ( prev ) => {
283
- if ( ! item . props . hasOwnProperty ( 'visibleInFilterBar' ) && prev ?. [ item . key ] === undefined ) {
284
- return { ...prev , [ item . key ] : true } ;
286
+ if ( ! item . props . hasOwnProperty ( 'visibleInFilterBar' ) && prev ?. [ key ] === undefined ) {
287
+ return { ...prev , [ key ] : true } ;
285
288
}
286
289
if ( item . props . hasOwnProperty ( 'visibleInFilterBar' ) ) {
287
- return { ...prev , [ item . key ] : item . props . visibleInFilterBar } ;
290
+ return { ...prev , [ key ] : item . props . visibleInFilterBar } ;
288
291
}
289
292
return prev ;
290
293
} ) ;
@@ -365,11 +368,14 @@ const FilterBar = forwardRef<HTMLDivElement, FilterBarPropTypes>((props, ref) =>
365
368
const safeChildren = ( ) => {
366
369
if ( Object . keys ( toggledFilters ) . length > 0 ) {
367
370
return Children . toArray ( children ) . map ( ( child ) => {
368
- if ( isValidElement ( child ) && toggledFilters ?. [ child . key ] !== undefined ) {
369
- // @ts -expect-error: child should always be a FilterGroupItem w/o portal
370
- return cloneElement < FilterGroupItemPropTypes , HTMLDivElement > ( child , {
371
- visibleInFilterBar : toggledFilters [ child . key ]
372
- } ) ;
371
+ if ( isValidElement ( child ) ) {
372
+ const key = child . key as ReactKeyWithoutBigInt ;
373
+ if ( toggledFilters ?. [ key ] !== undefined ) {
374
+ // @ts -expect-error: child should always be a FilterGroupItem w/o portal
375
+ return cloneElement < FilterGroupItemPropTypes , HTMLDivElement > ( child , {
376
+ visibleInFilterBar : toggledFilters [ key ]
377
+ } ) ;
378
+ }
373
379
}
374
380
return child ;
375
381
} ) ;
@@ -389,17 +395,18 @@ const FilterBar = forwardRef<HTMLDivElement, FilterBarPropTypes>((props, ref) =>
389
395
return item ?. props ?. visible && item . props ?. visibleInFilterBar ;
390
396
} )
391
397
. map ( ( child ) => {
398
+ const key = child . key as ReactKeyWithoutBigInt ;
392
399
// necessary because of varying widths of input elements
393
400
if ( filterContainerWidth ) {
394
401
childProps . style = { width : filterContainerWidth , ...child . props . style } ;
395
402
}
396
403
if ( hideFilterConfiguration ) {
397
404
return cloneElement ( child , { ...childProps } ) ;
398
405
}
399
- prevVisibleInFilterBarProps . current [ child . key ] = child . props . visibleInFilterBar ;
406
+ prevVisibleInFilterBarProps . current [ key ] = child . props . visibleInFilterBar ;
400
407
let filterItemProps = { } ;
401
408
if ( Object . keys ( dialogRefs ) . length > 0 ) {
402
- const dialogItemRef = dialogRefs [ child . key ] ;
409
+ const dialogItemRef = dialogRefs [ key ] ;
403
410
if ( dialogItemRef ) {
404
411
filterItemProps = filterValue ( dialogItemRef , child ) ;
405
412
}
@@ -410,22 +417,22 @@ const FilterBar = forwardRef<HTMLDivElement, FilterBarPropTypes>((props, ref) =>
410
417
} ) ;
411
418
}
412
419
if (
413
- prevChildren . current ?. [ child . key ] &&
420
+ prevChildren . current ?. [ key ] &&
414
421
//Input
415
- ( child . props . children ?. props ?. value !== prevChildren . current ?. [ child . key ] ?. value ||
422
+ ( child . props . children ?. props ?. value !== prevChildren . current ?. [ key ] ?. value ||
416
423
//Checkbox
417
- child . props . children ?. props ?. checked !== prevChildren . current ?. [ child . key ] ?. checked ||
424
+ child . props . children ?. props ?. checked !== prevChildren . current ?. [ key ] ?. checked ||
418
425
//Selectable
419
426
( Array . isArray ( child . props . children ?. props ?. children ) &&
420
427
child . props . children ?. props ?. children ?. map ( ( item ) => item . props . selected ) . join ( ',' ) !==
421
- prevChildren ?. current ?. [ child . key ] ?. children ?. map ( ( item ) => item . props . selected ) . join ( ',' ) ) )
428
+ prevChildren ?. current ?. [ key ] ?. children ?. map ( ( item ) => item . props . selected ) . join ( ',' ) ) )
422
429
) {
423
430
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
424
431
// @ts -ignore
425
432
const { [ child . key ] : _omit , ...rest } = dialogRefs ;
426
433
setDialogRefs ( rest ) ;
427
434
}
428
- prevChildren . current [ child . key ] = child . props . children . props ;
435
+ prevChildren . current [ key ] = child . props . children . props ;
429
436
430
437
return cloneElement ( child , {
431
438
...childProps ,
@@ -436,7 +443,7 @@ const FilterBar = forwardRef<HTMLDivElement, FilterBarPropTypes>((props, ref) =>
436
443
...filterItemProps
437
444
} ,
438
445
ref : ( node ) => {
439
- filterRefs . current [ child . key ] = node ;
446
+ filterRefs . current [ key ] = node ;
440
447
if ( ! dialogOpen ) syncRef ( child . props . children . ref , node ) ;
441
448
}
442
449
}
0 commit comments