Skip to content

Commit

Permalink
fix(tabs)!: use md-tab attribute to brand individual tab children
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 568943375
  • Loading branch information
AndrewJakubowicz authored and copybara-github committed Sep 27, 2023
1 parent b591196 commit 8ec0813
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
8 changes: 8 additions & 0 deletions tabs/internal/tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ export class Tab extends LitElement {
setupHostAria(Tab);
}

/**
* The attribute `md-tab` indicates that the element is a tab for the parent
* element, `<md-tabs>`. Make sure if you're implementing your own `md-tab`
* component that you have an `md-tab` attribute set.
*/
@property({type: Boolean, reflect: true, attribute: 'md-tab'})
readonly isTab = true;

/**
* Whether or not the tab is selected.
**/
Expand Down
11 changes: 4 additions & 7 deletions tabs/internal/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ export class Tabs extends LitElement {
/**
* The tabs of this tab bar.
*/
get tabs() {
return this.maybeTabs.filter(isTab);
}
@queryAssignedElements({flatten: true, selector: '[md-tab]'})
readonly tabs!: Tab[];

/**
* The currently selected tab, `null` only when there are no tab children.
Expand Down Expand Up @@ -106,8 +105,6 @@ export class Tabs extends LitElement {
@property({type: Boolean, attribute: 'auto-activate'}) autoActivate = false;

@query('slot') private readonly slotElement!: HTMLSlotElement|null;
@queryAssignedElements({flatten: true})
private readonly maybeTabs!: HTMLElement[];

private get focusedTab() {
return this.tabs.find(tab => tab.matches(':focus-within'));
Expand Down Expand Up @@ -307,5 +304,5 @@ export class Tabs extends LitElement {
}

function isTab(element: unknown): element is Tab {
return element instanceof Tab;
}
return element instanceof HTMLElement && element.hasAttribute('md-tab');
}

0 comments on commit 8ec0813

Please sign in to comment.