Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit 7fd16cb

Browse files
authored
feat(button): Add touch target (#2066)
closes #2061
1 parent aabb65f commit 7fd16cb

File tree

11 files changed

+51
-9
lines changed

11 files changed

+51
-9
lines changed

demos/src/app/app-routing.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const DEMO_DECLARATIONS = [
1212
const routes: Routes = [
1313
{
1414
path: 'button-demo', loadChildren: () =>
15-
import('./components/button-demo/button.module').then(m => m.ButtonModule)
15+
import('./components/button/module').then(m => m.ButtonModule)
1616
},
1717
{path: 'card-demo', loadChildren: () => import('./components/card-demo/card.module').then(m => m.CardModule)},
1818
{

demos/src/app/components/button-demo/api.html renamed to demos/src/app/components/button/api.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ <h4 mdcSubtitle2>Properties</h4>
2626
</tr>
2727
<tr>
2828
<td>outlined: boolean</td>
29-
<td>A contained button that is flush with the surface and has a visible border.</td>
29+
<td>A contained button that is flush with the surface and has a visible
30+
border.</td>
3031
</tr>
3132
<tr>
3233
<td>disabled: boolean</td>
@@ -36,6 +37,10 @@ <h4 mdcSubtitle2>Properties</h4>
3637
<td>label: string</td>
3738
<td>Indicates the element containing the button's text label.</td>
3839
</tr>
40+
<tr>
41+
<td>touch: boolean</td>
42+
<td>Set the component touch target to 48 x 48 px.</td>
43+
</tr>
3944
</tbody>
4045
</table>
4146

@@ -52,10 +57,11 @@ <h4 mdcSubtitle2>Methods</h4>
5257

5358
<div class="docs-api">
5459
<h3 mdcHeadline6>MdcButtonLabel</h3>
60+
Optional. Required for the trailing icon to be styled appropriately.
5561
<p>
5662
Selector:
5763
<span class="markdown-code">mdc-button-label</span>
5864
<span class="markdown-code">[mdcButtonLabel]</span>
5965
</p>
6066
Exported as: <span class="markdown-code">mdcButtonLabel</span>
61-
</div>
67+
</div>

demos/src/app/components/button-demo/button-demo.ts renamed to demos/src/app/components/button/button.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class Sass {}
1111
@Component({
1212
template: '<component-viewer></component-viewer>'
1313
})
14-
export class ButtonDemo implements OnInit {
14+
export class Button implements OnInit {
1515
@ViewChild(ComponentViewer, {static: true}) _componentViewer: ComponentViewer;
1616

1717
ngOnInit(): void {
@@ -136,4 +136,10 @@ export class Examples {
136136
</button>`,
137137
sass: `https://raw.githubusercontent.com/trimox/angular-mdc-web/master/demos/src/styles/_button.scss`
138138
};
139+
140+
exampleAccessibility = {
141+
html: `<div class="mdc-touch-target-wrapper">
142+
<button mdc-button touch>My Accessible Button</button>
143+
</div>`
144+
};
139145
}

demos/src/app/components/button-demo/examples.html renamed to demos/src/app/components/button/examples.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,22 @@ <h3 class="demo-content__headline">Trailing icon</h3>
158158
</div>
159159
</div>
160160
<example-viewer [example]="trailingIconExample"></example-viewer>
161+
</div>
162+
163+
<div class="demo-content">
164+
<h3 class="demo-content__headline">Accessibility</h3>
165+
<p>
166+
Material Design spec advises that touch targets should be at least 48 x 48
167+
px. To meet this requirement, add the `touch` property.
168+
</p>
169+
<p>
170+
Note that the outer mdc-touch-target-wrapper element is only necessary if
171+
you want to avoid potentially overlapping touch targets on adjacent elements
172+
(due to collapsing margins). </p>
173+
<div class="demo-layout__row">
174+
<div class="mdc-touch-target-wrapper">
175+
<button mdc-button touch>My Accessible Button</button>
176+
</div>
177+
</div>
178+
<example-viewer [example]="exampleAccessibility"></example-viewer>
161179
</div>

demos/src/app/components/button-demo/routing.module.ts renamed to demos/src/app/components/button/routing.module.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import {NgModule} from '@angular/core';
22
import {Routes, RouterModule} from '@angular/router';
33

4-
import {Api, Examples, Sass, ButtonDemo} from './button-demo';
4+
import {Api, Examples, Sass, Button} from './button';
55

66
export const ROUTE_DECLARATIONS = [
77
Api,
88
Examples,
99
Sass,
10-
ButtonDemo
10+
Button
1111
];
1212

1313
const ROUTES: Routes = [
1414
{
15-
path: '', component: ButtonDemo,
15+
path: '', component: Button,
1616
children: [
1717
{path: '', redirectTo: 'api'},
1818
{path: 'api', component: Api},

demos/src/app/shared/example-viewer/example-viewer.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<mdc-list-divider class="example-divider"></mdc-list-divider>
22
<button mdc-button raised class="example-opener" *ngIf="!open"
33
(click)="open = !open" [label]="label">
4-
<mdc-icon>code</mdc-icon>
54
</button>
65
<mdc-tab-bar fixed [focusOnActivate]="false" *ngIf="open"
76
(activated)="onActivatedTab($event)">

demos/src/app/shared/example-viewer/example-viewer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class ExampleViewer implements OnInit {
5353
}
5454

5555
isUrl(url: string): boolean {
56-
const regExp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
56+
const regExp = /(https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
5757
return regExp.test(url);
5858
}
5959

packages/button/button.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ export class MdcButtonLabel {}
3030
'[class.mdc-button--raised]': 'raised',
3131
'[class.mdc-button--unelevated]': 'unelevated',
3232
'[class.mdc-button--outlined]': 'outlined',
33+
'[class.mdc-button--touch]': 'touch',
3334
'(click)': 'onClick($event)'
3435
},
3536
template: `
3637
<div class="mdc-button__ripple"></div>
3738
<mdc-button-label *ngIf="label">{{label}}</mdc-button-label>
39+
<div class="mdc-button__touch" *ngIf="touch"></div>
3840
<ng-content></ng-content>
3941
`,
4042
providers: [MdcRipple],
@@ -69,6 +71,15 @@ export class MdcButton implements OnInit, OnDestroy {
6971
}
7072
private _outlined: boolean = false;
7173

74+
@Input()
75+
get touch(): boolean {
76+
return this._touch;
77+
}
78+
set touch(value: boolean) {
79+
this._touch = coerceBooleanProperty(value);
80+
}
81+
private _touch: boolean = false;
82+
7283
@Input()
7384
get disabled(): boolean {
7485
return this._disabled;

0 commit comments

Comments
 (0)