From 1570fbbe5cbc35518ed1f7807eb7e4451767eee9 Mon Sep 17 00:00:00 2001 From: tinayuangao Date: Mon, 31 Jul 2017 11:10:37 -0700 Subject: [PATCH] a11y(checkbox): Add checkbox accessibility demo page (#5921) * use real world examples for checkbox * Checkbox a11y demo * remove pseudo checkbox * address comments --- src/demo-app/a11y/a11y-module.ts | 2 + src/demo-app/a11y/button/button-a11y.html | 58 +++++++++---------- src/demo-app/a11y/checkbox/checkbox-a11y.html | 36 +++++++++++- src/demo-app/a11y/checkbox/checkbox-a11y.scss | 3 + src/demo-app/a11y/checkbox/checkbox-a11y.ts | 46 ++++++++++++++- 5 files changed, 113 insertions(+), 32 deletions(-) diff --git a/src/demo-app/a11y/a11y-module.ts b/src/demo-app/a11y/a11y-module.ts index b3b2ae84f72..dd07589c06b 100644 --- a/src/demo-app/a11y/a11y-module.ts +++ b/src/demo-app/a11y/a11y-module.ts @@ -26,6 +26,8 @@ export class AccessibilityRoutingModule {} ReactiveFormsModule, AccessibilityRoutingModule, DemoMaterialModule, + FormsModule, + ReactiveFormsModule, ], declarations: [ AccessibilityDemo, diff --git a/src/demo-app/a11y/button/button-a11y.html b/src/demo-app/a11y/button/button-a11y.html index 2650b1c38ab..8167528a18c 100644 --- a/src/demo-app/a11y/button/button-a11y.html +++ b/src/demo-app/a11y/button/button-a11y.html @@ -1,31 +1,29 @@ -
-
-

Button elements

- - - - - -
+
+

Button elements

+ + + + + +
-
-

Anchor elements

- Google search - Google search - - check - - - check - - - check - -
-
+
+

Anchor elements

+ Google search + Google search + + check + + + check + + + check + +
diff --git a/src/demo-app/a11y/checkbox/checkbox-a11y.html b/src/demo-app/a11y/checkbox/checkbox-a11y.html index d5b8931fa9b..458c201bb40 100644 --- a/src/demo-app/a11y/checkbox/checkbox-a11y.html +++ b/src/demo-app/a11y/checkbox/checkbox-a11y.html @@ -1 +1,35 @@ -Checkbox Placeholder \ No newline at end of file +
+

Checkbox without label

+ +
+
+

Standalone checkbox

+
+ Yes, I agree to the terms and conditions +
+
+ No, I do not agree to the terms and conditions +
+
+ A partially done task +
+
+ +
+

Nested checklist

+
+ + {{task.name}} + +
+
+ + {{subtask.name}} + +
+
+
+
diff --git a/src/demo-app/a11y/checkbox/checkbox-a11y.scss b/src/demo-app/a11y/checkbox/checkbox-a11y.scss index e69de29bb2d..174586cfab6 100644 --- a/src/demo-app/a11y/checkbox/checkbox-a11y.scss +++ b/src/demo-app/a11y/checkbox/checkbox-a11y.scss @@ -0,0 +1,3 @@ +.sub-list { + margin-left: 20px; +} diff --git a/src/demo-app/a11y/checkbox/checkbox-a11y.ts b/src/demo-app/a11y/checkbox/checkbox-a11y.ts index b860479e1cd..b401f065a98 100644 --- a/src/demo-app/a11y/checkbox/checkbox-a11y.ts +++ b/src/demo-app/a11y/checkbox/checkbox-a11y.ts @@ -1,5 +1,10 @@ import {Component} from '@angular/core'; +export interface Task { + name: string; + completed: boolean; + subtasks?: Task[]; +} @Component({ moduleId: module.id, @@ -8,5 +13,44 @@ import {Component} from '@angular/core'; styleUrls: ['checkbox-a11y.css'], }) export class CheckboxAccessibilityDemo { - // TODO(tinayuangao): Add use cases + + 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 { + let subtasks = task.subtasks; + + if (!subtasks) { + return false; + } + + return subtasks.every(t => t.completed); + } + + someComplete(tasks: Task[]): boolean { + const numComplete = tasks.filter(t => t.completed).length; + return numComplete > 0 && numComplete < tasks.length; + } + + setAllCompleted(tasks: Task[], completed: boolean) { + tasks.forEach(t => t.completed = completed); + } }