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

Commit 6053007

Browse files
authored
feat(checkbox): Add touch target (#2067)
closes #2062
1 parent 7fd16cb commit 6053007

File tree

10 files changed

+90
-55
lines changed

10 files changed

+90
-55
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const routes: Routes = [
1717
{path: 'card-demo', loadChildren: () => import('./components/card-demo/card.module').then(m => m.CardModule)},
1818
{
1919
path: 'checkbox-demo', loadChildren: () =>
20-
import('./components/checkbox-demo/checkbox.module').then(m => m.CheckboxModule)
20+
import('./components/checkbox/module').then(m => m.CheckboxModule)
2121
},
2222
{
2323
path: 'chips-demo', loadChildren: () =>

demos/src/app/components/checkbox-demo/routing.module.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ <h4 mdcSubtitle2>Properties</h4>
5959
<td>indeterminateToChecked: boolean</td>
6060
<td>Whether the checkbox should go to checked state or unchecked when toggled from indeterminate state.</td>
6161
</tr>
62+
<tr>
63+
<td>touch: boolean</td>
64+
<td>Set the component touch target to 48 x 48 px.</td>
65+
</tr>
6266
</tbody>
6367
</table>
6468

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

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class Api {}
1111
export class Sass {}
1212

1313
@Component({template: '<component-viewer></component-viewer>'})
14-
export class CheckboxDemo implements OnInit {
14+
export class Checkbox implements OnInit {
1515
@ViewChild(ComponentViewer, {static: true}) _componentViewer: ComponentViewer;
1616

1717
ngOnInit(): void {
@@ -103,23 +103,15 @@ toggle(cb: MdcCheckbox): void {
103103
<mdc-checkbox class="demo-checkbox--custom-stroke-and-fill"></mdc-checkbox>
104104
<label>Custom Stroke and Fill</label>
105105
</mdc-form-field>`,
106-
sass: `.demo-checkbox--custom-all {
107-
$color: $material-color-red-500;
108-
109-
@include mdc-checkbox-focus-indicator-color($color);
110-
@include mdc-states($color);
111-
@include mdc-checkbox-container-colors(
112-
$unmarked-stroke-color: $color,
113-
$unmarked-fill-color: rgba($color, .25),
114-
$marked-fill-color: $color,
115-
$generate-keyframes: false);
116-
}
106+
sass: `https://raw.githubusercontent.com/trimox/angular-mdc-web/master/demos/src/styles/_checkbox.scss`
107+
};
117108

118-
.demo-checkbox--custom-stroke-and-fill {
119-
@include mdc-checkbox-container-colors(
120-
$unmarked-stroke-color: $material-color-blue-500,
121-
$marked-fill-color: $material-color-purple-500,
122-
$generate-keyframes: false);
123-
}`
109+
exampleAccessibility = {
110+
html: `<div class="mdc-touch-target-wrapper">
111+
<mdc-form-field>
112+
<mdc-checkbox touch></mdc-checkbox>
113+
<label>My Accessible Checkbox</label>
114+
</mdc-form-field>
115+
</div>`
124116
};
125117
}

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

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,20 @@
4141
<button mdc-button (click)="toggle(cb)">Toggle</button>
4242
</div>
4343
<div class="demo-layout__row">
44-
<button mdc-button (click)="cb.indeterminateToChecked = !cb.indeterminateToChecked">
45-
Indeterminate To Checked: {{cb.indeterminateToChecked ? 'On' : 'Off'}}</button>
44+
<button mdc-button
45+
(click)="cb.indeterminateToChecked = !cb.indeterminateToChecked">
46+
Indeterminate To Checked:
47+
{{cb.indeterminateToChecked ? 'On' : 'Off'}}</button>
4648
<button mdc-button (click)="formField.alignEnd = !formField.alignEnd">RTL: {{formField.alignEnd ? 'On'
4749
: 'Off'}}</button>
48-
<button mdc-button (click)="cb.disabled = !cb.disabled">Disabled: {{cb.disabled ? 'On' : 'Off'}}</button>
49-
<button mdc-button (click)="cb.disableRipple = !cb.disableRipple">Ripple: {{!cb.disableRipple ? 'On' : 'Off'}}</button>
50+
<button mdc-button (click)="cb.disabled = !cb.disabled">Disabled:
51+
{{cb.disabled ? 'On' : 'Off'}}</button>
52+
<button mdc-button (click)="cb.disableRipple = !cb.disableRipple">Ripple:
53+
{{!cb.disableRipple ? 'On' : 'Off'}}</button>
5054
</div>
5155
<mdc-form-field #formField>
52-
<mdc-checkbox #cb indeterminateToChecked (change)="onChange($event)"></mdc-checkbox>
56+
<mdc-checkbox #cb indeterminateToChecked (change)="onChange($event)">
57+
</mdc-checkbox>
5358
<label>Checkbox value is {{cb.checked}}</label>
5459
</mdc-form-field>
5560

@@ -68,10 +73,32 @@ <h3 class="demo-content__headline">Theme</h3>
6873

6974
<div class="demo-container">
7075
<mdc-form-field>
71-
<mdc-checkbox class="demo-checkbox--custom-stroke-and-fill"></mdc-checkbox>
76+
<mdc-checkbox class="demo-checkbox--custom-stroke-and-fill">
77+
</mdc-checkbox>
7278
<label>Custom Stroke and Fill</label>
7379
</mdc-form-field>
7480
</div>
7581
</div>
7682
<example-viewer [example]="exampleTheme"></example-viewer>
83+
</div>
84+
85+
<div class="demo-content">
86+
<h3 class="demo-content__headline">Accessibility</h3>
87+
<p>
88+
Material Design spec advises that touch targets should be at least 48 x 48
89+
px. To meet this requirement, add the `touch` property.
90+
</p>
91+
<p>
92+
Note that the outer mdc-touch-target-wrapper element is only necessary if
93+
you want to avoid potentially overlapping touch targets on adjacent elements
94+
(due to collapsing margins). </p>
95+
<div class="demo-layout__row">
96+
<div class="mdc-touch-target-wrapper">
97+
<mdc-form-field>
98+
<mdc-checkbox touch></mdc-checkbox>
99+
<label>My Accessible Checkbox</label>
100+
</mdc-form-field>
101+
</div>
102+
</div>
103+
<example-viewer [example]="exampleAccessibility"></example-viewer>
77104
</div>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {NgModule} from '@angular/core';
2+
import {Routes, RouterModule} from '@angular/router';
3+
4+
import {Api, Examples, Sass, Checkbox} from './checkbox';
5+
6+
export const ROUTE_DECLARATIONS = [
7+
Api,
8+
Examples,
9+
Sass,
10+
Checkbox
11+
];
12+
13+
const ROUTES: Routes = [
14+
{
15+
path: '', component: Checkbox,
16+
children: [
17+
{path: '', redirectTo: 'api'},
18+
{path: 'api', component: Api},
19+
{path: 'sass', component: Sass},
20+
{path: 'examples', component: Examples}
21+
]
22+
}
23+
];
24+
25+
@NgModule({
26+
imports: [RouterModule.forChild(ROUTES)],
27+
exports: [RouterModule]
28+
})
29+
export class RoutingModule {}

packages/checkbox/checkbox.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ export const MDC_CHECKBOX_CONTROL_VALUE_ACCESSOR: any = {
5656
exportAs: 'mdcCheckbox',
5757
host: {
5858
'[id]': 'id',
59-
'class': 'mdc-checkbox'
59+
'class': 'mdc-checkbox',
60+
'[class.mdc-checkbox--touch]': 'touch',
6061
},
6162
template: `
6263
<input type="checkbox"
@@ -125,6 +126,15 @@ export class MdcCheckbox extends MDCComponent<MDCCheckboxFoundation> implements
125126
}
126127
private _checked: boolean = false;
127128

129+
@Input()
130+
get touch(): boolean {
131+
return this._touch;
132+
}
133+
set touch(value: boolean) {
134+
this._touch = coerceBooleanProperty(value);
135+
}
136+
private _touch: boolean = false;
137+
128138
@Input()
129139
get disabled(): boolean {
130140
return this._disabled;

test/checkbox/checkbox.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ describe('MdcCheckbox', () => {
334334
[id]="checkboxId"
335335
[(ngModel)]="checkboxValue"
336336
[checked]="checkboxValue"
337+
[touch]="touch"
337338
[indeterminateToChecked]="indeterminateToChecked"
338339
[indeterminate]="indeterminate"
339340
[disableRipple]="disableRipple"
@@ -348,6 +349,7 @@ class SingleCheckbox {
348349
checkboxValue: boolean = false;
349350
indeterminateToChecked: boolean = true;
350351
disableRipple: boolean = false;
352+
touch: boolean = false;
351353
}
352354

353355
/** Simple test component with an aria-label set. */

0 commit comments

Comments
 (0)