Преглед изворни кода

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

visuddhinanda пре 2 година
родитељ
комит
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(() => {
   useEffect(() => {
     if (word !== wordSearch) {
     if (word !== wordSearch) {
       setWordSearch(word?.toLowerCase());
       setWordSearch(word?.toLowerCase());
+      document.getElementById("pcd_dict_top")?.scrollIntoView();
     }
     }
   }, [word]);
   }, [word]);
 
 
@@ -27,12 +28,14 @@ const DictionaryWidget = ({ word, compact = false, onSearch }: IWidget) => {
     console.log("onSearch", value);
     console.log("onSearch", value);
     const word = value.toLowerCase();
     const word = value.toLowerCase();
     setWordSearch(word);
     setWordSearch(word);
+    document.getElementById("pcd_dict_top")?.scrollIntoView();
     if (typeof onSearch !== "undefined") {
     if (typeof onSearch !== "undefined") {
       onSearch(value, isFactor);
       onSearch(value, isFactor);
     }
     }
   };
   };
   return (
   return (
     <div ref={setContainer}>
     <div ref={setContainer}>
+      <div id="pcd_dict_top"></div>
       <Affix offsetTop={0} target={compact ? () => container : undefined}>
       <Affix offsetTop={0} target={compact ? () => container : undefined}>
         <div
         <div
           style={{
           style={{