itizawa 5 лет назад
Родитель
Сommit
6eda9ef4bd
1 измененных файлов с 13 добавлено и 9 удалено
  1. 13 9
      src/client/js/components/TableOfContents.jsx

+ 13 - 9
src/client/js/components/TableOfContents.jsx

@@ -1,4 +1,4 @@
-import React, { useCallback, useEffect } from 'react';
+import React, { useCallback, useEffect, useMemo } from 'react';
 import PropTypes from 'prop-types';
 import loggerFactory from '@alias/logger';
 
@@ -15,6 +15,7 @@ import RecentlyCreatedIcon from './Icons/RecentlyCreatedIcon';
 
 // eslint-disable-next-line no-unused-vars
 const logger = loggerFactory('growi:TableOfContents');
+const WIKI_HEADER_LINK = 120;
 
 /**
  * @author Yuki Takei <yuki@weseek.co.jp>
@@ -47,6 +48,10 @@ const TableOfContents = (props) => {
     navigationContainer.addSmoothScrollEvent(anchorsInToc);
   }, [tocHtml, navigationContainer]);
 
+  // get element for smoothScroll
+  const getBookMarkListHeaderDom = useMemo(() => { return document.getElementById('bookmarks-list') }, []);
+  const getRecentlyCreatedListHeaderDom = useMemo(() => { return document.getElementById('recently-created-list') }, []);
+
   return (
     <>
       <TopOfTableContents isGuestUserMode={isGuestUserMode} />
@@ -67,23 +72,22 @@ const TableOfContents = (props) => {
 
       { isUserPage && (
       <div className="mt-3 d-flex justify-content-around">
-        {/* <a className="btn btn-outline-secondary btn-sm" href="#bookmarks-list">
-          <i className="mr-2 icon-star"></i>
-          <span>Bookmarks</span>
-        </a> */}
         <button
           type="button"
           className="btn btn-outline-secondary btn-sm"
-          href="#bookmarks-list"
+          onClick={() => navigationContainer.smoothScrollIntoView(getBookMarkListHeaderDom, WIKI_HEADER_LINK)}
         >
-
           <i className="mr-2 icon-star"></i>
           <span>Bookmarks</span>
         </button>
-        <a className="btn btn-outline-secondary btn-sm" href="#recently-created-list">
+        <button
+          type="button"
+          className="btn btn-outline-secondary btn-sm"
+          onClick={() => navigationContainer.smoothScrollIntoView(getRecentlyCreatedListHeaderDom, WIKI_HEADER_LINK)}
+        >
           <i className="grw-icon-container-recently-created mr-2"><RecentlyCreatedIcon /></i>
           <span>Recently Created</span>
-        </a>
+        </button>
       </div>
       )}
     </>