mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Fix: making select to return empty list when no values are selected in multivalue mode.
* Fixed error in storybook when remving selections. * moved fix to select base instead of in story. * updated to check for null or undefined.
This commit is contained in:
parent
12f1af2956
commit
204682e9b8
@ -1,4 +1,4 @@
|
|||||||
import React from 'react';
|
import React, { useCallback } from 'react';
|
||||||
import { SelectableValue, deprecationWarning } from '@grafana/data';
|
import { SelectableValue, deprecationWarning } from '@grafana/data';
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import { default as ReactSelect } from '@torkelo/react-select';
|
import { default as ReactSelect } from '@torkelo/react-select';
|
||||||
@ -178,6 +178,15 @@ export function SelectBase<T>({
|
|||||||
}: SelectBaseProps<T>) {
|
}: SelectBaseProps<T>) {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const styles = getSelectStyles(theme);
|
const styles = getSelectStyles(theme);
|
||||||
|
const onChangeWithEmpty = useCallback(
|
||||||
|
(value: SelectValue<T>) => {
|
||||||
|
if (isMulti && (value === undefined || value === null)) {
|
||||||
|
return onChange([]);
|
||||||
|
}
|
||||||
|
onChange(value);
|
||||||
|
},
|
||||||
|
[isMulti]
|
||||||
|
);
|
||||||
let ReactSelectComponent: ReactSelect | Creatable = ReactSelect;
|
let ReactSelectComponent: ReactSelect | Creatable = ReactSelect;
|
||||||
const creatableProps: any = {};
|
const creatableProps: any = {};
|
||||||
let asyncSelectProps: any = {};
|
let asyncSelectProps: any = {};
|
||||||
@ -229,7 +238,7 @@ export function SelectBase<T>({
|
|||||||
onMenuClose: onCloseMenu,
|
onMenuClose: onCloseMenu,
|
||||||
tabSelectsValue,
|
tabSelectsValue,
|
||||||
options,
|
options,
|
||||||
onChange,
|
onChange: onChangeWithEmpty,
|
||||||
onBlur,
|
onBlur,
|
||||||
onKeyDown,
|
onKeyDown,
|
||||||
menuShouldScrollIntoView: false,
|
menuShouldScrollIntoView: false,
|
||||||
|
Loading…
Reference in New Issue
Block a user