Skip to content

Commit

Permalink
feat(tabs): make debounce wait configurable prop (#10385)
Browse files Browse the repository at this point in the history
* feat(tabs): make debounce wait configurable prop

* test: update snaps

* fix(tabs): ensure scrollDebounceWait is not passed through ...other

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
tay1orjones and kodiakhq[bot] authored Jan 21, 2022
1 parent eaf09dd commit 8272a2e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6706,6 +6706,7 @@ Map {
"$$typeof": Symbol(react.context),
},
"defaultProps": Object {
"scrollDebounceWait": 150,
"scrollIntoView": true,
"selected": 0,
"selectionMode": "automatic",
Expand Down Expand Up @@ -6739,6 +6740,9 @@ Map {
"rightOverflowButtonProps": Object {
"type": "object",
},
"scrollDebounceWait": Object {
"type": "number",
},
"scrollIntoView": Object {
"type": "bool",
},
Expand Down
14 changes: 13 additions & 1 deletion packages/react/src/components/Tabs/Tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ export default class Tabs extends React.Component {
*/
rightOverflowButtonProps: PropTypes.object,

/**
* Optionally provide a delay (in milliseconds) passed to the lodash
* debounce of the onScroll handler. This will impact the responsiveness
* of scroll arrow buttons rendering when scrolling to the first or last tab.
*/
scrollDebounceWait: PropTypes.number,

/**
* Choose whether or not to automatically scroll to newly selected tabs
* on component rerender
Expand Down Expand Up @@ -99,6 +106,7 @@ export default class Tabs extends React.Component {
scrollIntoView: true,
selected: 0,
selectionMode: 'automatic',
scrollDebounceWait: 150,
};

static contextType = PrefixContext;
Expand Down Expand Up @@ -174,7 +182,10 @@ export default class Tabs extends React.Component {
window.addEventListener('resize', this._debouncedHandleWindowResize);

if (!this._debouncedHandleScroll) {
this._debouncedHandleScroll = debounce(this._handleScroll, 125);
this._debouncedHandleScroll = debounce(
this._handleScroll,
this.props.scrollDebounceWait
);
}

// scroll selected tab into view on mount
Expand Down Expand Up @@ -411,6 +422,7 @@ export default class Tabs extends React.Component {
type,
light,
onSelectionChange,
scrollDebounceWait, // eslint-disable-line no-unused-vars
scrollIntoView, // eslint-disable-line no-unused-vars
selectionMode, // eslint-disable-line no-unused-vars
tabContentClassName,
Expand Down

0 comments on commit 8272a2e

Please sign in to comment.