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

Commit f790e93

Browse files
devversionThomasBurleson
authored andcommitted
fix(checkbox): pointer events disable ripple events too
We should not disable the ripple events by using `pointer-events: none`. IE11 always focuses the div, instead of the `md-checkbox`, and that's causing issues with ngModel etc. * redirect the focus, instead of preventing the whole focus / pointer events. * @see https://connect.microsoft.com/IE/feedback/details/1028411/ Fixes #7538. Closes #7541.
1 parent 822267b commit f790e93

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

src/components/checkbox/checkbox.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ function MdCheckboxDirective(inputDirective, $mdAria, $mdConstant, $mdTheming, $
6868
// **********************************************************
6969

7070
function compile (tElement, tAttrs) {
71+
var container = tElement.children();
7172

7273
tAttrs.type = 'checkbox';
7374
tAttrs.tabindex = tAttrs.tabindex || '0';
@@ -81,6 +82,12 @@ function MdCheckboxDirective(inputDirective, $mdAria, $mdConstant, $mdTheming, $
8182
}
8283
});
8384

85+
// Redirect focus events to the root element, because IE11 is always focusing the container element instead
86+
// of the md-checkbox element. This causes issues when using ngModelOptions: `updateOnBlur`
87+
container.on('focus', function() {
88+
tElement.focus();
89+
});
90+
8491
return function postLink(scope, element, attr, ngModelCtrl) {
8592
ngModelCtrl = ngModelCtrl || $mdUtil.fakeNgModel();
8693
$mdTheming(element);

src/components/checkbox/checkbox.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ md-checkbox {
5858
height: $checkbox-height;
5959
@include rtl(left, 0, auto);
6060
@include rtl(right, auto, 0);
61-
62-
// Disable pointer events, because IE11 is always focusing the child elements instead of the
63-
// md-checkbox element.
64-
pointer-events: none;
6561

6662
&:before {
6763
box-sizing: border-box;

src/components/checkbox/checkbox.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,25 @@ describe('mdCheckbox', function() {
136136
expect(checkbox[0]).not.toHaveClass('md-focused');
137137
});
138138

139+
it('should redirect focus of container to the checkbox element', function() {
140+
var checkbox = compileAndLink('<md-checkbox ng-model="blue"></md-checkbox>');
141+
142+
document.body.appendChild(checkbox[0]);
143+
144+
var container = checkbox.children().eq(0);
145+
expect(container[0]).toHaveClass('md-container');
146+
147+
// We simulate IE11's focus bug, which always focuses an unfocusable div
148+
// https://connect.microsoft.com/IE/feedback/details/1028411/
149+
container[0].tabIndex = -1;
150+
151+
container.triggerHandler('focus');
152+
153+
expect(document.activeElement).toBe(checkbox[0]);
154+
155+
checkbox.remove();
156+
});
157+
139158
it('should set focus state on keyboard interaction after clicking', function() {
140159
var checkbox = compileAndLink('<md-checkbox ng-model="blue"></md-checkbox>');
141160

0 commit comments

Comments
 (0)