Browse Source

success to get first navtab width in customNavigation

kaori 5 years ago
parent
commit
2f9ac48973
1 changed files with 10 additions and 3 deletions
  1. 10 3
      src/client/js/components/CustomNavigation.jsx

+ 10 - 3
src/client/js/components/CustomNavigation.jsx

@@ -8,8 +8,10 @@ import {
 const CustomNavigation = (props) => {
 const CustomNavigation = (props) => {
   const [activeTab, setActiveTab] = useState('');
   const [activeTab, setActiveTab] = useState('');
   // [TODO: set default active tab by gw4079]
   // [TODO: set default active tab by gw4079]
+
+  // const [defaultActiveTab, setDefaultActiveTab] = (null);
   const [sliderWidth, setSliderWidth] = useState(null);
   const [sliderWidth, setSliderWidth] = useState(null);
-  const [sliderMarginLeft, setSliderMarginLeft] = useState(null);
+  const [sliderMarginLeft, setSliderMarginLeft] = useState(0);
 
 
   function switchActiveTab(activeTab) {
   function switchActiveTab(activeTab) {
     setActiveTab(activeTab);
     setActiveTab(activeTab);
@@ -19,14 +21,19 @@ const CustomNavigation = (props) => {
   function getPercentage(min, max) {
   function getPercentage(min, max) {
     return min / max * 100;
     return min / max * 100;
   }
   }
+  const navBar = document.getElementById('grw-custom-navbar');
+  const navTabs = document.querySelectorAll('ul.grw-custom-navbar > li.grw-custom-navtab');
+
 
 
   useEffect(() => {
   useEffect(() => {
     if (activeTab === '') {
     if (activeTab === '') {
       return;
       return;
     }
     }
 
 
-    const navBar = document.getElementById('grw-custom-navbar');
-    const navTabs = document.querySelectorAll('ul.grw-custom-navbar > li.grw-custom-navtab');
+    const defaultActiveTab = navTabs[0];
+    const defaultActiveWidth = defaultActiveTab.offsetWidth;
+    console.log(defaultActiveWidth);
+
 
 
     if (navBar == null || navTabs == null) {
     if (navBar == null || navTabs == null) {
       return;
       return;