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 2828#### Other
2929
3030* Drop support for React before v16.8
31+ * Fix various issues with the filtering example improperly rendering parents and child nodes (#153 , #196 , #216 )
3132
3233### Added
3334
Original file line number Diff line number Diff line change @@ -57,21 +57,28 @@ class FilterExample extends Component {
5757 }
5858
5959 filterNodes ( filtered , node ) {
60- const { filterText } = this . state ;
61- const children = ( node . children || [ ] ) . reduce ( this . filterNodes , [ ] ) ;
62-
63- if (
60+ if ( this . nodeMatchesSearchString ( node ) ) {
6461 // 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+ }
7071 }
7172
7273 return filtered ;
7374 }
7475
76+ nodeMatchesSearchString ( { label } ) {
77+ const { filterText } = this . state ;
78+
79+ return label . toLocaleLowerCase ( ) . indexOf ( filterText . toLocaleLowerCase ( ) ) > - 1 ;
80+ }
81+
7582 render ( ) {
7683 const {
7784 checked,
You can’t perform that action at this time.
0 commit comments