From 19f47b5dcbf3006fbc14a08d909bc0265058dfe0 Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 26 Jan 2015 14:41:43 -0800 Subject: [PATCH] fix(switch): set tabindex to -1 while disabled --- src/components/switch/switch.js | 6 ++++++ src/components/switch/switch.spec.js | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/components/switch/switch.js b/src/components/switch/switch.js index 2c52429cf88..906ac0b14fc 100644 --- a/src/components/switch/switch.js +++ b/src/components/switch/switch.js @@ -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 diff --git a/src/components/switch/switch.spec.js b/src/components/switch/switch.spec.js index 0062ecb0e2d..f382f8aa810 100644 --- a/src/components/switch/switch.spec.js +++ b/src/components/switch/switch.spec.js @@ -36,4 +36,15 @@ describe('', 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('')($rootScope); + + $rootScope.$apply(); + expect(el.attr('tabindex')).not.toEqual('-1'); + + $rootScope.$apply('value = true'); + expect(el.attr('tabindex')).toEqual('-1'); + })); + });