Skip to content

Commit a6dc264

Browse files
tay1orjonessstrubberg
authored andcommitted
fix(tabs): debounce scroll handler (#10120)
1 parent 1836ce1 commit a6dc264

File tree

1 file changed

+14
-1
lines changed
  • packages/react/src/components/Tabs

1 file changed

+14
-1
lines changed

packages/react/src/components/Tabs/Tabs.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,15 @@ export default class Tabs extends React.Component {
153153

154154
_handleWindowResize = this.handleScroll;
155155

156+
/**
157+
* The debounced version of the `scroll` event handler.
158+
* @type {Function}
159+
* @private
160+
*/
161+
_debouncedHandleScroll = null;
162+
163+
_handleScroll = this.handleScroll;
164+
156165
componentDidMount() {
157166
if (!this._debouncedHandleWindowResize) {
158167
this._debouncedHandleWindowResize = debounce(
@@ -164,6 +173,10 @@ export default class Tabs extends React.Component {
164173
this._handleWindowResize();
165174
window.addEventListener('resize', this._debouncedHandleWindowResize);
166175

176+
if (!this._debouncedHandleScroll) {
177+
this._debouncedHandleScroll = debounce(this._handleScroll, 125);
178+
}
179+
167180
// scroll selected tab into view on mount
168181
const {
169182
clientWidth: tablistClientWidth,
@@ -516,7 +529,7 @@ export default class Tabs extends React.Component {
516529
tabIndex={-1}
517530
className={classes.tablist}
518531
ref={this.tablist}
519-
onScroll={this.handleScroll}>
532+
onScroll={this._debouncedHandleScroll}>
520533
{tabsWithProps}
521534
</ul>
522535
{!rightOverflowNavButtonHidden && (

0 commit comments

Comments
 (0)