Skip to content

Revert "fix(radio): clicks not landing correctly in some cases on Chrome (#18357)" #18820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/material/radio/BUILD.bazel
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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