Skip to content

Commit 340c9c4

Browse files
dfreedmcopybara-github
authored andcommitted
Track Checkbox focus state
- Also add z-index theming for ripple PiperOrigin-RevId: 318565070
1 parent 155c2f8 commit 340c9c4

File tree

5 files changed

+39
-0
lines changed

5 files changed

+39
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3333
- Add `reducedTouchTarget` param to `mwc-checkbox` to control touchscreen accessibility.
3434
- Typeahead on `mwc-select`
3535
- Added `focusItemAtIndex(index)` and `getFocusedItemIndex` to both `list` and `menu`
36+
- Add `--m-ripple-z-index` to control ripple z-index.
3637

3738
### Changed
3839

packages/checkbox/src/mwc-checkbox-base.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ export class CheckboxBase extends FormElement {
4343

4444
@internalProperty() protected shouldRenderRipple = false;
4545

46+
@internalProperty() protected focused = false;
47+
4648
@queryAsync('mwc-ripple') ripple!: Promise<Ripple|null>;
4749

4850
// MDC Foundation is unused
@@ -114,6 +116,7 @@ export class CheckboxBase extends FormElement {
114116
'mdc-checkbox--disabled': this.disabled,
115117
'mdc-checkbox--selected': selected,
116118
'mdc-checkbox--touch': !this.reducedTouchTarget,
119+
'mdc-checkbox--focused': this.focused,
117120
// transition animiation classes
118121
'mdc-checkbox--anim-checked-indeterminate':
119122
this.animationClass == 'checked-indeterminate',
@@ -165,10 +168,12 @@ export class CheckboxBase extends FormElement {
165168
}
166169

167170
private _handleFocus() {
171+
this.focused = true;
168172
this.rippleHandlers.startFocus();
169173
}
170174

171175
private _handleBlur() {
176+
this.focused = false;
172177
this.rippleHandlers.endFocus();
173178
}
174179

packages/checkbox/src/mwc-checkbox.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@ limitations under the License.
5353
varname: --mdc-checkbox-unchecked-color,
5454
fallback: checkbox.$border-color
5555
),
56+
$marked-stroke-color: (
57+
varname: --m-checkbox-checked-color,
58+
fallback: (
59+
varname: --mdc-theme-secondary,
60+
fallback: theme.prop-value(checkbox.$baseline-theme-color)
61+
)
62+
),
63+
$marked-fill-color: (
64+
varname: --m-checkbox-checked-color,
65+
fallback: (
66+
varname: --mdc-theme-secondary,
67+
fallback: theme.prop-value(checkbox.$baseline-theme-color)
68+
)
69+
),
5670
);
5771
@include checkbox.ink-color((
5872
varname: --mdc-checkbox-mark-color,

packages/ripple/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,4 @@ Name | Type | Default | Description
9191
| `--mdc-ripple-focus-opacity` | `0.12` | Opacity of the ripple when focused.
9292
| `--mdc-ripple-selected-opacity` | `0.08` | Opacity of the ripple when the host component is "selected". This opacity is added to `press`, `hover`, and `focus` states.
9393
| `--mdc-ripple-activated-opacity` | `0.12` | Opacity of the ripple when the host component is "activated". This opacity is added to `press`, `hover`, and `focus` states.
94+
| `--m-ripple-z-index` | `0` | Z-index of the ripple.

packages/ripple/src/mwc-ripple.scss

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ limitations under the License.
1818
@use 'sass:map';
1919
@use '@material/ripple';
2020
@use '@material/theme';
21+
@use '@material/theme/custom-properties';
2122

2223
@include ripple.common();
2324

@@ -122,5 +123,22 @@ limitations under the License.
122123
&.disabled {
123124
--mdc-ripple-color: transparent;
124125
}
126+
127+
&::before {
128+
@include theme.property(
129+
z-index,
130+
custom-properties.create(--m-ripple-z-index, 1),
131+
(alternate: true)
132+
);
133+
134+
}
135+
136+
&::after {
137+
@include theme.property(
138+
z-index,
139+
custom-properties.create(--m-ripple-z-index, 0),
140+
(alternate: true)
141+
);
142+
}
125143
}
126144

0 commit comments

Comments
 (0)