fix: Verify when null value should be undefined in Select (#17013)

* Check for null value

* Safety chek SelectControl and SelectAsyncControl
This commit is contained in:
Geido
2021-10-08 17:32:09 +03:00
committed by GitHub
parent 42efcdf027
commit a57ae35011
2 changed files with 28 additions and 4 deletions

View File

@@ -71,6 +71,17 @@ const SelectAsyncControl = ({
onChange(onChangeVal);
};
const getValue = () => {
const currentValue =
value || (props.default !== undefined ? props.default : undefined);
// safety check - the value is intended to be undefined but null was used
if (currentValue === null && !options.find(o => o.value === null)) {
return undefined;
}
return currentValue;
};
useEffect(() => {
const onError = (response: Response) =>
getClientErrorObject(response).then(e => {
@@ -93,7 +104,7 @@ const SelectAsyncControl = ({
<Select
allowClear={allowClear}
ariaLabel={ariaLabel || t('Select ...')}
value={value || (props.default !== undefined ? props.default : undefined)}
value={getValue()}
header={<ControlHeader {...props} />}
mode={multi ? 'multiple' : 'single'}
onChange={handleOnChange}