Skip to content

Commit

Permalink
Fixes tag count placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina committed Jul 21, 2023
1 parent a88148d commit 6b06ea0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
2 changes: 0 additions & 2 deletions superset-frontend/src/components/Select/AsyncSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ const AsyncSelect = forwardRef(
return previousState;
});
}
setInputValue('');
fireOnChange();
onSelect?.(selectedItem, option);
};
Expand All @@ -255,7 +254,6 @@ const AsyncSelect = forwardRef(
setSelectValue(array.filter(element => element !== value));
}
}
setInputValue('');
fireOnChange();
onDeselect?.(value, option);
};
Expand Down
2 changes: 2 additions & 0 deletions superset-frontend/src/components/Select/Select.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ InteractiveSelect.args = {
autoFocus: true,
allowNewOptions: false,
allowClear: false,
autoClearSearchValue: false,
allowSelectAll: true,
showSearch: true,
disabled: false,
invertSelection: false,
Expand Down
26 changes: 18 additions & 8 deletions superset-frontend/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ const Select = forwardRef(
return previousState;
});
}
setInputValue('');
fireOnChange();
onSelect?.(selectedItem, option);
};
Expand Down Expand Up @@ -307,7 +306,6 @@ const Select = forwardRef(
setSelectValue(array);
}
}
setInputValue('');
fireOnChange();
onDeselect?.(value, option);
};
Expand Down Expand Up @@ -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 (
<StyledContainer headerPosition={headerPosition}>
Expand All @@ -545,7 +555,7 @@ const Select = forwardRef(
}
headerPosition={headerPosition}
labelInValue={labelInValue}
maxTagCount={maxTagCount}
maxTagCount={actualMaxTagCount}
maxTagPlaceholder={customMaxTagPlaceholder}
mode={mappedMode}
notFoundContent={isLoading ? t('Loading...') : notFoundContent}
Expand Down

0 comments on commit 6b06ea0

Please sign in to comment.