Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit b5c6d66

Browse files
authored
feat(radio): Add disabled state color mixins (#5168)
1 parent 01628ef commit b5c6d66

File tree

5 files changed

+175
-45
lines changed

5 files changed

+175
-45
lines changed

packages/mdc-radio/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,12 @@ MDC Radio uses [MDC Theme](../mdc-theme)'s `secondary` color by default. Use the
127127

128128
Mixin | Description
129129
--- | ---
130-
`mdc-radio-unchecked-stroke-color($color)` | Sets the stroke color of an unchecked radio button
131-
`mdc-radio-checked-stroke-color($color)` | Sets the stroke color of a checked radio button
132-
`mdc-radio-ink-color($color)` | Sets the ink color of a radio button
130+
`mdc-radio-unchecked-stroke-color($color)` | Sets the stroke color of an unchecked, enabled radio button
131+
`mdc-radio-checked-stroke-color($color)` | Sets the stroke color of a checked, enabled radio button
132+
`mdc-radio-ink-color($color)` | Sets the ink color of an enabled radio button
133+
`mdc-radio-disabled-unchecked-stroke-color($color)` | Sets the stroke color of an unchecked, disabled radio button
134+
`mdc-radio-disabled-checked-stroke-color($color)` | Sets the stroke color of a checked, disabled radio button
135+
`mdc-radio-disabled-ink-color($color)` | Sets the ink color of a disabled radio button
133136
`mdc-radio-focus-indicator-color($color)` | Sets the color of the focus indicator
134137
`mdc-radio-touch-target($size, $ripple-size)` | Sets radio touch target size which can be more than the ripple size. Param `$ripple-size` is required for custom ripple size, defaults to `$mdc-radio-ripple-size`.
135138
`mdc-radio-ripple-size($size)` | Sets custom ripple size of radio.

packages/mdc-radio/_mixins.scss

Lines changed: 160 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,14 @@ $mdc-radio-ripple-target: ".mdc-radio__ripple";
5252
@include mdc-touch-target-wrapper($query);
5353

5454
.mdc-radio {
55-
@include mdc-radio-unchecked-stroke-color($mdc-radio-unchecked-color, $query);
56-
@include mdc-radio-checked-stroke-color($mdc-radio-baseline-theme-color, $query);
57-
@include mdc-radio-ink-color($mdc-radio-baseline-theme-color, $query);
58-
@include mdc-radio-focus-indicator-color($mdc-radio-baseline-theme-color, $query);
59-
@include mdc-radio-density($mdc-radio-density-scale, $query);
55+
@include mdc-radio-unchecked-stroke-color($mdc-radio-unchecked-color, $query: $query);
56+
@include mdc-radio-checked-stroke-color($mdc-radio-baseline-theme-color, $query: $query);
57+
@include mdc-radio-ink-color($mdc-radio-baseline-theme-color, $query: $query);
58+
@include mdc-radio-disabled-unchecked-stroke-color($mdc-radio-disabled-circle-color, $query: $query);
59+
@include mdc-radio-disabled-checked-stroke-color($mdc-radio-disabled-circle-color, $query: $query);
60+
@include mdc-radio-disabled-ink-color($mdc-radio-disabled-circle-color, $query: $query);
61+
@include mdc-radio-focus-indicator-color($mdc-radio-baseline-theme-color, $query: $query);
62+
@include mdc-radio-density($mdc-radio-density-scale, $query: $query);
6063

6164
@include mdc-feature-targets($feat-structure) {
6265
display: inline-block;
@@ -209,18 +212,6 @@ $mdc-radio-ripple-target: ".mdc-radio__ripple";
209212
@include mdc-feature-targets($feat-structure) {
210213
cursor: default;
211214
}
212-
213-
.mdc-radio__outer-circle {
214-
@include mdc-feature-targets($feat-color) {
215-
border-color: $mdc-radio-circle-color;
216-
}
217-
}
218-
219-
.mdc-radio__inner-circle {
220-
@include mdc-feature-targets($feat-color) {
221-
border-color: $mdc-radio-circle-color;
222-
}
223-
}
224215
}
225216
}
226217

@@ -269,36 +260,63 @@ $mdc-radio-ripple-target: ".mdc-radio__ripple";
269260
}
270261
}
271262

263+
///
264+
/// Sets the stroke color of an unchecked, enabled radio button.
265+
/// @param {Color} $color - The desired stroke color.
266+
///
272267
@mixin mdc-radio-unchecked-stroke-color($color, $query: mdc-feature-all()) {
273-
$feat-color: mdc-feature-create-target($query, color);
274-
275-
// stylelint-disable-next-line selector-max-specificity
276-
.mdc-radio__native-control:enabled:not(:checked) + .mdc-radio__background .mdc-radio__outer-circle {
277-
@include mdc-feature-targets($feat-color) {
278-
@include mdc-theme-prop(border-color, $color);
279-
}
268+
@include mdc-radio-if-enabled-unchecked_ {
269+
@include mdc-radio-stroke-color_($color, $query: $query);
280270
}
281271
}
282272

273+
///
274+
/// Sets the stroke color of a checked, enabled radio button.
275+
/// @param {Color} $color - The desired stroke color.
276+
///
283277
@mixin mdc-radio-checked-stroke-color($color, $query: mdc-feature-all()) {
284-
$feat-color: mdc-feature-create-target($query, color);
285-
286-
// stylelint-disable-next-line selector-max-specificity
287-
.mdc-radio__native-control:enabled:checked + .mdc-radio__background .mdc-radio__outer-circle {
288-
@include mdc-feature-targets($feat-color) {
289-
@include mdc-theme-prop(border-color, $color);
290-
}
278+
@include mdc-radio-if-enabled-checked_ {
279+
@include mdc-radio-stroke-color_($color, $query:$query);
291280
}
292281
}
293282

283+
///
284+
/// Sets the ink color of an enabled radio button.
285+
/// @param {Color} $color - The desired ink color.
286+
///
294287
@mixin mdc-radio-ink-color($color, $query: mdc-feature-all()) {
295-
$feat-color: mdc-feature-create-target($query, color);
288+
@include mdc-radio-if-enabled_ {
289+
@include mdc-radio-ink-color_($color, $query: $query);
290+
}
291+
}
296292

297-
// stylelint-disable-next-line selector-max-specificity
298-
.mdc-radio__native-control:enabled + .mdc-radio__background .mdc-radio__inner-circle {
299-
@include mdc-feature-targets($feat-color) {
300-
@include mdc-theme-prop(border-color, $color);
301-
}
293+
///
294+
/// Sets the stroke color of an unchecked, disabled radio button.
295+
/// @param {Color} $color - The desired stroke color.
296+
///
297+
@mixin mdc-radio-disabled-unchecked-stroke-color($color, $query: mdc-feature-all()) {
298+
@include mdc-radio-if-disabled-unchecked_ {
299+
@include mdc-radio-stroke-color_($color, $query: $query);
300+
}
301+
}
302+
303+
///
304+
/// Sets the stroke color of a checked, disabled radio button.
305+
/// @param {Color} $color - The desired stroke color.
306+
///
307+
@mixin mdc-radio-disabled-checked-stroke-color($color, $query: mdc-feature-all()) {
308+
@include mdc-radio-if-disabled-checked_ {
309+
@include mdc-radio-stroke-color_($color, $query: $query);
310+
}
311+
}
312+
313+
///
314+
/// Sets the ink color of a disabled radio button.
315+
/// @param {Color} $color - The desired ink color
316+
///
317+
@mixin mdc-radio-disabled-ink-color($color, $query: mdc-feature-all()) {
318+
@include mdc-radio-if-disabled_ {
319+
@include mdc-radio-ink-color_($color, $query: $query);
302320
}
303321
}
304322

@@ -395,3 +413,108 @@ $mdc-radio-ripple-target: ".mdc-radio__ripple";
395413
margin: 0;
396414
}
397415
}
416+
417+
///
418+
/// Helps select the radio background only when its native control is in the
419+
/// enabled state.
420+
/// @access private
421+
///
422+
@mixin mdc-radio-if-enabled_ {
423+
.mdc-radio__native-control:enabled + {
424+
@content;
425+
}
426+
}
427+
428+
///
429+
/// Helps select the radio background only when its native control is in the
430+
/// enabled & unchecked state.
431+
/// @access private
432+
///
433+
@mixin mdc-radio-if-enabled-unchecked_ {
434+
.mdc-radio__native-control:enabled:not(:checked) + {
435+
@content;
436+
}
437+
}
438+
439+
///
440+
/// Helps select the radio background only when its native control is in the
441+
/// enabled & checked state.
442+
/// @access private
443+
///
444+
@mixin mdc-radio-if-enabled-checked_ {
445+
.mdc-radio__native-control:enabled:checked + {
446+
@content;
447+
}
448+
}
449+
450+
///
451+
/// Helps select the radio background only when its native control is in the
452+
/// disabled state.
453+
/// @access private
454+
///
455+
@mixin mdc-radio-if-disabled_ {
456+
[aria-disabled="true"] .mdc-radio__native-control,
457+
.mdc-radio__native-control:disabled {
458+
+ {
459+
@content;
460+
}
461+
}
462+
}
463+
464+
///
465+
/// Helps select the radio background only when its native control is in the
466+
/// disabled & unchecked state.
467+
/// @access private
468+
///
469+
@mixin mdc-radio-if-disabled-unchecked_ {
470+
[aria-disabled="true"] .mdc-radio__native-control,
471+
.mdc-radio__native-control:disabled {
472+
&:not(:checked) + {
473+
@content;
474+
}
475+
}
476+
}
477+
478+
///
479+
/// Helps select the radio background only when its native control is in the
480+
/// disabled & checked state.
481+
/// @access private
482+
///
483+
@mixin mdc-radio-if-disabled-checked_ {
484+
[aria-disabled="true"] .mdc-radio__native-control,
485+
.mdc-radio__native-control:disabled {
486+
&:checked + {
487+
@content;
488+
}
489+
}
490+
}
491+
492+
///
493+
/// Sets the ink color for radio. This is wrapped in a mixin
494+
/// that qualifies state such as `mdc-radio-if-enabled_`
495+
/// @access private
496+
///
497+
@mixin mdc-radio-ink-color_($color, $query: mdc-feature-all()) {
498+
$feat-color: mdc-feature-create-target($query, color);
499+
500+
.mdc-radio__background .mdc-radio__inner-circle {
501+
@include mdc-feature-targets($feat-color) {
502+
@include mdc-theme-prop(border-color, $color);
503+
}
504+
}
505+
}
506+
507+
///
508+
/// Sets the stroke color for radio. This is wrapped in a mixin
509+
/// that qualifies state such as `mdc-radio-if-enabled_`
510+
/// @access private
511+
///
512+
@mixin mdc-radio-stroke-color_($color, $query: mdc-feature-all()) {
513+
$feat-color: mdc-feature-create-target($query, color);
514+
515+
.mdc-radio__background .mdc-radio__outer-circle {
516+
@include mdc-feature-targets($feat-color) {
517+
@include mdc-theme-prop(border-color, $color);
518+
}
519+
}
520+
}

packages/mdc-radio/_variables.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ $mdc-radio-transition-duration: 120ms !default;
2929
$mdc-radio-ripple-opacity: .14 !default;
3030
$mdc-radio-baseline-theme-color: secondary !default;
3131
$mdc-radio-unchecked-color: rgba(mdc-theme-prop-value(on-surface), .54) !default;
32-
$mdc-radio-circle-color: rgba(mdc-theme-prop-value(on-surface), .26) !default;
32+
$mdc-radio-disabled-circle-color: rgba(mdc-theme-prop-value(on-surface), .26) !default;
3333

3434
$mdc-radio-minimum-size: 28px !default;
3535
$mdc-radio-maximum-size: $mdc-radio-ripple-size !default;

test/screenshot/golden.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -960,11 +960,11 @@
960960
}
961961
},
962962
"spec/mdc-radio/mixins/mixins.html": {
963-
"public_url": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2019/09/20/22_06_30_583/spec/mdc-radio/mixins/mixins.html?utm_source=golden_json",
963+
"public_url": "https://storage.googleapis.com/mdc-web-screenshot-tests/allanchen/2019/10/10/22_20_16_416/spec/mdc-radio/mixins/mixins.html?utm_source=golden_json",
964964
"screenshots": {
965-
"desktop_windows_chrome@latest": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2019/09/20/22_06_30_583/spec/mdc-radio/mixins/mixins.html.windows_chrome_76.png",
966-
"desktop_windows_firefox@latest": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2019/09/20/22_06_30_583/spec/mdc-radio/mixins/mixins.html.windows_firefox_69.png",
967-
"desktop_windows_ie@11": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2019/09/20/22_06_30_583/spec/mdc-radio/mixins/mixins.html.windows_ie_11.png"
965+
"desktop_windows_chrome@latest": "https://storage.googleapis.com/mdc-web-screenshot-tests/allanchen/2019/10/10/22_20_16_416/spec/mdc-radio/mixins/mixins.html.windows_chrome_77.png",
966+
"desktop_windows_firefox@latest": "https://storage.googleapis.com/mdc-web-screenshot-tests/allanchen/2019/10/10/22_20_16_416/spec/mdc-radio/mixins/mixins.html.windows_firefox_69.png",
967+
"desktop_windows_ie@11": "https://storage.googleapis.com/mdc-web-screenshot-tests/allanchen/2019/10/10/22_20_16_416/spec/mdc-radio/mixins/mixins.html.windows_ie_11.png"
968968
}
969969
},
970970
"spec/mdc-rtl/variables/include.html": {

test/screenshot/spec/mdc-radio/fixture.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
@import "../mixins";
2626

2727
$custom-radio-color: $material-color-red-300;
28+
$custom-disabled-radio-color: rgba(purple, .4);
2829

2930
.test-cell--radio {
3031
@include test-cell-size(71, 91);
@@ -53,14 +54,17 @@ $custom-radio-color: $material-color-red-300;
5354

5455
.custom-radio--unchecked-stroke-color {
5556
@include mdc-radio-unchecked-stroke-color($custom-radio-color);
57+
@include mdc-radio-disabled-unchecked-stroke-color($custom-disabled-radio-color);
5658
}
5759

5860
.custom-radio--checked-stroke-color {
5961
@include mdc-radio-checked-stroke-color($custom-radio-color);
62+
@include mdc-radio-disabled-checked-stroke-color($custom-disabled-radio-color);
6063
}
6164

6265
.custom-radio--ink-color {
6366
@include mdc-radio-ink-color($custom-radio-color);
67+
@include mdc-radio-disabled-ink-color($custom-disabled-radio-color);
6468
}
6569

6670
.custom-radio-density {

0 commit comments

Comments
 (0)