Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 4bfae22

Browse files
Leonard Seymorewesleycho
Leonard Seymore
authored andcommitted
fix(tab): change to disable attribute
- Switch support to `disable` attribute - Deprecate support for `disabled` Closes #2677
1 parent 461087b commit 4bfae22

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

src/tabs/docs/demo.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<tabset>
1313
<tab heading="Static title">Static content</tab>
14-
<tab ng-repeat="tab in tabs" heading="{{tab.title}}" active="tab.active" disabled="tab.disabled">
14+
<tab ng-repeat="tab in tabs" heading="{{tab.title}}" active="tab.active" disable="tab.disabled">
1515
{{tab.content}}
1616
</tab>
1717
<tab select="alertMe()">

src/tabs/docs/readme.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ AngularJS version of the tabs directive.
2626
_(Defaults: false)_ :
2727
Whether tab is currently selected.
2828

29-
* `disabled` <i class="glyphicon glyphicon-eye-open"></i>
29+
* `disable` <i class="glyphicon glyphicon-eye-open"></i>
3030
_(Defaults: false)_ :
3131
Whether tab is clickable and can be activated.
32+
Note that this was previously the `disabled` attribute, which is now deprecated.
3233

3334
* `select()`
3435
_(Defaults: null)_ :
3536
An optional expression called when tab is activated.
3637

3738
* `deselect()`
3839
_(Defaults: null)_ :
39-
An optional expression called when tab is deactivated.
40+
An optional expression called when tab is deactivated.

src/tabs/tabs.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ angular.module('ui.bootstrap.tabs', [])
182182
</file>
183183
</example>
184184
*/
185-
.directive('tab', ['$parse', function($parse) {
185+
.directive('tab', ['$parse', '$log', function($parse, $log) {
186186
return {
187187
require: '^tabset',
188188
restrict: 'EA',
@@ -208,7 +208,18 @@ angular.module('ui.bootstrap.tabs', [])
208208
});
209209

210210
scope.disabled = false;
211+
if ( attrs.disable ) {
212+
scope.$parent.$watch($parse(attrs.disable), function(value) {
213+
scope.disabled = !! value;
214+
});
215+
}
216+
217+
// Deprecation support of "disabled" parameter
218+
// fix(tab): IE9 disabled attr renders grey text on enabled tab #2677
219+
// This code is duplicated from the lines above to make it easy to remove once
220+
// the feature has been completely deprecated
211221
if ( attrs.disabled ) {
222+
$log.warn('Use of "disabled" attribute has been deprecated, please use "disable"');
212223
scope.$parent.$watch($parse(attrs.disabled), function(value) {
213224
scope.disabled = !! value;
214225
});

src/tabs/test/tabs.spec.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -566,23 +566,23 @@ describe('tabs', function() {
566566
}));
567567
});
568568

569-
describe('disabled', function() {
569+
describe('disable', function() {
570570
beforeEach(inject(function($compile, $rootScope) {
571571
scope = $rootScope.$new();
572572

573-
function makeTab(disabled) {
573+
function makeTab(disable) {
574574
return {
575575
active: false,
576576
select: jasmine.createSpy(),
577-
disabled: disabled
577+
disable: disable
578578
};
579579
}
580580
scope.tabs = [
581581
makeTab(false), makeTab(true), makeTab(false), makeTab(true)
582582
];
583583
elm = $compile([
584584
'<tabset>',
585-
' <tab ng-repeat="t in tabs" active="t.active" select="t.select()" disabled="t.disabled">',
585+
' <tab ng-repeat="t in tabs" active="t.active" select="t.select()" disable="t.disable">',
586586
' <tab-heading><b>heading</b> {{index}}</tab-heading>',
587587
' content {{$index}}',
588588
' </tab>',
@@ -596,7 +596,7 @@ describe('tabs', function() {
596596
angular.forEach(scope.tabs, function(tab, i) {
597597
if (activeTab === tab) {
598598
expect(tab.active).toBe(true);
599-
expect(tab.select.calls.count()).toBe( (tab.disabled) ? 0 : 1 );
599+
expect(tab.select.calls.count()).toBe( (tab.disable) ? 0 : 1 );
600600
expect(_titles.eq(i)).toHaveClass('active');
601601
expect(contents().eq(i).text().trim()).toBe('content ' + i);
602602
expect(contents().eq(i)).toHaveClass('active');
@@ -617,11 +617,11 @@ describe('tabs', function() {
617617

618618
it('should toggle between states', function() {
619619
expect(titles().eq(3)).toHaveClass('disabled');
620-
scope.$apply('tabs[3].disabled = false');
620+
scope.$apply('tabs[3].disable = false');
621621
expect(titles().eq(3)).not.toHaveClass('disabled');
622622

623623
expect(titles().eq(2)).not.toHaveClass('disabled');
624-
scope.$apply('tabs[2].disabled = true');
624+
scope.$apply('tabs[2].disable = true');
625625
expect(titles().eq(2)).toHaveClass('disabled');
626626
});
627627
});

0 commit comments

Comments
 (0)