@@ -5,11 +5,12 @@ import nodeVisitor from './nodeVisitor'
55import keyboardNavigation , { FocusActionNames } from './keyboardNavigation'
66
77class TreeManager {
8- constructor ( { data, mode, showPartiallySelected, rootPrefixId } ) {
8+ constructor ( { data, mode, showPartiallySelected, rootPrefixId, searchPredicate } ) {
99 this . _src = data
1010 this . simpleSelect = mode === 'simpleSelect'
1111 this . radioSelect = mode === 'radioSelect'
1212 this . hierarchical = mode === 'hierarchical'
13+ this . searchPredicate = searchPredicate
1314 const { list, defaultValues, singleSelectedNode } = flattenTree ( {
1415 tree : JSON . parse ( JSON . stringify ( data ) ) ,
1516 simple : this . simpleSelect ,
@@ -49,11 +50,7 @@ class TreeManager {
4950
5051 const matches = [ ]
5152
52- const addOnMatch = node => {
53- if ( node . label . toLowerCase ( ) . indexOf ( searchTerm ) >= 0 ) {
54- matches . push ( node . _id )
55- }
56- }
53+ const addOnMatch = this . _getAddOnMatch ( matches , searchTerm )
5754
5855 if ( closestMatch !== searchTerm ) {
5956 const superMatches = this . searchMaps . get ( closestMatch )
@@ -278,6 +275,19 @@ class TreeManager {
278275
279276 return keyboardNavigation . handleToggleNavigationkey ( action , prevFocus , readOnly , onToggleChecked , onToggleExpanded )
280277 }
278+
279+ _getAddOnMatch ( matches , searchTerm ) {
280+ let isMatch = ( node , term ) => node . label . toLowerCase ( ) . indexOf ( term ) >= 0
281+ if ( typeof this . searchPredicate === 'function' ) {
282+ isMatch = this . searchPredicate
283+ }
284+
285+ return node => {
286+ if ( isMatch ( node , searchTerm ) ) {
287+ matches . push ( node . _id )
288+ }
289+ }
290+ }
281291}
282292
283293export default TreeManager
0 commit comments