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

Commit

Permalink
fix(switch): set tabindex to -1 while disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
ajoslin committed Jan 26, 2015
1 parent f592f21 commit 19f47b5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/components/switch/switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ function MdSwitch(mdCheckboxDirective, $mdTheming, $mdUtil, $document, $mdConsta

checkboxLink(scope, element, attr, ngModel);

if (angular.isDefined(attr.ngDisabled)) {
scope.$watch(disabledGetter, function(isDisabled) {
element.attr('tabindex', isDisabled ? -1 : 0);
});
}

// These events are triggered by setup drag
$mdGesture.register(switchContainer, 'drag');
switchContainer
Expand Down
11 changes: 11 additions & 0 deletions src/components/switch/switch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,15 @@ describe('<md-switch>', function() {
expect(switches.eq(1).attr('role')).toEqual('checkbox');
}));

it('should have tabindex -1 while disabled', inject(function($rootScope, $compile) {
$rootScope.value = false;
var el = $compile('<md-switch ng-disabled="$root.value">')($rootScope);

$rootScope.$apply();
expect(el.attr('tabindex')).not.toEqual('-1');

$rootScope.$apply('value = true');
expect(el.attr('tabindex')).toEqual('-1');
}));

});

0 comments on commit 19f47b5

Please sign in to comment.