mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
Enable adding tags on blur (#34374)
This commit is contained in:
parent
e291203528
commit
958ebce1e1
@ -13,6 +13,7 @@ export interface Props {
|
||||
width?: number;
|
||||
className?: string;
|
||||
disabled?: boolean;
|
||||
addOnBlur?: boolean;
|
||||
}
|
||||
|
||||
export const TagsInput: FC<Props> = ({
|
||||
@ -22,6 +23,7 @@ export const TagsInput: FC<Props> = ({
|
||||
width,
|
||||
className,
|
||||
disabled,
|
||||
addOnBlur,
|
||||
}) => {
|
||||
const [newTagName, setNewName] = useState('');
|
||||
const styles = useStyles(getStyles);
|
||||
@ -38,14 +40,20 @@ export const TagsInput: FC<Props> = ({
|
||||
onChange(tags?.filter((x) => x !== tagToRemove));
|
||||
};
|
||||
|
||||
const onAdd = (event: React.MouseEvent) => {
|
||||
event.preventDefault();
|
||||
const onAdd = (event?: React.MouseEvent) => {
|
||||
event?.preventDefault();
|
||||
if (!tags.includes(newTagName)) {
|
||||
onChange(tags.concat(newTagName));
|
||||
}
|
||||
setNewName('');
|
||||
};
|
||||
|
||||
const onBlur = () => {
|
||||
if (addOnBlur && newTagName) {
|
||||
onAdd();
|
||||
}
|
||||
};
|
||||
|
||||
const onKeyboardAdd = (event: KeyboardEvent) => {
|
||||
event.preventDefault();
|
||||
if (event.key === 'Enter' && newTagName !== '') {
|
||||
@ -68,6 +76,7 @@ export const TagsInput: FC<Props> = ({
|
||||
onChange={onNameChange}
|
||||
value={newTagName}
|
||||
onKeyUp={onKeyboardAdd}
|
||||
onBlur={onBlur}
|
||||
suffix={
|
||||
newTagName.length > 0 && (
|
||||
<Button fill="text" className={styles.addButtonStyle} onClick={onAdd} size="md">
|
||||
|
Loading…
Reference in New Issue
Block a user