From 553d3b9dbce2e1d5d6a43cdd83b7a30af61d85c8 Mon Sep 17 00:00:00 2001 From: Alex Khomenko Date: Wed, 12 May 2021 15:09:12 +0300 Subject: [PATCH] Grafana-UI: Add className to TagsInput (#33944) * Grafana-UI: Add className to TagsInput * Do not add existing tags --- .../src/components/TagsInput/TagsInput.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/grafana-ui/src/components/TagsInput/TagsInput.tsx b/packages/grafana-ui/src/components/TagsInput/TagsInput.tsx index 70a2727a79d..095e1e739df 100644 --- a/packages/grafana-ui/src/components/TagsInput/TagsInput.tsx +++ b/packages/grafana-ui/src/components/TagsInput/TagsInput.tsx @@ -11,9 +11,16 @@ export interface Props { tags?: string[]; onChange: (tags: string[]) => void; width?: number; + className?: string; } -export const TagsInput: FC = ({ placeholder = 'New tag (enter key to add)', tags = [], onChange, width }) => { +export const TagsInput: FC = ({ + placeholder = 'New tag (enter key to add)', + tags = [], + onChange, + width, + className, +}) => { const [newTagName, setNewName] = useState(''); const styles = useStyles(getStyles); const theme = useTheme2(); @@ -28,7 +35,9 @@ export const TagsInput: FC = ({ placeholder = 'New tag (enter key to add) const onAdd = (event: React.MouseEvent) => { event.preventDefault(); - onChange(tags.concat(newTagName)); + if (!tags.includes(newTagName)) { + onChange(tags.concat(newTagName)); + } setNewName(''); }; @@ -41,7 +50,7 @@ export const TagsInput: FC = ({ placeholder = 'New tag (enter key to add) }; return ( -
+
{tags?.map((tag: string, index: number) => { return ;