Commit 88c3b719 by Alex Khomenko Committed by GitHub

Grafana UI: Fix Forms.Select onChangeWithEmpty (#22647)

* Sort props

* Add missing deps to useCallback
parent 0e7c746a
...@@ -65,44 +65,44 @@ const CustomControl = (props: any) => { ...@@ -65,44 +65,44 @@ const CustomControl = (props: any) => {
}; };
export function SelectBase<T>({ export function SelectBase<T>({
value, allowCustomValue = false,
autoFocus = false,
backspaceRemovesValue = true,
components,
defaultOptions,
defaultValue, defaultValue,
inputValue,
onInputChange,
onCreateOption,
options = [],
onChange,
onBlur,
onKeyDown,
onCloseMenu,
onOpenMenu,
placeholder = 'Choose',
getOptionValue,
getOptionLabel,
isSearchable = true,
disabled = false, disabled = false,
formatCreateLabel,
getOptionLabel,
getOptionValue,
inputValue,
invalid,
isClearable = false, isClearable = false,
isMulti = false,
isLoading = false, isLoading = false,
isMulti = false,
isOpen, isOpen,
autoFocus = false, isSearchable = true,
openMenuOnFocus = false, loadOptions,
loadingMessage = 'Loading options...',
maxMenuHeight = 300, maxMenuHeight = 300,
menuPosition,
noOptionsMessage = 'No options found', noOptionsMessage = 'No options found',
tabSelectsValue = true, onBlur,
backspaceRemovesValue = true, onChange,
allowCustomValue = false, onCloseMenu,
size = 'auto', onCreateOption,
onInputChange,
onKeyDown,
onOpenMenu,
openMenuOnFocus = false,
options = [],
placeholder = 'Choose',
prefix, prefix,
formatCreateLabel,
loadOptions,
loadingMessage = 'Loading options...',
defaultOptions,
renderControl, renderControl,
size = 'auto',
tabSelectsValue = true,
value,
width, width,
invalid,
components,
menuPosition,
}: SelectBaseProps<T>) { }: SelectBaseProps<T>) {
const theme = useTheme(); const theme = useTheme();
const styles = getSelectStyles(theme); const styles = getSelectStyles(theme);
...@@ -113,7 +113,7 @@ export function SelectBase<T>({ ...@@ -113,7 +113,7 @@ export function SelectBase<T>({
} }
onChange(value); onChange(value);
}, },
[isMulti] [isMulti, value, onChange]
); );
let ReactSelectComponent: ReactSelect | Creatable = ReactSelect; let ReactSelectComponent: ReactSelect | Creatable = ReactSelect;
const creatableProps: any = {}; const creatableProps: any = {};
...@@ -141,39 +141,39 @@ export function SelectBase<T>({ ...@@ -141,39 +141,39 @@ export function SelectBase<T>({
const commonSelectProps = { const commonSelectProps = {
autoFocus, autoFocus,
placeholder, backspaceRemovesValue,
isSearchable, captureMenuScroll: false,
// Passing isDisabled as react-select accepts this prop defaultValue,
isDisabled: disabled,
// Also passing disabled, as this is the new Select API, and I want to use this prop instead of react-select's one // Also passing disabled, as this is the new Select API, and I want to use this prop instead of react-select's one
disabled, disabled,
getOptionLabel,
getOptionValue,
inputValue,
invalid, invalid,
prefix,
isClearable, isClearable,
// Passing isDisabled as react-select accepts this prop
isDisabled: disabled,
isLoading, isLoading,
isMulti,
isSearchable,
maxMenuHeight,
menuIsOpen: isOpen, menuIsOpen: isOpen,
defaultValue, menuPlacement: 'auto',
inputValue, menuPosition,
menuShouldScrollIntoView: false,
onBlur,
onChange: onChangeWithEmpty,
onInputChange, onInputChange,
value: isMulti ? selectedValue : selectedValue[0], onKeyDown,
getOptionLabel,
getOptionValue,
openMenuOnFocus,
maxMenuHeight,
isMulti,
backspaceRemovesValue,
onMenuOpen: onOpenMenu,
onMenuClose: onCloseMenu, onMenuClose: onCloseMenu,
tabSelectsValue, onMenuOpen: onOpenMenu,
openMenuOnFocus,
options, options,
onChange: onChangeWithEmpty, placeholder,
onBlur, prefix,
onKeyDown,
menuShouldScrollIntoView: false,
renderControl, renderControl,
captureMenuScroll: false, tabSelectsValue,
menuPlacement: 'auto', value: isMulti ? selectedValue : selectedValue[0],
menuPosition,
}; };
// width property is deprecated in favor of size or className // width property is deprecated in favor of size or className
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment