Skip to content

Commit 4ff346b

Browse files
authored
fix(material/radio): hide empty labels (#32754)
We have similar logic in the checkbox and slide toggle so these changes apply it to the radio button: hiding the label when it's empty so it doesn't affect the layout.
1 parent 70f8b6a commit 4ff346b

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/material/form-field/_mdc-text-field-structure-overrides.scss

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,7 @@
33
@use '../core/style/vendor-prefixes';
44

55
$fallbacks: m3-form-field.get-tokens();
6-
7-
// TODO(b/263527625): should be removed when this is addressed on the MDC side.
8-
// MDC sets a will-change on this element, because of the animation. This can cause
9-
// scrolling performance degradation on pages with a lot of form fields so we reset it.
10-
// The animation is on a `transform` which is hardware-accelerated already.
11-
// This flag is used to re-add the `will-change` internally since removing it causes a
12-
// lot of screenshot diffs.
13-
$_enable-form-field-will-change-reset: true;
6+
$_is-external-build: true;
147

158
// Mixin that can be included to override the default MDC text-field
169
// styles to fit our needs. See individual comments for context on why
@@ -45,7 +38,13 @@ $_enable-form-field-will-change-reset: true;
4538
// clicking the label to focus the input.
4639
pointer-events: all;
4740

48-
@if ($_enable-form-field-will-change-reset) {
41+
// TODO(b/263527625): should be removed when this is addressed on the MDC side.
42+
// MDC sets a will-change on this element, because of the animation. This can cause
43+
// scrolling performance degradation on pages with a lot of form fields so we reset it.
44+
// The animation is on a `transform` which is hardware-accelerated already.
45+
// This flag is used to re-add the `will-change` internally since removing it causes a
46+
// lot of screenshot diffs.
47+
@if ($_is-external-build) {
4948
will-change: auto;
5049
}
5150
}
@@ -81,7 +80,8 @@ $_enable-form-field-will-change-reset: true;
8180
height: auto;
8281
flex: auto;
8382

84-
@if ($_enable-form-field-will-change-reset) {
83+
// TODO(b/263527625): should be removed when this is addressed on the MDC side.
84+
@if ($_is-external-build) {
8585
will-change: auto;
8686
}
8787
}

src/material/radio/radio.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
@use './radio-common';
55

66
$fallbacks: m3-radio.get-tokens();
7+
$_is-external-build: true;
78

89
.mat-mdc-radio-button {
910
-webkit-tap-highlight-color: transparent;
@@ -15,6 +16,14 @@ $fallbacks: m3-radio.get-tokens();
1516
// user of this. Therefore we add the pointer cursor on top of MDC's styles.
1617
label {
1718
cursor: pointer;
19+
20+
// TODO(crisbeto): disable internally due to a large amount of breakages.
21+
// Prevent the label from taking up space when it's empty.
22+
@if ($_is-external-build) {
23+
&:empty {
24+
display: none;
25+
}
26+
}
1827
}
1928

2029
.mdc-radio__background::before {

0 commit comments

Comments
 (0)