diff --git a/ui/src/components/TagSelector/index.tsx b/ui/src/components/TagSelector/index.tsx index b747a470..41b5e11e 100644 --- a/ui/src/components/TagSelector/index.tsx +++ b/ui/src/components/TagSelector/index.tsx @@ -64,7 +64,6 @@ const TagSelector: FC = ({ const [tags, setTags] = useState(null); const [requiredTags, setRequiredTags] = useState(null); const { t } = useTranslation('translation', { keyPrefix: 'tag_selector' }); - const [visibleMenu, setVisibleMenu] = useState(false); const { data: userPermission } = useUserPermission('tag.add'); const toast = useToast(); const tagModal = useTagModal({ @@ -207,10 +206,6 @@ const TagSelector: FC = ({ fetchTags(searchStr); }; - const handleSelect = (eventKey) => { - setCurrentIndex(eventKey); - inputRef.current?.focus(); - }; const handleKeyDown = (e) => { e.stopPropagation(); const { keyCode } = e; @@ -218,7 +213,7 @@ const TagSelector: FC = ({ handleRemove(value[value.length - 1]); } - if (!tags || tags.length === 0) { + if (!tags) { return; } @@ -231,8 +226,7 @@ const TagSelector: FC = ({ if (keyCode === 13 && currentIndex > -1) { e.preventDefault(); - - if (tags.length === 0) { + if (tags.length === 0 && searchValue) { tagModal.onShow(searchValue); return; } @@ -281,19 +275,9 @@ const TagSelector: FC = ({ useEffect(() => { if (focusState) { fetchTags(searchValue); - } - if (visibleMenu) { inputRef.current?.focus(); } - }, [visibleMenu]); - - useEffect(() => { - if (autoFocus) { - setShowMenu(true); - setFocusState(true); - inputRef.current?.focus(); - } - }, [autoFocus]); + }, [focusState]); useEffect(() => { queryTags('').then((res) => { @@ -310,7 +294,6 @@ const TagSelector: FC = ({ !containerRef.current?.contains(event.target) ) { handleTagSelectorBlur(); - console.log('outside click'); } }; document.addEventListener('click', handleOutsideClick); @@ -325,22 +308,22 @@ const TagSelector: FC = ({ (tags && tags?.length > 0) || (searchValue && tags?.length === 0) || (searchValue && !hiddenCreateBtn); - if ((value.length < 5 || alwaysShowAddBtn) && menuHasContent) { - handleMenuShow(true); - } else { - handleMenuShow(false); - } + if (focusState) { + if ((value.length < 5 || alwaysShowAddBtn) && menuHasContent) { + handleMenuShow(true); + } else { + handleMenuShow(false); + } - if ((tags && tags?.length < 5) || alwaysShowAddBtn) { - inputRef.current?.focus(); + if ((tags && tags?.length < 5) || alwaysShowAddBtn) { + inputRef.current?.focus(); + } } - }, [tags, hiddenCreateBtn, searchValue, alwaysShowAddBtn]); + }, [focusState, tags, hiddenCreateBtn, searchValue, alwaysShowAddBtn]); return (
- = ({ )} onFocus={handleTagSelectorFocus} onKeyDown={handleKeyDown}> - +
@@ -393,7 +376,7 @@ const TagSelector: FC = ({ )} {searchValue}
- +
{!searchValue && showRequiredTagText && @@ -407,7 +390,6 @@ const TagSelector: FC = ({ handleClick(item)}> {item.display_name} @@ -428,7 +410,7 @@ const TagSelector: FC = ({ )} -
+
{!hiddenDescription && {t('hint')}} );