File tree Expand file tree Collapse file tree 4 files changed +64
-6
lines changed Expand file tree Collapse file tree 4 files changed +64
-6
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,23 @@ class Combobox extends React.Component {
79
79
reset
80
80
</ button >
81
81
</ p >
82
+ < Select
83
+ value = { value }
84
+ mode = "combobox"
85
+ onChange = { this . onChange }
86
+ filterOption = { ( inputValue , option ) => {
87
+ if ( ! inputValue ) {
88
+ return true ;
89
+ }
90
+ return ( option . value as string ) . includes ( inputValue ) ;
91
+ } }
92
+ >
93
+ { [ '1' , '2' , '3' ] . map ( ( i ) => (
94
+ < Option value = { i } key = { i } >
95
+ { i }
96
+ </ Option >
97
+ ) ) }
98
+ </ Select >
82
99
< div >
83
100
< Select
84
101
disabled = { disabled }
Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ import OptGroup from './OptGroup';
49
49
import Option from './Option' ;
50
50
import OptionList from './OptionList' ;
51
51
import SelectContext from './SelectContext' ;
52
- import { toArray , hasValue } from './utils/commonUtil' ;
52
+ import { hasValue , toArray } from './utils/commonUtil' ;
53
53
import { fillFieldNames , flattenOptions , injectPropsWithOption } from './utils/valueUtil' ;
54
54
import warningProps , { warningNullOptions } from './utils/warningPropsUtil' ;
55
55
@@ -295,7 +295,7 @@ const Select = React.forwardRef(
295
295
const values = convert2LabelValues ( internalValue ) ;
296
296
297
297
// combobox no need save value when it's no value
298
- if ( mode === 'combobox' && ! hasValue ( values [ 0 ] ?. value ) ) {
298
+ if ( mode === 'combobox' && ! values [ 0 ] ?. value ) {
299
299
return [ ] ;
300
300
}
301
301
@@ -333,10 +333,7 @@ const Select = React.forwardRef(
333
333
React . useEffect ( ( ) => {
334
334
if ( mode === 'combobox' ) {
335
335
const strValue = mergedValues [ 0 ] ?. value ;
336
-
337
- if ( strValue !== undefined && strValue !== null ) {
338
- setSearchValue ( String ( strValue ) ) ;
339
- }
336
+ setSearchValue ( hasValue ( strValue ) ? String ( strValue ) : '' ) ;
340
337
}
341
338
} , [ mergedValues ] ) ;
342
339
Original file line number Diff line number Diff line change @@ -39,6 +39,17 @@ describe('Select.Combobox', () => {
39
39
expect ( wrapper . render ( ) ) . toMatchSnapshot ( ) ;
40
40
} ) ;
41
41
42
+ it ( 'renders controlled correctly' , ( ) => {
43
+ const wrapper = mount (
44
+ < Select value = "" mode = "combobox" placeholder = "Search" >
45
+ < Option value = "1" > 1</ Option >
46
+ < Option value = "2" > 2</ Option >
47
+ </ Select > ,
48
+ ) ;
49
+
50
+ expect ( wrapper . render ( ) ) . toMatchSnapshot ( ) ;
51
+ } ) ;
52
+
42
53
it ( 'set inputValue based on value' , ( ) => {
43
54
const wrapper = mount (
44
55
< Select mode = "combobox" value = "1" >
Original file line number Diff line number Diff line change 1
1
// Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
3
+ exports [` Select.Combobox renders controlled correctly 1` ] = `
4
+ <div
5
+ class = " rc-select rc-select-single rc-select-show-search"
6
+ >
7
+ <div
8
+ class = " rc-select-selector"
9
+ >
10
+ <span
11
+ class = " rc-select-selection-search"
12
+ >
13
+ <input
14
+ aria-activedescendant = " rc_select_TEST_OR_SSR_list_0"
15
+ aria-autocomplete = " list"
16
+ aria-controls = " rc_select_TEST_OR_SSR_list"
17
+ aria-haspopup = " listbox"
18
+ aria-owns = " rc_select_TEST_OR_SSR_list"
19
+ autocomplete = " off"
20
+ class = " rc-select-selection-search-input"
21
+ id = " rc_select_TEST_OR_SSR"
22
+ role = " combobox"
23
+ type = " search"
24
+ value = " "
25
+ />
26
+ </span >
27
+ <span
28
+ class = " rc-select-selection-placeholder"
29
+ >
30
+ Search
31
+ </span >
32
+ </div >
33
+ </div >
34
+ ` ;
35
+
3
36
exports [` Select.Combobox renders correctly 1` ] = `
4
37
<div
5
38
class = " rc-select rc-select-single rc-select-show-search"
You can’t perform that action at this time.
0 commit comments