File tree 2 files changed +53
-1
lines changed
packages/material-ui-lab/src
2 files changed +53
-1
lines changed Original file line number Diff line number Diff line change @@ -658,4 +658,38 @@ describe('<Autocomplete />', () => {
658
658
expect ( textbox . value ) . to . equal ( '' ) ;
659
659
} ) ;
660
660
} ) ;
661
+
662
+ describe ( 'prop: filterOptions' , ( ) => {
663
+ it ( 'should ignore object keys by default' , ( ) => {
664
+ const { queryAllByRole, getByRole } = render (
665
+ < Autocomplete
666
+ options = { [
667
+ {
668
+ value : 'one' ,
669
+ label : 'One' ,
670
+ } ,
671
+ {
672
+ value : 'two' ,
673
+ label : 'Two' ,
674
+ } ,
675
+ ] }
676
+ getOptionLabel = { option => option . name }
677
+ renderInput = { params => < TextField autoFocus { ...params } /> }
678
+ /> ,
679
+ ) ;
680
+ let options ;
681
+ const textbox = getByRole ( 'textbox' ) ;
682
+
683
+ options = queryAllByRole ( 'option' ) ;
684
+ expect ( options . length ) . to . equal ( 2 ) ;
685
+
686
+ fireEvent . change ( textbox , { target : { value : 'value' } } ) ;
687
+ options = queryAllByRole ( 'option' ) ;
688
+ expect ( options . length ) . to . equal ( 0 ) ;
689
+
690
+ fireEvent . change ( textbox , { target : { value : 'one' } } ) ;
691
+ options = queryAllByRole ( 'option' ) ;
692
+ expect ( options . length ) . to . equal ( 1 ) ;
693
+ } ) ;
694
+ } ) ;
661
695
} ) ;
Original file line number Diff line number Diff line change @@ -11,12 +11,30 @@ function stripDiacritics(string) {
11
11
: string ;
12
12
}
13
13
14
+ function defaultStringify ( value ) {
15
+ if ( value == null ) {
16
+ return '' ;
17
+ }
18
+
19
+ if ( typeof value === 'string' ) {
20
+ return value ;
21
+ }
22
+
23
+ if ( typeof value === 'object' ) {
24
+ return Object . keys ( value )
25
+ . map ( key => value [ key ] )
26
+ . join ( ' ' ) ;
27
+ }
28
+
29
+ return JSON . stringify ( value ) ;
30
+ }
31
+
14
32
export function createFilterOptions ( config = { } ) {
15
33
const {
16
34
ignoreAccents = true ,
17
35
ignoreCase = true ,
18
36
matchFrom = 'any' ,
19
- stringify = JSON . stringify ,
37
+ stringify = defaultStringify ,
20
38
trim = false ,
21
39
} = config ;
22
40
You can’t perform that action at this time.
0 commit comments