From 00cca92cdb090a110aa6e28eb74e0a5acc6848c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E7=8E=B2=E7=8E=B2?= Date: Mon, 26 Feb 2024 19:10:15 +0800 Subject: [PATCH] fix: incorrect display when value change from with label to without label --- src/hooks/useCache.ts | 5 ++--- tests/Select.test.tsx | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/hooks/useCache.ts b/src/hooks/useCache.ts index 732f864b9..653188287 100644 --- a/src/hooks/useCache.ts +++ b/src/hooks/useCache.ts @@ -15,14 +15,13 @@ export default ( }); const filledLabeledValues = React.useMemo(() => { - const { values: prevValueCache, options: prevOptionCache } = cacheRef.current; - + const {options: prevOptionCache } = cacheRef.current; // Fill label by cache const patchedValues = labeledValues.map((item) => { if (item.label === undefined) { return { ...item, - label: prevValueCache.get(item.value)?.label, + label: prevOptionCache.get(item.value)?.label, }; } diff --git a/tests/Select.test.tsx b/tests/Select.test.tsx index 413c80bf3..e9c32b1bc 100644 --- a/tests/Select.test.tsx +++ b/tests/Select.test.tsx @@ -1885,6 +1885,23 @@ describe('Select.Basic', () => { expect(findSelection(wrapper).text()).toEqual('903'); }); + it('value should be used as label When value does not have a label attribute and historical options do not contain value', () => { + const wrapper = mount(