File tree 2 files changed +19
-3
lines changed
2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -15,14 +15,13 @@ export default (
15
15
} ) ;
16
16
17
17
const filledLabeledValues = React . useMemo ( ( ) => {
18
- const { values : prevValueCache , options : prevOptionCache } = cacheRef . current ;
19
-
18
+ const { options : prevOptionCache } = cacheRef . current ;
20
19
// Fill label by cache
21
20
const patchedValues = labeledValues . map ( ( item ) => {
22
21
if ( item . label === undefined ) {
23
22
return {
24
23
...item ,
25
- label : prevValueCache . get ( item . value ) ?. label ,
24
+ label : prevOptionCache . get ( item . value ) ?. label ,
26
25
} ;
27
26
}
28
27
Original file line number Diff line number Diff line change @@ -1885,6 +1885,23 @@ describe('Select.Basic', () => {
1885
1885
expect ( findSelection ( wrapper ) . text ( ) ) . toEqual ( '903' ) ;
1886
1886
} ) ;
1887
1887
1888
+ it ( 'value should be used as label When value does not have a label attribute and historical options do not contain value' , ( ) => {
1889
+ const wrapper = mount ( < Select value = { { value : 903 , label : 'light' } } options = { [ ] } /> ) ;
1890
+ expect ( findSelection ( wrapper ) . text ( ) ) . toEqual ( 'light' ) ;
1891
+
1892
+ wrapper . setProps ( { value : 903 } ) ;
1893
+ expect ( findSelection ( wrapper ) . text ( ) ) . toEqual ( '903' ) ;
1894
+
1895
+ wrapper . setProps ( { options : [ { value : 903 , label : 'Bamboo' } ] } ) ;
1896
+ expect ( findSelection ( wrapper ) . text ( ) ) . toEqual ( 'Bamboo' ) ;
1897
+
1898
+ wrapper . setProps ( { value :{ value : 903 , label : 'light' } , options :[ ] } ) ;
1899
+ expect ( findSelection ( wrapper ) . text ( ) ) . toEqual ( 'light' ) ;
1900
+
1901
+ wrapper . setProps ( { value : 903 , options :[ ] } ) ;
1902
+ expect ( findSelection ( wrapper ) . text ( ) ) . toEqual ( 'Bamboo' ) ;
1903
+ } ) ;
1904
+
1888
1905
// https://github.com/ant-design/ant-design/issues/24747
1889
1906
// This can not test function called with jest spy, coverage only
1890
1907
it ( 'mouse enter to refresh' , ( ) => {
You can’t perform that action at this time.
0 commit comments