From b8a7dccf92fce936e2e860daa1b5bfb2d76c7f13 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 15 Aug 2021 09:45:14 +0200 Subject: [PATCH] Ensured TagsSelector does not allow duplicated tags, and allows adding multiple coma-separated tags at once --- src/tags/helpers/TagsSelector.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/tags/helpers/TagsSelector.tsx b/src/tags/helpers/TagsSelector.tsx index 21cd1cb8..c7041576 100644 --- a/src/tags/helpers/TagsSelector.tsx +++ b/src/tags/helpers/TagsSelector.tsx @@ -44,13 +44,18 @@ const TagsSelector = (colorGenerator: ColorGenerator) => ( addOnBlur placeholderText={placeholder} minQueryLength={1} + delimiters={[ 'Enter', 'Tab', ',' ]} onDelete={(removedTagIndex) => { const tagsCopy = [ ...selectedTags ]; tagsCopy.splice(removedTagIndex, 1); 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(',') ]) ], + )} /> ); };