diff --git a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart-controls/src/components/InfoTooltipWithTrigger.tsx b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart-controls/src/components/InfoTooltipWithTrigger.tsx index 0641b19c6e22a..1ac49381c7ad0 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart-controls/src/components/InfoTooltipWithTrigger.tsx +++ b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart-controls/src/components/InfoTooltipWithTrigger.tsx @@ -52,7 +52,7 @@ export function InfoTooltipWithTrigger({ onClick={onClick} onKeyPress={ onClick && - ((event: React.KeyboardEvent) => { + (event => { if (event.key === 'Enter' || event.key === ' ') { onClick(); } diff --git a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart-controls/src/components/Select.tsx b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart-controls/src/components/Select.tsx index 845d54e981fbc..0176dfe993762 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart-controls/src/components/Select.tsx +++ b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart-controls/src/components/Select.tsx @@ -16,8 +16,8 @@ * specific language governing permissions and limitations * under the License. */ -import React, { useState, ReactNode, ReactElement } from 'react'; -import AntdSelect, { SelectProps as AntdSelectProps, OptionProps } from 'antd/lib/select'; +import React, { useState, ReactNode } from 'react'; +import AntdSelect, { SelectProps as AntdSelectProps } from 'antd/lib/select'; export const { Option } = AntdSelect; @@ -34,12 +34,14 @@ export type SelectProps = Omit, 'options'> & { */ export default function Select({ creatable, - children, onSearch, dropdownMatchSelectWidth = false, minWidth = '100%', showSearch: showSearch_ = true, + onChange, options, + children, + value, ...props }: SelectProps) { const [searchValue, setSearchValue] = useState(); @@ -56,15 +58,26 @@ export default function Select({ } : undefined; - const searchValueNotFound = React.Children.toArray(children).every( - node => node && (node as ReactElement).props.value !== searchValue, - ); + const optionsHasSearchValue = options?.some(([val]) => val === searchValue); + const optionsHasValue = options?.some(([val]) => val === value); + + const handleChange: SelectProps['onChange'] = showSearch + ? (val, opt) => { + // reset input value once selected + setSearchValue(''); + if (onChange) { + onChange(val, opt); + } + } + : onChange; return ( dropdownMatchSelectWidth={dropdownMatchSelectWidth} showSearch={showSearch} onSearch={handleSearch} + onChange={handleChange} + value={value} {...props} css={{ minWidth, @@ -74,7 +87,12 @@ export default function Select({ ))} {children} - {searchValue && searchValueNotFound && ( + {value && !optionsHasValue && ( + + )} + {searchValue && !optionsHasSearchValue && (