Skip to content

Commit 274ce3e

Browse files
asynclizcopybara-github
authored andcommitted
fix(tabs): default scroll-behavior: smooth not working
Fixes #5497 PiperOrigin-RevId: 610915724
1 parent c6ffd70 commit 274ce3e

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

tabs/internal/_tabs.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
display: flex;
3030
height: 100%;
3131
overflow: inherit;
32+
scroll-behavior: inherit;
33+
scrollbar-width: inherit;
3234
justify-content: space-between;
3335
width: 100%;
3436
}

tabs/internal/tabs.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,11 @@ export class Tabs extends LitElement {
157157
const min = offset - scrollMargin;
158158
const max = offset + extent - hostExtent + scrollMargin;
159159
const to = Math.min(min, Math.max(max, scroll));
160-
// TODO(b/299934312): improve focus smoothness
161-
const behavior: ScrollBehavior = !this.focusedTab ? 'smooth' : 'instant';
160+
// When a tab is focused, use 'auto' to use the CSS `scroll-behavior`. The
161+
// default behavior is smooth scrolling. However, when there is not a tab
162+
// focused on initialization, use 'instant' to immediately bring the focused
163+
// tab into view.
164+
const behavior: ScrollBehavior = !this.focusedTab ? 'instant' : 'auto';
162165
this.tabsScrollerElement.scrollTo({behavior, top: 0, left: to});
163166
}
164167

0 commit comments

Comments
 (0)