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

Commit 0c4d8f3

Browse files
authored
feat(fab): Add support for increased touch target to mini FAB. (#5231)
1 parent 0861b84 commit 0c4d8f3

File tree

5 files changed

+56
-8
lines changed

5 files changed

+56
-8
lines changed

packages/mdc-button/_mixins.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ $mdc-button-ripple-target: ".mdc-button__ripple";
7272
}
7373

7474
.mdc-button__touch {
75-
@include mdc-touch-target($query);
75+
@include mdc-touch-target($query: $query);
7676
}
7777

7878
@include mdc-button-ink-color(primary, $query);

packages/mdc-chips/_mixins.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ $mdc-chip-ripple-target: ".mdc-chip__ripple";
8989
}
9090

9191
.mdc-chip__touch {
92-
@include mdc-touch-target($query);
92+
@include mdc-touch-target($query: $query);
9393
}
9494
}
9595

packages/mdc-fab/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,24 @@ In browsers that fully support CSS custom properties, the above mixins will work
143143

144144
### Additional Information
145145

146+
#### Accessibility
147+
148+
Material Design spec advises that touch targets should be at least 48x48px.
149+
While the FAB is 48x48px by default, the mini FAB is 40x40px. Add the following to meet this requirement for mini FAB's:
150+
151+
```html
152+
<div class="mdc-touch-target-wrapper">
153+
<button class="mdc-fab mdc-fab--mini mdc-fab--touch">
154+
<div class="mdc-fab__ripple"></div>
155+
<span class="material-icons mdc-fab__icon">add</span>
156+
<span class="mdc-fab__label">Create</span>
157+
<div class="mdc-fab__touch"></div>
158+
</button>
159+
</div>
160+
```
161+
162+
Note that the outer `mdc-touch-target-wrapper` element is only necessary if you want to avoid potentially overlapping touch targets on adjacent elements (due to collapsing margins).
163+
146164
#### Positioning
147165

148166
Developers must position MDC FAB as needed within their application's design.

packages/mdc-fab/_mixins.scss

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@
2525
@import "@material/feature-targeting/mixins";
2626
@import "@material/ripple/mixins";
2727
@import "@material/ripple/variables";
28-
@import "@material/theme/functions";
29-
@import "@material/theme/mixins";
28+
@import "@material/rtl/mixins";
3029
@import "@material/shape/mixins";
3130
@import "@material/shape/functions";
32-
@import "@material/rtl/mixins";
31+
@import "@material/theme/functions";
32+
@import "@material/theme/mixins";
33+
@import "@material/touch-target/mixins";
3334
@import "@material/typography/mixins";
3435
@import "./variables";
3536

@@ -43,6 +44,8 @@ $mdc-fab-ripple-target: ".mdc-fab__ripple";
4344
@mixin mdc-fab-without-ripple($query: mdc-feature-all()) {
4445
// postcss-bem-linter: define fab
4546

47+
@include mdc-touch-target-wrapper($query);
48+
4649
.mdc-fab {
4750
@include mdc-fab-base_($query: $query);
4851
@include mdc-fab-container-color(secondary, $query: $query);
@@ -58,6 +61,17 @@ $mdc-fab-ripple-target: ".mdc-fab__ripple";
5861
@include mdc-fab--extended_($query: $query);
5962
}
6063

64+
.mdc-fab--touch {
65+
@include mdc-touch-target-component(
66+
$component-height: $mdc-fab-mini-height,
67+
$component-width: $mdc-fab-mini-height,
68+
$query: $query);
69+
70+
.mdc-fab__touch {
71+
@include mdc-touch-target($set-width: true, $query: $query);
72+
}
73+
}
74+
6175
.mdc-fab__label {
6276
@include mdc-fab--label_($query: $query);
6377
}

packages/mdc-touch-target/_mixins.scss

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,32 @@
4343
}
4444

4545
/// Styles applied to the component's inner touch target element.
46-
@mixin mdc-touch-target($query: mdc-feature-all()) {
46+
/// By default, only sets the inner element height to the minimum touch target
47+
/// height ($mdc-touch-target-height).
48+
/// @param {Boolean} $set-width [false] - Sets the inner element width to the
49+
/// minimum touch target width ($mdc-touch-target-width).
50+
@mixin mdc-touch-target($set-width: false, $query: mdc-feature-all()) {
4751
$feat-structure: mdc-feature-create-target($query, structure);
4852

4953
@include mdc-feature-targets($feat-structure) {
5054
position: absolute;
5155
top: 50%;
5256
right: 0;
53-
left: 0;
5457
height: $mdc-touch-target-height;
55-
transform: translateY(-50%);
58+
}
59+
60+
@if $set-width {
61+
@include mdc-feature-targets($feat-structure) {
62+
/* @noflip */
63+
left: 50%;
64+
width: $mdc-touch-target-width;
65+
transform: translate(-50%, -50%);
66+
}
67+
} @else {
68+
@include mdc-feature-targets($feat-structure) {
69+
left: 0;
70+
transform: translateY(-50%);
71+
}
5672
}
5773
}
5874

0 commit comments

Comments
 (0)