diff --git a/src/Select.tsx b/src/Select.tsx index ee91bc50..eccb269a 100644 --- a/src/Select.tsx +++ b/src/Select.tsx @@ -470,6 +470,30 @@ const Select = React.forwardRef { + // When it's a non-controllable component and options change. + if ( + defaultValue === undefined && + value === undefined && + rawLabeledValues.length && + valueOptions.size + ) { + // check whether if match new label. + const findNotMatchLabel = rawLabeledValues.find((item) => { + const findedOption = valueOptions.get(item.value); + return findedOption ? findedOption.label !== item.label : false; + }); + // update values to match the new label. + if (findNotMatchLabel) { + // should not use triggerChange directly to cause `onChange` event + const values = rawLabeledValues.map((item) => valueOptions.get(item.value)); + const labeledValues = convert2LabelValues(values); + setInternalValue(labeledValues); + } + } + }, [valueOptions]); + // ======================= Accessibility ======================== const [activeValue, setActiveValue] = React.useState(null); const [accessibilityIndex, setAccessibilityIndex] = React.useState(0);