mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-17 13:03:50 +00:00
Ensured TagsSelector does not allow duplicated tags, and allows adding multiple coma-separated tags at once
This commit is contained in:
@@ -44,13 +44,18 @@ const TagsSelector = (colorGenerator: ColorGenerator) => (
|
|||||||
addOnBlur
|
addOnBlur
|
||||||
placeholderText={placeholder}
|
placeholderText={placeholder}
|
||||||
minQueryLength={1}
|
minQueryLength={1}
|
||||||
|
delimiters={[ 'Enter', 'Tab', ',' ]}
|
||||||
onDelete={(removedTagIndex) => {
|
onDelete={(removedTagIndex) => {
|
||||||
const tagsCopy = [ ...selectedTags ];
|
const tagsCopy = [ ...selectedTags ];
|
||||||
|
|
||||||
tagsCopy.splice(removedTagIndex, 1);
|
tagsCopy.splice(removedTagIndex, 1);
|
||||||
onChange(tagsCopy);
|
onChange(tagsCopy);
|
||||||
}}
|
}}
|
||||||
onAddition={({ name: newTag }) => onChange([ ...selectedTags, newTag.toLowerCase() ])}
|
onAddition={({ name: newTag }) => onChange(
|
||||||
|
// * Avoid duplicated tags (thanks to the Set),
|
||||||
|
// * Split any of the new tags by comma, allowing to paste multiple comma-separated tags at once.
|
||||||
|
[ ...new Set([ ...selectedTags, ...newTag.toLowerCase().split(',') ]) ],
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user