Skip to content
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