Skip to content

Commit

Permalink
feat(native-filters): add option to create value in select filter
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro committed Apr 23, 2021
1 parent b963624 commit 8bb466c
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ export default function PluginFilterSelect(props: PluginFilterSelectProps) {
? firstItem
: initSelectValue,
);
const [currentSuggestionSearch, setCurrentSuggestionSearch] = useState('');

const clearSuggestionSearch = () => {
setCurrentSuggestionSearch('');
};

const [col] = groupby;
const datatype: GenericDataType = coltypeMap[col];
Expand Down Expand Up @@ -150,6 +155,9 @@ export default function PluginFilterSelect(props: PluginFilterSelectProps) {
showSearch={showSearch}
mode={multiSelect ? 'multiple' : undefined}
placeholder={placeholderText}
onSearch={val => setCurrentSuggestionSearch(val)}
onSelect={clearSuggestionSearch}
onBlur={clearSuggestionSearch}
// @ts-ignore
onChange={handleChange}
ref={inputRef}
Expand All @@ -163,6 +171,14 @@ export default function PluginFilterSelect(props: PluginFilterSelectProps) {
</Option>
);
})}
{currentSuggestionSearch &&
!(values || []).some(
suggestion => suggestion === currentSuggestionSearch,
) && (
<Option value={currentSuggestionSearch}>
{currentSuggestionSearch}
</Option>
)}
</StyledSelect>
</Styles>
);
Expand Down

0 comments on commit 8bb466c

Please sign in to comment.