Skip to content

Commit e7799b8

Browse files
authored
fix(touch-target): Add class to touch target wrapper. (material-components#5174)
1 parent 5dc45b8 commit e7799b8

File tree

12 files changed

+73
-17
lines changed

12 files changed

+73
-17
lines changed

packages/mdc-button/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,16 @@ Material Design spec advises that touch targets should be at least 48 x 48 px.
145145
To meet this requirement, add the following to your button:
146146

147147
```html
148-
<span>
148+
<div class="mdc-touch-target-wrapper">
149149
<button class="mdc-button mdc-button--touch">
150150
<div class="mdc-button__ripple"></div>
151151
<span class="mdc-button__label">My Accessible Button</span>
152152
<div class="mdc-button__touch"></div>
153153
</button>
154-
</span>
154+
</div>
155155
```
156156

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).
157+
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).
158158

159159
## Style Customization
160160

packages/mdc-button/_mixins.scss

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ $mdc-button-ripple-target: ".mdc-button__ripple";
5353
$feat-color: mdc-feature-create-target($query, color);
5454
$feat-structure: mdc-feature-create-target($query, structure);
5555

56+
@include mdc-touch-target-wrapper($query);
57+
5658
// postcss-bem-linter: define button
5759
.mdc-button {
5860
@include mdc-button-base_($query);

packages/mdc-checkbox/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Material Design spec advises that touch targets should be at least 48 x 48 px.
119119
To meet this requirement, add the `mdc-checkbox--touch` class to your checkbox as follows:
120120

121121
```html
122-
<span>
122+
<div class="mdc-touch-target-wrapper">
123123
<div class="mdc-checkbox mdc-checkbox--touch">
124124
<input type="checkbox"
125125
class="mdc-checkbox__native-control"
@@ -135,10 +135,10 @@ To meet this requirement, add the `mdc-checkbox--touch` class to your checkbox a
135135
</div>
136136
<div class="mdc-checkbox__ripple"></div>
137137
</div>
138-
</span>
138+
</div>
139139
```
140140

141-
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).
141+
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).
142142

143143
## Style Customization
144144

packages/mdc-checkbox/_mixins.scss

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ $mdc-checkbox-ripple-target: ".mdc-checkbox__ripple";
5050
$feat-color: mdc-feature-create-target($query, color);
5151
$feat-structure: mdc-feature-create-target($query, structure);
5252

53+
@include mdc-touch-target-wrapper($query);
54+
5355
@include mdc-feature-targets($feat-animation) {
5456
@include mdc-checkbox-mark-keyframes_;
5557
}

packages/mdc-chips/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -257,18 +257,18 @@ Material Design spec advises that touch targets should be at least 48 x 48 px.
257257
To meet this requirement, add the following to your chip:
258258

259259
```html
260-
<span>
260+
<div class="mdc-touch-target-wrapper">
261261
<button class="mdc-chip mdc-chip--touch">
262262
<div class="mdc-chip__ripple"></div>
263263
<span role="gridcell">
264264
<span role="button" tabindex="0" class="mdc-chip__text">Chip One</span>
265265
</span>
266266
<div class="mdc-chip__touch"></div>
267267
</button>
268-
</span>
268+
</div>
269269
```
270270

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).
271+
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).
272272

273273
## Style Customization
274274

packages/mdc-chips/_mixins.scss

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ $mdc-chip-ripple-target: ".mdc-chip__ripple";
5555
@include mdc-chip-leading-icon-size($mdc-chip-leading-icon-size, $query: $query);
5656
@include mdc-chip-trailing-icon-size($mdc-chip-trailing-icon-size, $query: $query);
5757
@include mdc-chip-trailing-icon-margin($query: $query);
58+
@include mdc-touch-target-wrapper($query);
5859

5960
.mdc-chip {
6061
@include mdc-chip-shape-radius(50%, $query: $query);

packages/mdc-radio/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Material Design spec advises that touch targets should be at least 48 x 48 px.
105105
To meet this requirement, add the `mdc-radio--touch` class to your radio as follows:
106106

107107
```html
108-
<span>
108+
<div class="mdc-touch-target-wrapper">
109109
<div class="mdc-radio mdc-radio--touch">
110110
<input class="mdc-radio__native-control" type="radio" id="radio-1" name="radios" checked>
111111
<div class="mdc-radio__background">
@@ -114,10 +114,10 @@ To meet this requirement, add the `mdc-radio--touch` class to your radio as foll
114114
</div>
115115
<div class="mdc-radio__ripple"></div>
116116
</div>
117-
</span>
117+
</div>
118118
```
119119

120-
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).
120+
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).
121121

