@@ -69,6 +69,7 @@ const Tabs = props => {
6969
7070 const initializeScrollIncrements = ( ) => {
7171 const tabContainerWidth = tabRef . current . parentElement . clientWidth
72+ const tabContainerWidthWithBuffer = tabContainerWidth - MARGIN_BUFFER
7273
7374 if ( ! tabScrollIntervals . current . length ) {
7475 let tabMargin = null
@@ -79,36 +80,34 @@ const Tabs = props => {
7980 Array . from ( tabRef . current . children [ 0 ] . childNodes )
8081 // populates tabScrollIntervals and tabArrowKeyIntervals
8182 let currentTabsLength = 0
83+
8284 tabsArray . forEach ( ( value , index ) => {
8385 if ( ! tabMargin ) {
8486 tabMargin = value . offsetLeft * 2
8587 }
8688 const increment = value . offsetWidth + tabMargin
8789 totalTabWidth += increment
8890
89- if (
90- increment > tabContainerWidth - MARGIN_BUFFER &&
91- tabScrollIntervals . current . length === 0
92- ) {
91+ if ( increment > tabContainerWidthWithBuffer && tabScrollIntervals . current . length === 0 ) {
9392 tabScrollIntervals . current . push ( increment - MARGIN_BUFFER )
9493 tabArrowKeyIntervals . current . push ( index )
9594 currentTabsLength = 0
9695 } else if (
97- increment > tabContainerWidth - MARGIN_BUFFER &&
96+ increment > tabContainerWidthWithBuffer &&
9897 tabScrollIntervals . current . length !== 0
9998 ) {
10099 tabScrollIntervals . current . push ( increment )
101100 tabArrowKeyIntervals . current . push ( index )
102101 currentTabsLength = 0
103102 } else if (
104- currentTabsLength + increment > tabContainerWidth - MARGIN_BUFFER &&
103+ currentTabsLength + increment > tabContainerWidthWithBuffer &&
105104 tabScrollIntervals . current . length === 0
106105 ) {
107106 tabScrollIntervals . current . push ( currentTabsLength - MARGIN_BUFFER )
108107 tabArrowKeyIntervals . current . push ( index )
109108 currentTabsLength = increment
110109 } else if (
111- currentTabsLength + increment > tabContainerWidth - MARGIN_BUFFER * 2 &&
110+ currentTabsLength + increment > tabContainerWidthWithBuffer - MARGIN_BUFFER &&
112111 tabScrollIntervals . current . length !== 0
113112 ) {
114113 tabScrollIntervals . current . push ( currentTabsLength )
@@ -127,6 +126,7 @@ const Tabs = props => {
127126 for ( let i = 0 ; i < tabScrollIntervals . current . length - 1 ; i += 1 ) {
128127 tabSumBeforeFinalScroll += tabScrollIntervals . current [ i ]
129128 }
129+
130130 tabScrollIntervals . current [ tabScrollIntervals . current . length - 1 ] =
131131 totalTabWidth - tabContainerWidth - tabSumBeforeFinalScroll
132132 } else {
0 commit comments