Skip to content

Commit

Permalink
fix(tabs): scroll exceeding tabs limit
Browse files Browse the repository at this point in the history
  • Loading branch information
mizgaionutalexandru committed Sep 4, 2024
1 parent f4df058 commit d3b3230
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/tabs/src/Tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,28 @@ export class Tabs extends SizedMixin(Focusable, { noDefaultSize: true }) {
return this.rovingTabindexController.focusInElement || this;
}

private limitDelta(min: number, max: number) {
return (delta: number): number => Math.min(Math.max(delta, min), max);
}

public scrollTabs(
delta: number,
behavior: ScrollBehavior = 'smooth'
): void {
if (delta === 0) return;

const { scrollLeft, clientWidth, scrollWidth } = this.tabList;
const dirLimit = scrollWidth - clientWidth - Math.abs(scrollLeft);

const limitDelta =
this.dir === 'ltr'
? this.limitDelta(-scrollLeft, dirLimit)
: this.limitDelta(-dirLimit, Math.abs(scrollLeft));

const left = limitDelta(delta);

this.tabList?.scrollBy({
left: delta,
left,
top: 0,
behavior,
});
Expand Down

0 comments on commit d3b3230

Please sign in to comment.