Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit aa30ada

Browse files
benedikt-rothjosephperrott
authored andcommitted
feat(tabs): Custom class names for tabs (#11332)
1 parent affe84b commit aa30ada

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

src/components/tabs/demoStaticTabs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<md-content class="md-padding">
33
<md-tabs class="md-primary" md-selected="data.selectedIndex"
44
md-align-tabs="{{data.bottom ? 'bottom' : 'top'}}">
5-
<md-tab id="tab1">
5+
<md-tab id="tab1" md-tab-class="example-selector-tab1">
66
<md-tab-label>Item One</md-tab-label>
77
<md-tab-body>
88
View for Item #1 <br/>

src/components/tabs/js/tabDirective.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* @param {string=} label Optional attribute to specify a simple string as the tab label
2626
* @param {boolean=} ng-disabled If present and expression evaluates to truthy, disabled tab
2727
* selection.
28+
* @param {string=} md-tab-class Optional attribute to specify a class that will be applied to the tab's button
2829
* @param {expression=} md-on-deselect Expression to be evaluated after the tab has been
2930
* de-selected.
3031
* @param {expression=} md-on-select Expression to be evaluated after the tab has been selected.
@@ -35,7 +36,7 @@
3536
* @usage
3637
*
3738
* <hljs lang="html">
38-
* <md-tab label="My Tab" ng-disabled md-on-select="onSelect()" md-on-deselect="onDeselect()">
39+
* <md-tab label="My Tab" md-tab-class="my-content-tab" ng-disabled md-on-select="onSelect()" md-on-deselect="onDeselect()">
3940
* <h3>My Tab content</h3>
4041
* </md-tab>
4142
*
@@ -89,7 +90,8 @@ function MdTab () {
8990
active: '=?mdActive',
9091
disabled: '=?ngDisabled',
9192
select: '&?mdOnSelect',
92-
deselect: '&?mdOnDeselect'
93+
deselect: '&?mdOnDeselect',
94+
tabClass: '@mdTabClass'
9395
}
9496
};
9597

src/components/tabs/js/tabsDirective.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ function MdTabs ($$mdSvgRegistry) {
165165
'aria-label="{{::$mdTabsCtrl.navigationHint}}">' +
166166
'<md-tab-item ' +
167167
'tabindex="{{ tab.isActive() ? 0 : -1 }}" ' +
168-
'class="md-tab" ' +
168+
'class="md-tab {{::tab.scope.tabClass}}" ' +
169169
'ng-repeat="tab in $mdTabsCtrl.tabs" ' +
170170
'role="tab" ' +
171171
'id="tab-item-{{::tab.id}}" ' +

src/components/tabs/tabs.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,16 @@ describe('<md-tabs>', function () {
450450
expect(tab.find('md-tab-label').text()).toBe('test');
451451
expect(tab.find('md-tab-body').length).toBe(0);
452452
});
453+
it('should apply tab class on the associated md-tab-item', function () {
454+
var template = '\
455+
<md-tabs md-selected="selectedTab">\
456+
<md-tab label="a" md-tab-class="tester-class"></md-tab>\
457+
</md-tabs>';
458+
var element = setup(template);
459+
var tab = element.find('md-tab-item');
460+
461+
expect(tab[ 0 ].className.indexOf('tester-class')).toBeGreaterThan(-1);
462+
});
453463
});
454464

455465
describe('internal scope', function () {

0 commit comments

Comments
 (0)