File tree Expand file tree Collapse file tree 2 files changed +17
-9
lines changed Expand file tree Collapse file tree 2 files changed +17
-9
lines changed Original file line number Diff line number Diff line change 28
28
#### Other
29
29
30
30
* Drop support for React before v16.8
31
+ * Fix various issues with the filtering example improperly rendering parents and child nodes (#153 , #196 , #216 )
31
32
32
33
### Added
33
34
Original file line number Diff line number Diff line change @@ -57,21 +57,28 @@ class FilterExample extends Component {
57
57
}
58
58
59
59
filterNodes ( filtered , node ) {
60
- const { filterText } = this . state ;
61
- const children = ( node . children || [ ] ) . reduce ( this . filterNodes , [ ] ) ;
62
-
63
- if (
60
+ if ( this . nodeMatchesSearchString ( node ) ) {
64
61
// Node's label matches the search string
65
- node . label . toLocaleLowerCase ( ) . indexOf ( filterText . toLocaleLowerCase ( ) ) > - 1 ||
66
- // Or a children has a matching node
67
- children . length
68
- ) {
69
- filtered . push ( { ...node , children } ) ;
62
+ filtered . push ( node ) ;
63
+ } else {
64
+ // Find if any children match the search string or have descendants who do
65
+ const filteredChildren = ( node . children || [ ] ) . reduce ( this . filterNodes , [ ] ) ;
66
+
67
+ // If so, render these children
68
+ if ( filteredChildren . length > 0 ) {
69
+ filtered . push ( { ...node , children : filteredChildren } ) ;
70
+ }
70
71
}
71
72
72
73
return filtered ;
73
74
}
74
75
76
+ nodeMatchesSearchString ( { label } ) {
77
+ const { filterText } = this . state ;
78
+
79
+ return label . toLocaleLowerCase ( ) . indexOf ( filterText . toLocaleLowerCase ( ) ) > - 1 ;
80
+ }
81
+
75
82
render ( ) {
76
83
const {
77
84
checked,
You can’t perform that action at this time.
0 commit comments