-
Notifications
You must be signed in to change notification settings - Fork 905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add "active-tab-index" attribute support for Tabs? #5297
Add "active-tab-index" attribute support for Tabs? #5297
Comments
I think the request is reasonable, but are there pain points to setting the <md-tabs>
<md-primary-tab>Tab 1</md-primary-tab>
<md-primary-tab active>Tab 2</md-primary-tab>
</md-tabs> The parent's active tab index is more expensive than its children, since it will look up and set the child's attribute. Select is the same way, and discourages using |
Thanks for the suggestion, I can't recall now what issue I ran into trying to use
Also in reactive frameworks, usually it's a bit awkward to use @{
var counter = 0;
}
<md-tabs @onchange="ProcessTabIndexChange">
@foreach (var tab of tabs)
{
var z = counter++; // Must have a scoped variable here because counter changes
<md-tab label="@(tab.Title)" active="@(z == currTabIndex)"></md-tab>
}
</md-tabs> If <md-tabs @bind-ActiveTabIndex="currTabIndex">
@foreach (var tab of tabs)
{
<md-tab label="@(tab.Title)"></md-tab>
}
</md-tabs> |
I agree and expected this behaviour based on the properties defined in the docs. I'm using the bundled version from npm and was able to get it running by just adding the following patch: diff --git a/node_modules/@material/web/tabs/internal/tabs.js b/node_modules/@material/web/tabs/internal/tabs.js
index 801d980..a2844e6 100644
--- a/node_modules/@material/web/tabs/internal/tabs.js
+++ b/node_modules/@material/web/tabs/internal/tabs.js
@@ -270,6 +270,9 @@ export class Tabs extends LitElement {
__decorate([
queryAssignedElements({ flatten: true, selector: '[md-tab]' })
], Tabs.prototype, "tabs", void 0);
+__decorate([
+ property({ type: Number, attribute: 'active-tab-index' })
+], Tabs.prototype, "activeTabIndex", void 0);
__decorate([
property({ type: Boolean, attribute: 'auto-activate' })
], Tabs.prototype, "autoActivate", void 0); It looks like everything that is necessary to get it working is already there, there is just a binding to the outer world missing. For the |
Description
I think Lit Playground should work for
<md-tabs>
similar to<md-select>
'sselected-index
:This would make life much easier for a lot of Web frameworks where it's much harder to access DOM property than HTML attributes.
The text was updated successfully, but these errors were encountered: