File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -15,14 +15,13 @@ export default (
1515 } ) ;
1616
1717 const filledLabeledValues = React . useMemo ( ( ) => {
18- const { values : prevValueCache , options : prevOptionCache } = cacheRef . current ;
19-
18+ const { options : prevOptionCache } = cacheRef . current ;
2019 // Fill label by cache
2120 const patchedValues = labeledValues . map ( ( item ) => {
2221 if ( item . label === undefined ) {
2322 return {
2423 ...item ,
25- label : prevValueCache . get ( item . value ) ?. label ,
24+ label : prevOptionCache . get ( item . value ) ?. label ,
2625 } ;
2726 }
2827
Original file line number Diff line number Diff line change @@ -1885,6 +1885,23 @@ describe('Select.Basic', () => {
18851885 expect ( findSelection ( wrapper ) . text ( ) ) . toEqual ( '903' ) ;
18861886 } ) ;
18871887
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+
18881905 // https://github.com/ant-design/ant-design/issues/24747
18891906 // This can not test function called with jest spy, coverage only
18901907 it ( 'mouse enter to refresh' , ( ) => {
You can’t perform that action at this time.
0 commit comments