Skip to content

Commit

Permalink
Revert "fix(radio): clicks not landing correctly in some cases on Chr…
Browse files Browse the repository at this point in the history
…ome (angular#18357)" (angular#18820)

This reverts commit fe29835.
  • Loading branch information
andrewseguin committed Mar 13, 2020
1 parent bcb36c2 commit b5b3c8a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 25 deletions.
1 change: 0 additions & 1 deletion src/material/radio/BUILD.bazel
Expand Up @@ -55,7 +55,6 @@ ng_test_library(
),
deps = [
":radio",
"//src/cdk/a11y",
"//src/cdk/testing/private",
"@npm//@angular/forms",
"@npm//@angular/platform-browser",
Expand Down
18 changes: 1 addition & 17 deletions src/material/radio/radio.spec.ts
@@ -1,9 +1,8 @@
import {async, ComponentFixture, fakeAsync, TestBed, tick, inject} from '@angular/core/testing';
import {async, ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
import {FormControl, FormsModule, NgModel, ReactiveFormsModule} from '@angular/forms';
import {Component, DebugElement, ViewChild} from '@angular/core';
import {By} from '@angular/platform-browser';
import {dispatchFakeEvent} from '@angular/cdk/testing/private';
import {FocusMonitor} from '@angular/cdk/a11y';

import {MAT_RADIO_DEFAULT_OPTIONS} from './radio';
import {MatRadioButton, MatRadioChange, MatRadioGroup, MatRadioModule} from './index';
Expand Down Expand Up @@ -396,21 +395,6 @@ describe('MatRadio', () => {
.every(element => element.classList.contains('mat-focus-indicator'))).toBe(true);
});

it('should not manually move focus to underlying input when focus comes from mouse or touch',
inject([FocusMonitor], (focusMonitor: FocusMonitor) => {
const radioElement = radioNativeElements[0];
const inputElement = radioInputElements[0];
expect(document.activeElement).not.toBe(inputElement);

focusMonitor.focusVia(radioElement, 'mouse');
fixture.detectChanges();
expect(document.activeElement).not.toBe(inputElement);

focusMonitor.focusVia(radioElement, 'touch');
fixture.detectChanges();
expect(document.activeElement).not.toBe(inputElement);
}));

});

describe('group with ngModel', () => {
Expand Down
12 changes: 5 additions & 7 deletions src/material/radio/radio.ts
Expand Up @@ -351,6 +351,10 @@ const _MatRadioButtonMixinBase:
'[attr.aria-label]': 'null',
'[attr.aria-labelledby]': 'null',
'[attr.aria-describedby]': 'null',
// Note: under normal conditions focus shouldn't land on this element, however it may be
// programmatically set, for example inside of a focus trap, in this case we want to forward
// the focus to the native element.
'(focus)': '_inputElement.nativeElement.focus()',
},
changeDetection: ChangeDetectionStrategy.OnPush,
})
Expand Down Expand Up @@ -536,13 +540,7 @@ export class MatRadioButton extends _MatRadioButtonMixinBase
this._focusMonitor
.monitor(this._elementRef, true)
.subscribe(focusOrigin => {
// Only forward focus manually when it was received programmatically or through the
// keyboard. We should not do this for mouse/touch focus for two reasons:
// 1. It can prevent clicks from landing in Chrome (see #18269).
// 2. They're already handled by the wrapping `label` element.
if (focusOrigin === 'keyboard' || focusOrigin === 'program') {
this._inputElement.nativeElement.focus();
} else if (!focusOrigin && this.radioGroup) {
if (!focusOrigin && this.radioGroup) {
this.radioGroup._touch();
}
});
Expand Down

0 comments on commit b5b3c8a

Please sign in to comment.