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

Commit

Permalink
fix(tab): change to disable attribute
Browse files Browse the repository at this point in the history
- Switch support to `disable` attribute
- Deprecate support for `disabled`

Closes #2677
  • Loading branch information
Leonard Seymore authored and wesleycho committed Apr 7, 2015
1 parent 461087b commit 4bfae22
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/tabs/docs/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<tabset>
<tab heading="Static title">Static content</tab>
<tab ng-repeat="tab in tabs" heading="{{tab.title}}" active="tab.active" disabled="tab.disabled">
<tab ng-repeat="tab in tabs" heading="{{tab.title}}" active="tab.active" disable="tab.disabled">
{{tab.content}}
</tab>
<tab select="alertMe()">
Expand Down
5 changes: 3 additions & 2 deletions src/tabs/docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ AngularJS version of the tabs directive.
_(Defaults: false)_ :
Whether tab is currently selected.

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

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

* `deselect()`
_(Defaults: null)_ :
An optional expression called when tab is deactivated.
An optional expression called when tab is deactivated.
13 changes: 12 additions & 1 deletion src/tabs/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ angular.module('ui.bootstrap.tabs', [])
</file>
</example>
*/
.directive('tab', ['$parse', function($parse) {
.directive('tab', ['$parse', '$log', function($parse, $log) {
return {
require: '^tabset',
restrict: 'EA',
Expand All @@ -208,7 +208,18 @@ angular.module('ui.bootstrap.tabs', [])
});

scope.disabled = false;
if ( attrs.disable ) {
scope.$parent.$watch($parse(attrs.disable), function(value) {
scope.disabled = !! value;
});
}

// Deprecation support of "disabled" parameter
// fix(tab): IE9 disabled attr renders grey text on enabled tab #2677
// This code is duplicated from the lines above to make it easy to remove once
// the feature has been completely deprecated
if ( attrs.disabled ) {
$log.warn('Use of "disabled" attribute has been deprecated, please use "disable"');
scope.$parent.$watch($parse(attrs.disabled), function(value) {
scope.disabled = !! value;
});
Expand Down
14 changes: 7 additions & 7 deletions src/tabs/test/tabs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,23 +566,23 @@ describe('tabs', function() {
}));
});

describe('disabled', function() {
describe('disable', function() {
beforeEach(inject(function($compile, $rootScope) {
scope = $rootScope.$new();

function makeTab(disabled) {
function makeTab(disable) {
return {
active: false,
select: jasmine.createSpy(),
disabled: disabled
disable: disable
};
}
scope.tabs = [
makeTab(false), makeTab(true), makeTab(false), makeTab(true)
];
elm = $compile([
'<tabset>',
' <tab ng-repeat="t in tabs" active="t.active" select="t.select()" disabled="t.disabled">',
' <tab ng-repeat="t in tabs" active="t.active" select="t.select()" disable="t.disable">',
' <tab-heading><b>heading</b> {{index}}</tab-heading>',
' content {{$index}}',
' </tab>',
Expand All @@ -596,7 +596,7 @@ describe('tabs', function() {
angular.forEach(scope.tabs, function(tab, i) {
if (activeTab === tab) {
expect(tab.active).toBe(true);
expect(tab.select.calls.count()).toBe( (tab.disabled) ? 0 : 1 );
expect(tab.select.calls.count()).toBe( (tab.disable) ? 0 : 1 );
expect(_titles.eq(i)).toHaveClass('active');
expect(contents().eq(i).text().trim()).toBe('content ' + i);
expect(contents().eq(i)).toHaveClass('active');
Expand All @@ -617,11 +617,11 @@ describe('tabs', function() {

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

expect(titles().eq(2)).not.toHaveClass('disabled');
scope.$apply('tabs[2].disabled = true');
scope.$apply('tabs[2].disable = true');
expect(titles().eq(2)).toHaveClass('disabled');
});
});
Expand Down

0 comments on commit 4bfae22

Please sign in to comment.