122122
## Style Customization
123123

packages/mdc-radio/_mixins.scss

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ $mdc-radio-ripple-target: ".mdc-radio__ripple";
4949
$feat-color: mdc-feature-create-target($query, color);
5050
$feat-structure: mdc-feature-create-target($query, structure);
5151

52+
@include mdc-touch-target-wrapper($query);
53+
5254
.mdc-radio {
5355
@include mdc-radio-unchecked-stroke-color($mdc-radio-unchecked-color, $query);
5456
@include mdc-radio-checked-stroke-color($mdc-radio-baseline-theme-color, $query);

packages/mdc-touch-target/README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ For a given button component:
4949
You would add an increased touch target as follows:
5050

5151
```html
52-
<span>
52+
<div class="mdc-touch-target-wrapper>
5353
<button class="mdc-button mdc-button--touch">
5454
<div class="mdc-button__ripple"></div>
5555
<span class="mdc-button__label">My Accessible Button</span>
5656
<div class="mdc-button__touch"></div>
5757
</button>
58-
</span>
58+
</div>
5959
```
6060
61-
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).
61+
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).
6262
6363
### Styles
6464
@@ -72,5 +72,6 @@ Note that the wrapper `<span>` element is only necessary if you want to avoid po
7272
7373
Mixin | Description
7474
--- | ---
75+
`mdc-touch-target-wrapper` | Applied to the wrapper touch target element.
7576
`mdc-touch-target` | Applied to the inner touch target element.
7677
`mdc-touch-target-component` | Applied to the component root element. Adds margin to compensate for the increased touch target.

packages/mdc-touch-target/_mixins.scss

+20-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,29 @@
2020
// THE SOFTWARE.
2121
//
2222

23+
@import "@material/base/mixins";
2324
@import "@material/feature-targeting/functions";
2425
@import "@material/feature-targeting/mixins";
2526
@import "./variables";
2627

27-
// Styles applied to the component's inner touch target element.
28+
/// Styles applied to the component's touch target wrapper element.
29+
@mixin mdc-touch-target-wrapper($query: mdc-feature-all()) {
30+
$feat-structure: mdc-feature-create-target($query, structure);
31+
32+
.mdc-touch-target-wrapper {
33+
@include mdc-feature-targets($feat-structure) {
34+
// Ensure that styles are only emitted once across all components that
35+
// have increased touch targets.
36+
@include mdc-base-emit-once("mdc-touch-target/wrapper") {
37+
// NOTE: Will change to `inline-block` in the future, but keeping as is
38+
// temporarily for backwards-compatibility.
39+
display: inline;
40+
}
41+
}
42+
}
43+
}
44+
45+
/// Styles applied to the component's inner touch target element.
2846
@mixin mdc-touch-target($query: mdc-feature-all()) {
2947
$feat-structure: mdc-feature-create-target($query, structure);
3048

@@ -38,7 +56,7 @@
3856
}
3957
}
4058

41-
// Styles applied to the component with the increased touch target.
59+
/// Styles applied to the component with the increased touch target.
4260
@mixin mdc-touch-target-component($component-height, $component-width: null, $query: mdc-feature-all()) {
4361
$feat-structure: mdc-feature-create-target($query, structure);
4462

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// Copyright 2019 Google Inc.
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
//
22+
23+
@import "./mixins";
24+
@include mdc-touch-target-wrapper;

test/scss/_feature-targeting-test.scss

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
@import "@material/tab-indicator/mixins";
2626
@import "@material/tab/mixins";
2727
@import "@material/theme/mixins";
28+
@import "@material/touch-target/mixins";
2829
@import "@material/typography/mixins";
2930
@import "@material/data-table/mixins";
3031

@@ -304,6 +305,11 @@
304305
// Theme
305306
@include mdc-theme-core-styles($query: $query);
306307

308+
// Touch Target
309+
@include mdc-touch-target-wrapper($query: $query);
310+
@include mdc-touch-target($query: $query);
311+
@include mdc-touch-target-component(0, $query: $query);
312+
307313
// Typography
308314
@include mdc-typography-core-styles($query: $query);
309315
@include mdc-typography-base($query: $query);

0 commit comments

Comments
 (0)