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

Commit 6aa109d

Browse files
authored
feat(chips): Add support for increased touch target to chips. (#4970)
* feat(chips): Add support for increased touch target to chips. * feat(chips): Add support for increased touch target to chips.
1 parent 8e7fd7d commit 6aa109d

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

packages/mdc-chips/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,27 @@ To pre-select filter chips that have a leading icon, also add the class `mdc-chi
249249
</div>
250250
```
251251

252+
## Additional Information
253+
254+
### Accessibility
255+
256+
Material Design spec advises that touch targets should be at least 48 x 48 px.
257+
To meet this requirement, add the following to your chip:
258+
259+
```html
260+
<span>
261+
<button class="mdc-chip mdc-chip--touch">
262+
<div class="mdc-chip__ripple"></div>
263+
<span role="gridcell">
264+
<span role="button" tabindex="0" class="mdc-chip__text">Chip One</span>
265+
</span>
266+
<div class="mdc-chip__touch"></div>
267+
</button>
268+
</span>
269+
```
270+
271+
Note that the wrapper `<span>` element is only necessary if you want to avoid potentially overlapping touch targets on adjacent elements (due to collapsing margins).
272+
252273
## Style Customization
253274

254275
### CSS Classes

packages/mdc-chips/_mixins.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
@import "@material/rtl/mixins";
3232
@import "@material/theme/functions";
3333
@import "@material/theme/mixins";
34+
@import "@material/touch-target/mixins";
3435
@import "@material/typography/mixins";
3536
@import "@material/shape/mixins";
3637
@import "@material/shape/functions";
@@ -84,6 +85,10 @@ $mdc-chip-ripple-target: ".mdc-chip__ripple";
8485
@include mdc-theme-prop(color, on-surface);
8586
}
8687
}
88+
89+
.mdc-chip__touch {
90+
@include mdc-touch-target($query);
91+
}
8792
}
8893

8994
.mdc-chip--exit {
@@ -489,6 +494,11 @@ $mdc-chip-ripple-target: ".mdc-chip__ripple";
489494
margin: $gap-size / 2;
490495
}
491496
}
497+
498+
.mdc-chip--touch {
499+
@include mdc-touch-target-component(
500+
$component-height: $mdc-chip-height-default, $query: $query);
501+
}
492502
}
493503

494504
@mixin mdc-chip-leading-icon-color($color, $opacity: $mdc-chip-icon-opacity, $query: mdc-feature-all()) {

packages/mdc-touch-target/_mixins.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@
4242
@mixin mdc-touch-target-component($component-height, $query: mdc-feature-all()) {
4343
$feat-structure: mdc-feature-create-target($query, structure);
4444

45+
$vertical-margin-value: ($mdc-touch-target-height - $component-height) / 2;
46+
4547
@include mdc-feature-targets($feat-structure) {
46-
margin: ($mdc-touch-target-height - $component-height) / 2 0;
48+
margin-top: $vertical-margin-value;
49+
margin-bottom: $vertical-margin-value;
4750
}
4851
}

0 commit comments

Comments
 (0)