File tree 2 files changed +36
-2
lines changed
2 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,13 @@ export default class Tags extends Component {
26
26
{ text : 'documents' , id : 3 } ,
27
27
{ text : 'discussion' , id : 4 } ,
28
28
] ,
29
+ value11 : 1 ,
30
+ data11 : [
31
+ { text : 'bug' , id : 1 } ,
32
+ { text : 'feature' , id : 2 } ,
33
+ { text : 'documents' , id : 3 } ,
34
+ { text : 'discussion' , id : 4 } ,
35
+ ] ,
29
36
placeholder9 : 'search by tags' ,
30
37
} ;
31
38
}
@@ -287,6 +294,28 @@ export default class Tags extends Component {
287
294
) ;
288
295
}
289
296
297
+ example11 ( ) {
298
+ const { value11, data11 } = this . state ;
299
+ return (
300
+ < div >
301
+ Add a new item and set a new `onChange` event< br />
302
+ < Select2
303
+ multiple = { false }
304
+ data = { data11 }
305
+ defaultValue = { 1 }
306
+ value = { value11 }
307
+ onChange = { ( e ) => { this . setState ( { value11 : e . target . value } ) ; } }
308
+ options = { {
309
+ placeholder : 'search by tags' ,
310
+ allowClear : true ,
311
+ } }
312
+ />
313
+ —
314
+ Click "x" to clear
315
+ </ div >
316
+ ) ;
317
+ }
318
+
290
319
render ( ) {
291
320
return (
292
321
< div >
@@ -299,7 +328,7 @@ export default class Tags extends Component {
299
328
{ this . example7 ( ) } < br />
300
329
{ this . example8 ( ) } < br />
301
330
{ this . example9 ( ) } < br />
302
- { this . example10 ( ) } < br />
331
+ { this . example11 ( ) } < br />
303
332
</ div >
304
333
) ;
305
334
}
Original file line number Diff line number Diff line change @@ -105,7 +105,7 @@ export default class Select2 extends Component {
105
105
const newValue = this . prepareValue ( value , defaultValue ) ;
106
106
const currentValue = multiple ? this . el . val ( ) || [ ] : this . el . val ( ) ;
107
107
108
- if ( ! shallowEqualFuzzy ( currentValue , newValue ) || this . forceUpdateValue ) {
108
+ if ( ! this . fuzzyValuesEqual ( currentValue , newValue ) || this . forceUpdateValue ) {
109
109
const onChange = this . props . onChange ;
110
110
111
111
if ( this . initialRender && onChange ) {
@@ -121,6 +121,11 @@ export default class Select2 extends Component {
121
121
}
122
122
}
123
123
124
+ fuzzyValuesEqual ( currentValue , newValue ) {
125
+ return ( currentValue === null && newValue === '' ) ||
126
+ shallowEqualFuzzy ( currentValue , newValue ) ;
127
+ }
128
+
124
129
destroySelect2 ( withCallbacks = true ) {
125
130
if ( withCallbacks ) {
126
131
this . detachEventHandlers ( ) ;
You can’t perform that action at this time.
0 commit comments