From d5c3e0dd1b2f78fbde2d42d74df487ca8504bc68 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Mon, 20 Jul 2026 17:41:01 +0200 Subject: [PATCH] fix(material/radio): avoid making the touch target a focus stop Some screen readers detect which elements have `click` listeners and make them a focus stop, even if they're `aria-hidden`. These changes rework the radio button so it doesn't have to rely on a `click` listener on the touch target by wrapping the `input` in the `label` instead. --- goldens/material/core/index.api.md | 2 +- goldens/material/radio/index.api.md | 1 - .../internal-form-field.scss | 12 ++++--- .../internal-form-field.ts | 3 +- src/material/radio/radio.html | 31 +++++++++---------- src/material/radio/radio.scss | 15 ++++----- src/material/radio/radio.ts | 11 ------- 7 files changed, 30 insertions(+), 45 deletions(-) diff --git a/goldens/material/core/index.api.md b/goldens/material/core/index.api.md index 6a1b9cd40528..a5bd1221c626 100644 --- a/goldens/material/core/index.api.md +++ b/goldens/material/core/index.api.md @@ -162,7 +162,7 @@ export const MATERIAL_ANIMATIONS: InjectionToken; export class _MatInternalFormField { labelPosition: 'before' | 'after'; // (undocumented) - static ɵcmp: i0.ɵɵComponentDeclaration<_MatInternalFormField, "div[mat-internal-form-field]", never, { "labelPosition": { "alias": "labelPosition"; "required": true; }; }, {}, never, ["*"], true, never>; + static ɵcmp: i0.ɵɵComponentDeclaration<_MatInternalFormField, "[mat-internal-form-field]", never, { "labelPosition": { "alias": "labelPosition"; "required": true; }; }, {}, never, ["*"], true, never>; // (undocumented) static ɵfac: i0.ɵɵFactoryDeclaration<_MatInternalFormField, never>; } diff --git a/goldens/material/radio/index.api.md b/goldens/material/radio/index.api.md index c3f04b0c930b..8e9933b6f6cc 100644 --- a/goldens/material/radio/index.api.md +++ b/goldens/material/radio/index.api.md @@ -77,7 +77,6 @@ export class MatRadioButton implements OnInit, AfterViewInit, DoCheck, OnDestroy ngOnInit(): void; _noopAnimations: boolean; _onInputInteraction(event: Event): void; - _onTouchTargetClick(event: Event): void; radioGroup: MatRadioGroup; get required(): boolean; set required(value: boolean); diff --git a/src/material/core/internal-form-field/internal-form-field.scss b/src/material/core/internal-form-field/internal-form-field.scss index fb2191d05b34..d46f1d1b1348 100644 --- a/src/material/core/internal-form-field/internal-form-field.scss +++ b/src/material/core/internal-form-field/internal-form-field.scss @@ -6,7 +6,8 @@ align-items: center; vertical-align: middle; - & > label { + & > label, + & > .mat-internal-form-field-label { margin-left: 0; margin-right: auto; padding-left: 4px; @@ -14,7 +15,8 @@ order: 0; } - [dir='rtl'] & > label { + [dir='rtl'] & > label, + [dir='rtl'] & > .mat-internal-form-field-label { margin-left: auto; margin-right: 0; padding-left: 0; @@ -23,7 +25,8 @@ } .mdc-form-field--align-end { - & > label { + & > label, + & > .mat-internal-form-field-label { margin-left: auto; margin-right: 0; padding-left: 0; @@ -31,7 +34,8 @@ order: -1; } - [dir='rtl'] .mdc-form-field--align-end & label { + [dir='rtl'] .mdc-form-field--align-end & label, + [dir='rtl'] .mdc-form-field--align-end & .mat-internal-form-field-label { margin-left: 0; margin-right: auto; padding-left: 4px; diff --git a/src/material/core/internal-form-field/internal-form-field.ts b/src/material/core/internal-form-field/internal-form-field.ts index 5442c4f80ae2..db494457d6e1 100644 --- a/src/material/core/internal-form-field/internal-form-field.ts +++ b/src/material/core/internal-form-field/internal-form-field.ts @@ -14,8 +14,7 @@ import {Component, Input, ViewEncapsulation} from '@angular/core'; * @docs-private */ @Component({ - // Use a `div` selector to match the old markup closer. - selector: 'div[mat-internal-form-field]', + selector: '[mat-internal-form-field]', template: '', styleUrl: 'internal-form-field.css', encapsulation: ViewEncapsulation.None, diff --git a/src/material/radio/radio.html b/src/material/radio/radio.html index 6067b2022e0f..f7546b17e11e 100644 --- a/src/material/radio/radio.html +++ b/src/material/radio/radio.html @@ -1,10 +1,7 @@ -
-
+