Skip to content

Commit 1159022

Browse files
committed
fix(radio): not checked on first click if partially visible
Currently the native `input` inside the radio button is collapsed down to 1px by 1px and moved to the bottom of the element which causes browsers to scroll the window down, rather than change the value, on the first click when the input is partially hidden. These changes fix the issue by having the input cover the entire button and hiding it with `opacity`. From my testing, using `opacity` versus `cdk-visually-hidden` doesn't make a difference for screen readers. Fixes #19397.
1 parent 8008218 commit 1159022

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/material/radio/radio.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<div class="mat-radio-container">
66
<div class="mat-radio-outer-circle"></div>
77
<div class="mat-radio-inner-circle"></div>
8-
<input #input class="mat-radio-input cdk-visually-hidden" type="radio"
8+
<input #input class="mat-radio-input" type="radio"
99
[id]="inputId"
1010
[checked]="checked"
1111
[disabled]="disabled"

src/material/radio/radio.scss

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,14 @@ $mat-radio-ripple-radius: 20px;
177177
}
178178

179179
.mat-radio-input {
180-
// Move the input in the middle and towards the bottom so
181-
// the native validation messages are aligned correctly.
182-
bottom: 0;
183-
left: 50%;
180+
opacity: 0;
181+
position: absolute;
182+
top: 0;
183+
left: 0;
184+
margin: 0;
185+
width: 100%;
186+
height: 100%;
187+
cursor: inherit;
184188
}
185189

186190
@include cdk-high-contrast(active, off) {

0 commit comments

Comments
 (0)