From f31dd9a396dd720074b5328497bdb014d05a629d Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Sat, 25 Jul 2026 09:20:49 +0200 Subject: [PATCH] fix(material/checkbox): avoid making the touch target a focus stop Along the same lines as #33558. 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 checkbox 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/checkbox/index.api.md | 3 -- src/material/checkbox/checkbox.html | 39 ++++++++++++-------------- src/material/checkbox/checkbox.scss | 5 +++- src/material/checkbox/checkbox.ts | 15 +--------- 4 files changed, 23 insertions(+), 39 deletions(-) diff --git a/goldens/material/checkbox/index.api.md b/goldens/material/checkbox/index.api.md index 9e72c1808591..4eb98f892047 100644 --- a/goldens/material/checkbox/index.api.md +++ b/goldens/material/checkbox/index.api.md @@ -63,7 +63,6 @@ export class MatCheckbox implements AfterViewInit, OnChanges, ControlValueAccess get inputId(): string; // (undocumented) _isRippleDisabled(): boolean; - _labelElement: ElementRef; labelPosition: 'before' | 'after'; name: string | null; // (undocumented) @@ -94,8 +93,6 @@ export class MatCheckbox implements AfterViewInit, OnChanges, ControlValueAccess _onInteractionEvent(event: Event): void; _onLabelTextChange(): void; _onTouched: () => any; - // (undocumented) - _onTouchTargetClick(): void; _preventBubblingFromLabel(event: MouseEvent): void; // (undocumented) registerOnChange(fn: (value: any) => void): void; diff --git a/src/material/checkbox/checkbox.html b/src/material/checkbox/checkbox.html index a5101aa584c8..e32a8240523f 100644 --- a/src/material/checkbox/checkbox.html +++ b/src/material/checkbox/checkbox.html @@ -1,10 +1,11 @@ -
-
+
- - -
+ + diff --git a/src/material/checkbox/checkbox.scss b/src/material/checkbox/checkbox.scss index c07c0b111e55..0bf883c03ad2 100644 --- a/src/material/checkbox/checkbox.scss +++ b/src/material/checkbox/checkbox.scss @@ -44,6 +44,9 @@ $fallbacks: m3-checkbox.get-tokens(); label { cursor: default; + } + + .mat-internal-form-field-label { color: token-utils.slot(checkbox-disabled-label-color, $fallbacks); @include cdk.high-contrast { @@ -54,7 +57,7 @@ $fallbacks: m3-checkbox.get-tokens(); // The MDC styles result in extra padding if the label is present but empty. To fix this we hide // the label when it is empty. - label:empty { + .mat-internal-form-field-label:empty { display: none; } diff --git a/src/material/checkbox/checkbox.ts b/src/material/checkbox/checkbox.ts index f009b4bc8ef8..103390066fb3 100644 --- a/src/material/checkbox/checkbox.ts +++ b/src/material/checkbox/checkbox.ts @@ -205,9 +205,6 @@ export class MatCheckbox /** The native `` element */ @ViewChild('input') _inputElement!: ElementRef; - /** The native `