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

Commit 1d7a2e6

Browse files
authored
feat(button): Add support for increased touch target to button. (#4948)
1 parent b2e0fea commit 1d7a2e6

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

packages/mdc-button/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,25 @@ Disabled buttons cannot be interacted with and have no visual interaction effect
137137
</button>
138138
```
139139

140+
## Additional Information
141+
142+
### Accessibility
143+
144+
Material Design spec advises that touch targets should be at least 48 x 48 px.
145+
To meet this requirement, add the following to your button:
146+
147+
```html
148+
<span>
149+
<button class="mdc-button mdc-button--touch">
150+
<div class="mdc-button__ripple"></div>
151+
<span class="mdc-button__label">My Accessible Button</span>
152+
<div class="mdc-button__touch"></div>
153+
</button>
154+
</span>
155+
```
156+
157+
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).
158+
140159
## Style Customization
141160

142161
### CSS Classes

packages/mdc-button/_mixins.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
@import "@material/rtl/mixins";
2828
@import "@material/theme/functions";
2929
@import "@material/theme/mixins";
30+
@import "@material/touch-target/mixins";
3031
@import "@material/typography/mixins";
3132
@import "@material/shape/mixins";
3233
@import "@material/shape/functions";
@@ -61,6 +62,10 @@ $mdc-button-ripple-target: ".mdc-button__ripple";
6162
}
6263
}
6364

65+
.mdc-button__touch {
66+
@include mdc-touch-target($query);
67+
}
68+
6469
@include mdc-button-ink-color(primary, $query);
6570
}
6671

@@ -116,6 +121,11 @@ $mdc-button-ripple-target: ".mdc-button__ripple";
116121
@include mdc-button--dense_;
117122
}
118123
}
124+
125+
.mdc-button--touch {
126+
@include mdc-touch-target-component(
127+
$component-height: $mdc-button-height, $query: $query);
128+
}
119129
// postcss-bem-linter: end
120130
}
121131

packages/mdc-touch-target/_mixins.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
@import "@material/feature-targeting/mixins";
2525
@import "./variables";
2626

27-
/** Styles applied to the component's inner touch target element. */
27+
// Styles applied to the component's inner touch target element.
2828
@mixin mdc-touch-target($query: mdc-feature-all()) {
2929
$feat-structure: mdc-feature-create-target($query, structure);
3030

@@ -38,7 +38,7 @@
3838
}
3939
}
4040

41-
/** Styles applied to the component with the increased touch target. */
41+
// Styles applied to the component with the increased touch target.
4242
@mixin mdc-touch-target-component($component-height, $query: mdc-feature-all()) {
4343
$feat-structure: mdc-feature-create-target($query, structure);
4444

0 commit comments

Comments
 (0)