Просмотр исходного кода

每次查新词,都先滚动到开始

visuddhinanda 2 лет назад
Родитель
Сommit
a5e04e24ea
1 измененных файлов с 3 добавлено и 0 удалено
  1. 3 0
      dashboard/src/components/dict/Dictionary.tsx

+ 3 - 0
dashboard/src/components/dict/Dictionary.tsx

@@ -20,6 +20,7 @@ const DictionaryWidget = ({ word, compact = false, onSearch }: IWidget) => {
   useEffect(() => {
     if (word !== wordSearch) {
       setWordSearch(word?.toLowerCase());
+      document.getElementById("pcd_dict_top")?.scrollIntoView();
     }
   }, [word]);
 
@@ -27,12 +28,14 @@ const DictionaryWidget = ({ word, compact = false, onSearch }: IWidget) => {
     console.log("onSearch", value);
     const word = value.toLowerCase();
     setWordSearch(word);
+    document.getElementById("pcd_dict_top")?.scrollIntoView();
     if (typeof onSearch !== "undefined") {
       onSearch(value, isFactor);
     }
   };
   return (
     <div ref={setContainer}>
+      <div id="pcd_dict_top"></div>
       <Affix offsetTop={0} target={compact ? () => container : undefined}>
         <div
           style={{