@@ -10,7 +10,7 @@ const useResize = (refTabList: MutableRefObject<HTMLDivElement | null>) => {
1010 const [ viewWidth , setViewWidth ] = useState ( 0 ) ;
1111
1212 const handleWindowSizeChange = useCallback ( ( ) => {
13- setViewWidth ( refTabList ? .current ?. offsetWidth ?? 0 ) ;
13+ setViewWidth ( refTabList . current ?. offsetWidth ?? 0 ) ;
1414 } , [ refTabList ] ) ;
1515
1616 useEffect ( ( ) => {
@@ -60,21 +60,21 @@ const DxcTabs = ({
6060
6161 useEffect ( ( ) => {
6262 if ( activeTabIndex != null || innerActiveTabIndex != null ) {
63- const sumWidth = refTabs ? .current ?. reduce ( ( count , obj ) => count + obj . offsetWidth , 0 ) ;
63+ const sumWidth = refTabs . current ?. reduce ( ( count , obj ) => count + obj . offsetWidth , 0 ) ;
6464 setTotalTabsWidth ( sumWidth ) ;
65- setActiveIndicatorWidth ( refTabs ? .current [ activeTabIndex ?? innerActiveTabIndex ! ] ?. offsetWidth ?? 0 ) ;
66- setActiveIndicatorLeft ( refTabs ? .current [ activeTabIndex ?? innerActiveTabIndex ! ] ?. offsetLeft ?? 0 ) ;
65+ setActiveIndicatorWidth ( refTabs . current [ activeTabIndex ?? innerActiveTabIndex ! ] ?. offsetWidth ?? 0 ) ;
66+ setActiveIndicatorLeft ( refTabs . current [ activeTabIndex ?? innerActiveTabIndex ! ] ?. offsetLeft ?? 0 ) ;
6767 }
68- } , [ refTabs ] ) ;
68+ } , [ activeTabIndex , innerActiveTabIndex ] ) ;
6969
7070 useEffect ( ( ) => {
71- setMinHeightTabs ( ( refTabList ? .current ?. offsetHeight || 0 ) + 1 ) ;
72- } , [ refTabList ] ) ;
71+ setMinHeightTabs ( ( refTabList . current ?. offsetHeight ?? 0 ) + 1 ) ;
72+ } , [ ] ) ;
7373
7474 useEffect ( ( ) => {
7575 if ( activeTabIndex && activeTabIndex >= 0 ) {
76- setActiveIndicatorWidth ( refTabs ? .current [ activeTabIndex ] ?. offsetWidth ?? 0 ) ;
77- setActiveIndicatorLeft ( refTabs ? .current [ activeTabIndex ] ?. offsetLeft ?? 0 ) ;
76+ setActiveIndicatorWidth ( refTabs . current [ activeTabIndex ] ?. offsetWidth ?? 0 ) ;
77+ setActiveIndicatorLeft ( refTabs . current [ activeTabIndex ] ?. offsetLeft ?? 0 ) ;
7878 }
7979 } , [ activeTabIndex ] ) ;
8080
@@ -84,13 +84,13 @@ const DxcTabs = ({
8484 }
8585 onTabClick ?.( newValue ) ;
8686 if ( activeTabIndex === undefined ) {
87- setActiveIndicatorWidth ( refTabs ? .current [ newValue ] ?. offsetWidth ?? 0 ) ;
88- setActiveIndicatorLeft ( refTabs ? .current [ newValue ] ?. offsetLeft ?? 0 ) ;
87+ setActiveIndicatorWidth ( refTabs . current [ newValue ] ?. offsetWidth ?? 0 ) ;
88+ setActiveIndicatorLeft ( refTabs . current [ newValue ] ?. offsetLeft ?? 0 ) ;
8989 }
9090 } ;
9191
9292 const scrollLeft = ( ) => {
93- const scrollWidth = ( refTabList ?. current ?. offsetHeight || 0 ) * 0.75 ;
93+ const scrollWidth = ( refTabList ?. current ?. offsetHeight ?? 0 ) * 0.75 ;
9494 let moveX = 0 ;
9595 if ( countClick <= scrollWidth ) {
9696 moveX = 0 ;
@@ -106,10 +106,11 @@ const DxcTabs = ({
106106 } ;
107107
108108 const scrollRight = ( ) => {
109- const scrollWidth = ( refTabList ?. current ?. offsetHeight || 0 ) * 0.75 ;
109+ const offsetHeight = refTabList ?. current ?. offsetHeight ?? 0 ;
110+ const scrollWidth = offsetHeight * 0.75 ;
110111 let moveX = 0 ;
111- if ( countClick + scrollWidth + ( refTabList ?. current ?. offsetHeight || 0 ) >= totalTabsWidth ) {
112- moveX = totalTabsWidth - ( refTabList ?. current ?. offsetHeight || 0 ) ;
112+ if ( countClick + scrollWidth + offsetHeight >= totalTabsWidth ) {
113+ moveX = totalTabsWidth - offsetHeight ;
113114 setScrollRightEnabled ( false ) ;
114115 setScrollLeftEnabled ( true ) ;
115116 } else {
@@ -129,7 +130,7 @@ const DxcTabs = ({
129130 while ( tabs [ index ] ?. isDisabled ) {
130131 index = index === 0 ? tabs . length - 1 : index - 1 ;
131132 }
132- refTabs ? .current [ index ] ?. focus ( { preventScroll : true } ) ;
133+ refTabs . current [ index ] ?. focus ( { preventScroll : true } ) ;
133134 setScrollFocus ( index ) ;
134135 return index ;
135136 }
@@ -146,7 +147,7 @@ const DxcTabs = ({
146147 while ( tabs [ index ] ?. isDisabled ) {
147148 index = index === tabs . length - 1 ? 0 : index + 1 ;
148149 }
149- refTabs ? .current [ index ] ?. focus ( { preventScroll : true } ) ;
150+ refTabs . current [ index ] ?. focus ( { preventScroll : true } ) ;
150151 setScrollFocus ( index ) ;
151152 return index ;
152153 }
@@ -158,7 +159,7 @@ const DxcTabs = ({
158159 const setScrollFocus = ( actualIndex : number ) => {
159160 if ( tabs ) {
160161 let sumPrev = 0 ;
161- refTabs ? .current ?. forEach ( ( item , index ) => {
162+ refTabs . current ?. forEach ( ( item , index ) => {
162163 if ( index <= actualIndex ) {
163164 sumPrev += item . offsetWidth ;
164165 }
@@ -207,7 +208,7 @@ const DxcTabs = ({
207208 if ( temporalFocusIndex !== currentFocusIndex ) {
208209 event . preventDefault ( ) ;
209210 setTemporalFocusIndex ( currentFocusIndex ) ;
210- refTabs ? .current [ currentFocusIndex ] ?. focus ( ) ;
211+ refTabs . current [ currentFocusIndex ] ?. focus ( ) ;
211212 }
212213 handleSelected ( currentFocusIndex ) ;
213214 }
0 commit comments