diff --git a/superset-frontend/src/components/Select/AsyncSelect.tsx b/superset-frontend/src/components/Select/AsyncSelect.tsx index b1fd990058be4..3453ce2b5f06a 100644 --- a/superset-frontend/src/components/Select/AsyncSelect.tsx +++ b/superset-frontend/src/components/Select/AsyncSelect.tsx @@ -238,7 +238,6 @@ const AsyncSelect = forwardRef( return previousState; }); } - setInputValue(''); fireOnChange(); onSelect?.(selectedItem, option); }; @@ -255,7 +254,6 @@ const AsyncSelect = forwardRef( setSelectValue(array.filter(element => element !== value)); } } - setInputValue(''); fireOnChange(); onDeselect?.(value, option); }; diff --git a/superset-frontend/src/components/Select/Select.stories.tsx b/superset-frontend/src/components/Select/Select.stories.tsx index cb7224fdca3b4..58fa424700761 100644 --- a/superset-frontend/src/components/Select/Select.stories.tsx +++ b/superset-frontend/src/components/Select/Select.stories.tsx @@ -208,6 +208,8 @@ InteractiveSelect.args = { autoFocus: true, allowNewOptions: false, allowClear: false, + autoClearSearchValue: false, + allowSelectAll: true, showSearch: true, disabled: false, invertSelection: false, diff --git a/superset-frontend/src/components/Select/Select.tsx b/superset-frontend/src/components/Select/Select.tsx index 6e08bd59edcd2..d9b022224c0d3 100644 --- a/superset-frontend/src/components/Select/Select.tsx +++ b/superset-frontend/src/components/Select/Select.tsx @@ -262,7 +262,6 @@ const Select = forwardRef( return previousState; }); } - setInputValue(''); fireOnChange(); onSelect?.(selectedItem, option); }; @@ -307,7 +306,6 @@ const Select = forwardRef( setSelectValue(array); } } - setInputValue(''); fireOnChange(); onDeselect?.(value, option); }; @@ -520,13 +518,25 @@ const Select = forwardRef( [selectAllEnabled, options], ); - const customMaxTagPlaceholder = () => { + const omittedCount = useMemo(() => { const num_selected = ensureIsArray(selectValue).length; const num_shown = maxTagCount as number; - return selectAllMode - ? `+ ${num_selected - num_shown - 1} ...` - : `+ ${num_selected - num_shown} ...`; - }; + return num_selected - num_shown - (selectAllMode ? 1 : 0); + }, [maxTagCount, selectAllMode, selectValue]); + + const customMaxTagPlaceholder = () => + `+ ${omittedCount > 0 ? omittedCount : 1} ...`; + + // We can't remove the + tag so when Select All + // is the only item omitted, we subtract one from maxTagCount + let actualMaxTagCount = maxTagCount; + if ( + actualMaxTagCount !== 'responsive' && + omittedCount === 0 && + selectAllMode + ) { + actualMaxTagCount -= 1; + } return ( @@ -545,7 +555,7 @@ const Select = forwardRef( } headerPosition={headerPosition} labelInValue={labelInValue} - maxTagCount={maxTagCount} + maxTagCount={actualMaxTagCount} maxTagPlaceholder={customMaxTagPlaceholder} mode={mappedMode} notFoundContent={isLoading ? t('Loading...') : notFoundContent}