Skip to content

Commit eb7c17e

Browse files
asyncLizcopybara-github
authored andcommitted
fix(tabs): tabs.scrollToTab() not working
Fixes material-components#5385 The thing that scrolls is an internal element, not the host element. PiperOrigin-RevId: 599221652
1 parent a3a05e4 commit eb7c17e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

tabs/internal/tabs.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export class Tabs extends LitElement {
102102
*/
103103
@property({type: Boolean, attribute: 'auto-activate'}) autoActivate = false;
104104

105+
@query('.tabs') private readonly tabsScrollerElement!: HTMLElement | null;
105106
@query('slot') private readonly slotElement!: HTMLSlotElement | null;
106107

107108
private get focusedTab() {
@@ -134,7 +135,11 @@ export class Tabs extends LitElement {
134135
await this.updateComplete;
135136
const {tabs} = this;
136137
tabToScrollTo ??= this.activeTab;
137-
if (!tabToScrollTo || !tabs.includes(tabToScrollTo)) {
138+
if (
139+
!tabToScrollTo ||
140+
!tabs.includes(tabToScrollTo) ||
141+
!this.tabsScrollerElement
142+
) {
138143
return;
139144
}
140145

@@ -153,7 +158,7 @@ export class Tabs extends LitElement {
153158
const to = Math.min(min, Math.max(max, scroll));
154159
// TODO(b/299934312): improve focus smoothness
155160
const behavior: ScrollBehavior = !this.focusedTab ? 'smooth' : 'instant';
156-
this.scrollTo({behavior, top: 0, left: to});
161+
this.tabsScrollerElement.scrollTo({behavior, top: 0, left: to});
157162
}
158163

159164
protected override render() {

0 commit comments

Comments
 (0)