ryoji-s 2 лет назад
Родитель
Сommit
fc52e5319f
1 измененных файлов с 7 добавлено и 36 удалено
  1. 7 36
      apps/app/src/components/PageTags/TagsInput.tsx

+ 7 - 36
apps/app/src/components/PageTags/TagsInput.tsx

@@ -1,19 +1,11 @@
-import React, {
-  FC, useRef, useState, useCallback,
-} from 'react';
+import type { FC } from 'react';
+import React, { useState, useCallback } from 'react';
 
 
 import { useTranslation } from 'next-i18next';
 import { useTranslation } from 'next-i18next';
 import { AsyncTypeahead } from 'react-bootstrap-typeahead';
 import { AsyncTypeahead } from 'react-bootstrap-typeahead';
 
 
 import { useSWRxTagsSearch } from '~/stores/tag';
 import { useSWRxTagsSearch } from '~/stores/tag';
 
 
-type TypeaheadInstance = {
-  _handleMenuItemSelect: (activeItem: string, event: React.KeyboardEvent) => void,
-  state: {
-    initialItem: string,
-  },
-}
-
 type Props = {
 type Props = {
   tags: string[],
   tags: string[],
   autoFocus: boolean,
   autoFocus: boolean,
@@ -24,7 +16,6 @@ export const TagsInput: FC<Props> = (props: Props) => {
   const { t } = useTranslation();
   const { t } = useTranslation();
   const { tags, autoFocus, onTagsUpdated } = props;
   const { tags, autoFocus, onTagsUpdated } = props;
 
 
-  const tagsInputRef = useRef<TypeaheadInstance>(null);
   const [resultTags, setResultTags] = useState<string[]>([]);
   const [resultTags, setResultTags] = useState<string[]>([]);
   const [searchQuery, setSearchQuery] = useState('');
   const [searchQuery, setSearchQuery] = useState('');
 
 
@@ -33,9 +24,7 @@ export const TagsInput: FC<Props> = (props: Props) => {
   const isLoading = error == null && tagsSearch === undefined;
   const isLoading = error == null && tagsSearch === undefined;
 
 
   const changeHandler = useCallback((selected: string[]) => {
   const changeHandler = useCallback((selected: string[]) => {
-    if (onTagsUpdated != null) {
-      onTagsUpdated(selected);
-    }
+    onTagsUpdated(selected);
   }, [onTagsUpdated]);
   }, [onTagsUpdated]);
 
 
   const searchHandler = useCallback(async(query: string) => {
   const searchHandler = useCallback(async(query: string) => {
@@ -43,39 +32,21 @@ export const TagsInput: FC<Props> = (props: Props) => {
     setSearchQuery(query);
     setSearchQuery(query);
     tagsSearchData.unshift(query);
     tagsSearchData.unshift(query);
     setResultTags(Array.from(new Set(tagsSearchData)));
     setResultTags(Array.from(new Set(tagsSearchData)));
-
   }, [tagsSearch?.tags]);
   }, [tagsSearch?.tags]);
 
 
-  const keyDownHandler = useCallback((event: React.KeyboardEvent) => {
-    if (event.key === ' ') {
-      event.preventDefault();
-
-      const initialItem = tagsInputRef?.current?.state?.initialItem;
-      const handleMenuItemSelect = tagsInputRef?.current?._handleMenuItemSelect;
-
-      if (initialItem != null && handleMenuItemSelect != null) {
-        handleMenuItemSelect(initialItem, event);
-      }
-    }
-  }, []);
-
   return (
   return (
     <div className="tag-typeahead">
     <div className="tag-typeahead">
       <AsyncTypeahead
       <AsyncTypeahead
         id="tag-typeahead-asynctypeahead"
         id="tag-typeahead-asynctypeahead"
-        ref={tagsInputRef}
-        caseSensitive={false}
-        defaultSelected={tags}
+        options={resultTags} // Search result (Some tag names)
         isLoading={isLoading}
         isLoading={isLoading}
-        minLength={1}
+        onSearch={searchHandler}
+        defaultSelected={tags}
         multiple
         multiple
-        newSelectionPrefix=""
         onChange={changeHandler}
         onChange={changeHandler}
-        onSearch={searchHandler}
-        onKeyDown={keyDownHandler}
-        options={resultTags} // Search result (Some tag names)
         placeholder={t('tag_edit_modal.tags_input.tag_name')}
         placeholder={t('tag_edit_modal.tags_input.tag_name')}
         autoFocus={autoFocus}
         autoFocus={autoFocus}
+        minLength={1}
       />
       />
     </div>
     </div>
   );
   );