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

@@ -205,6 +205,21 @@ export default class SelectControl extends React.PureComponent {
danger,
};
const getValue = () => {
const currentValue =
value ||
(this.props.default !== undefined ? this.props.default : undefined);
// safety check - the value is intended to be undefined but null was used
if (
currentValue === null &&
!this.state.options.find(o => o.value === null)
) {
return undefined;
}
return currentValue;
};
const selectProps = {
allowNewOptions: freeForm,
autoFocus,
@@ -225,9 +240,7 @@ export default class SelectControl extends React.PureComponent {
optionRenderer,
options: this.state.options,
placeholder,
value:
value ||
(this.props.default !== undefined ? this.props.default : undefined),
value: getValue(),
};
return (