Skip to content

Commit bffbee4

Browse files
Becky Conningperrygovier
Becky Conning
authored andcommitted
feat(tabs): Allow disabled tab items
1 parent ef512b8 commit bffbee4

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

Diff for: js/angular/directive/tab.js

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
* @param {expression=} on-select Called when this tab is selected.
3333
* @param {expression=} on-deselect Called when this tab is deselected.
3434
* @param {expression=} ng-click By default, the tab will be selected on click. If ngClick is set, it will not. You can explicitly switch tabs using {@link ionic.service:$ionicTabsDelegate#select $ionicTabsDelegate.select()}.
35+
* @param {expression=} hidden Whether the tab is to be hidden or not.
36+
* @param {expression=} disabled Whether the tab is to be disabled or not.
3537
*/
3638
IonicModule
3739
.directive('ionTab', [
@@ -64,6 +66,7 @@ function($compile, $ionicConfig, $ionicBind, $ionicViewSwitcher) {
6466
attrStr('badge', attr.badge) +
6567
attrStr('badge-style', attr.badgeStyle) +
6668
attrStr('hidden', attr.hidden) +
69+
attrStr('disabled', attr.disabled) +
6770
attrStr('class', attr['class']) +
6871
'></ion-tab-nav>';
6972

Diff for: js/angular/directive/tabNav.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ IonicModule
66
require: ['^ionTabs', '^ionTab'],
77
template:
88
'<a ng-class="{\'tab-item-active\': isTabActive(), \'has-badge\':badge, \'tab-hidden\':isHidden()}" ' +
9-
' class="tab-item">' +
9+
' ng-disabled="disabled()" class="tab-item">' +
1010
'<span class="badge {{badgeStyle}}" ng-if="badge">{{badge}}</span>' +
1111
'<i class="icon {{getIconOn()}}" ng-if="getIconOn() && isTabActive()"></i>' +
1212
'<i class="icon {{getIconOff()}}" ng-if="getIconOff() && !isTabActive()"></i>' +
@@ -19,6 +19,7 @@ IonicModule
1919
iconOff: '@',
2020
badge: '=',
2121
hidden: '@',
22+
disabled: '&',
2223
badgeStyle: '@',
2324
'class': '@'
2425
},

Diff for: test/unit/angular/directive/tabs.unit.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -387,15 +387,16 @@ describe('tabs', function() {
387387
});
388388

389389
it('should compile a <ion-tab-nav> with all of the relevant attrs', function() {
390-
setup('title="{{a}}" icon-on="{{b}}" icon-off="{{c}}" badge="d" badge-style="{{e}}" class="{{f}}" ng-click="click" hidden="{{g}}"');
390+
setup('title="{{a}}" icon-on="{{b}}" icon-off="{{c}}" badge="d" badge-style="{{e}}" class="{{f}}" ng-click="click" hidden="{{g}}" disabled="h"');
391391
angular.extend(tabEl.scope(), {
392392
a: 'title',
393393
b: 'on',
394394
c: 'off',
395395
d: 6,
396396
e: 'badger',
397397
f: 'someClass',
398-
g: true
398+
g: true,
399+
h: true
399400
});
400401
tabEl.scope().$apply();
401402
var navItem = angular.element(tabsEl[0].querySelector('.tab-item'));
@@ -407,6 +408,7 @@ describe('tabs', function() {
407408
expect(navItem[0].className).toMatch(/someClass/);
408409
expect(navItem.attr('ng-click')).toEqual('click');
409410
expect(navItem.isolateScope().hidden).toEqual('true');
411+
expect(navItem.isolateScope().disabled()).toEqual(true);
410412

411413
angular.extend(tabEl.scope(), {
412414
a: 'title2',
@@ -415,7 +417,8 @@ describe('tabs', function() {
415417
d: 7,
416418
e: 'badger2',
417419
f: 'someClass2',
418-
g: false
420+
g: false,
421+
h: false
419422
});
420423
tabEl.scope().$apply();
421424
expect(navItem.isolateScope().title).toEqual('title2');
@@ -425,6 +428,7 @@ describe('tabs', function() {
425428
expect(navItem.isolateScope().badgeStyle).toEqual('badger2');
426429
expect(navItem[0].className).toMatch(/someClass2/);
427430
expect(navItem.isolateScope().hidden).toEqual('false');
431+
expect(navItem.isolateScope().disabled()).toEqual(false);
428432

429433
expect(navItem.parent()[0]).toBe(tabsCtrl.$tabsElement[0]);
430434
});

0 commit comments

Comments
 (0)