-
Notifications
You must be signed in to change notification settings - Fork 6.7k
/
checkbox-a11y.ts
67 lines (58 loc) · 1.6 KB
/
checkbox-a11y.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {Component} from '@angular/core';
export interface Task {
name: string;
completed: boolean;
subtasks?: Task[];
}
@Component({
moduleId: module.id,
selector: 'checkbox-a11y',
templateUrl: 'checkbox-a11y.html',
styleUrls: ['checkbox-a11y.css'],
})
export class CheckboxAccessibilityDemo {
tasks: Task[] = [
{
name: 'Reminders',
completed: false,
subtasks: [
{name: 'Cook Dinner', completed: false},
{name: 'Read the Material Design Spec', completed: false},
{name: 'Upgrade Application to Angular', completed: false}
]
},
{
name: 'Groceries',
completed: false,
subtasks: [
{name: 'Organic Eggs', completed: false},
{name: 'Protein Powder', completed: false},
{name: 'Almond Meal Flour', completed: false}
]
}
];
allComplete(task: Task): boolean {
const subtasks = task.subtasks;
return task.completed || (subtasks != null && subtasks.every(t => t.completed));
}
someComplete(tasks: Task[] | undefined | null): boolean {
if (tasks == null) {
return false;
}
const numComplete = tasks.filter(t => t.completed).length;
return numComplete > 0 && numComplete < tasks.length;
}
setAllCompleted(tasks: Task[] | undefined | null, completed: boolean): void {
if (tasks == null) {
return;
}
tasks.forEach(t => t.completed = completed);
}
}