Skip to content

Commit

Permalink
AUTO-HIDE: extract to constant
Browse files Browse the repository at this point in the history
  • Loading branch information
yringler committed Jul 31, 2024
1 parent a29eabe commit d603b37
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/components/tab-group/tab-group.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,15 +372,21 @@ export default class SlTabGroup extends ShoelaceElement {
return nextTab;
}

/**
* The reality of the browser means that we can't expect the scroll position to be exactly what we want it to be, so
* we add one pixel of wiggle room to our calculations.
*/
private scrollOffset = 1;

private updateScrollButtons() {
if (this.hasScrollControls && this.autoHideScrollButtons) {
this.shouldHideScrollStartButton = this.scrollFromStart() <= 0;
this.shouldHideScrollStartButton = this.scrollFromStart() <= this.scrollOffset;
this.shouldHideScrollEndButton = this.isScrolledToEnd();
}
}

private isScrolledToEnd() {
return (this.scrollFromStart() + this.nav.clientWidth) >= this.nav.scrollWidth;
return (this.scrollFromStart() + this.nav.clientWidth) >= this.nav.scrollWidth - this.scrollOffset;
}

private scrollFromStart() {
Expand Down

0 comments on commit d603b37

Please sign in to comment.