From a3b3acf027a9adad0dfea1e671c9fb4c7bddd38a Mon Sep 17 00:00:00 2001 From: Raven Avalon Date: Thu, 2 Mar 2017 11:25:32 -0500 Subject: [PATCH] chore(accessibility): Add aria attributes to aid screen reader flow --- src/app/material-docs-app.ts | 29 +++++++++++- .../component-category-list.html | 21 ++++----- .../component-category-list.spec.ts | 7 +++ .../component-page-header.html | 2 +- .../component-sidenav/component-sidenav.html | 8 ++-- src/app/pages/guide-list/guide-list.html | 20 +++++---- src/app/pages/guide-list/guide-list.scss | 2 +- src/app/pages/guide-viewer/guide-viewer.html | 2 +- src/app/pages/homepage/homepage.html | 2 +- .../shared/example-viewer/example-viewer.html | 1 + .../focus-element/focus-element.spec.ts | 44 +++++++++++++++++++ src/app/shared/focus-element/focus-element.ts | 26 +++++++++++ src/app/shared/plunker/plunker-button.html | 1 + 13 files changed, 137 insertions(+), 28 deletions(-) create mode 100644 src/app/shared/focus-element/focus-element.spec.ts create mode 100644 src/app/shared/focus-element/focus-element.ts diff --git a/src/app/material-docs-app.ts b/src/app/material-docs-app.ts index 7596e28b0..84958c704 100644 --- a/src/app/material-docs-app.ts +++ b/src/app/material-docs-app.ts @@ -1,5 +1,6 @@ import {Component, ViewEncapsulation} from '@angular/core'; import {Router, NavigationStart} from '@angular/router'; +import {Title} from '@angular/platform-browser'; @Component({ @@ -10,8 +11,9 @@ import {Router, NavigationStart} from '@angular/router'; }) export class MaterialDocsApp { showShadow = false; + baseTitle = 'Angular Material'; - constructor(router: Router) { + constructor(router: Router, private _titleService: Title) { let previousRoute = router.routerState.snapshot.url; router.events.subscribe((data: NavigationStart) => { @@ -24,8 +26,33 @@ export class MaterialDocsApp { } previousRoute = data.url; + + // set page title + this._setTitle(window.location.pathname); }); } + + private _setTitle(pathname) { + const title = this._getTitle(pathname); + title ? + this._titleService.setTitle(`${this.baseTitle} - ${this._capitalizeTitle(title)}`) : + this._titleService.setTitle(this.baseTitle); + } + + private _getTitle(pathname) { + return pathname.split('/').filter(Boolean).pop(); + } + + private _trimFilename(filename) { + const isFilenameRegex = new RegExp(/.+\./g); + return ~filename.search(isFilenameRegex) ? + filename.match(isFilenameRegex)[0].replace('.', '') : + filename; + } + + private _capitalizeTitle(title) { + return title[0].toUpperCase() + this._trimFilename(title.slice(1)); + } } function isNavigationWithinComponentView(oldUrl: string, newUrl: string) { diff --git a/src/app/pages/component-category-list/component-category-list.html b/src/app/pages/component-category-list/component-category-list.html index 740f47926..3bb64bd82 100644 --- a/src/app/pages/component-category-list/component-category-list.html +++ b/src/app/pages/component-category-list/component-category-list.html @@ -1,12 +1,13 @@
- - {{category.name}} -

{{category.summary}}

- - -
+ + + {{category.name}} +

{{category.summary}}

+ + +
+
diff --git a/src/app/pages/component-category-list/component-category-list.spec.ts b/src/app/pages/component-category-list/component-category-list.spec.ts index f5d1e99ca..b7b227fa2 100644 --- a/src/app/pages/component-category-list/component-category-list.spec.ts +++ b/src/app/pages/component-category-list/component-category-list.spec.ts @@ -1,6 +1,12 @@ import {async, ComponentFixture, TestBed} from '@angular/core/testing'; +import {MaterialModule} from '@angular/material'; +import {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core'; +import {RouterTestingModule} from '@angular/router/testing'; + import {ComponentCategoryList, ComponentCategoryListModule} from './component-category-list'; import {DocsAppTestingModule} from '../../testing/testing-module'; +import {DocumentationItems} from '../../shared/documentation-items/documentation-items'; +import {ComponentPageTitle} from '../page-title/page-title'; describe('ComponentCategoryList', () => { @@ -9,6 +15,7 @@ describe('ComponentCategoryList', () => { beforeEach(async(() => { TestBed.configureTestingModule({ imports: [ComponentCategoryListModule, DocsAppTestingModule], + providers: [ComponentPageTitle], }).compileComponents(); })); diff --git a/src/app/pages/component-page-header/component-page-header.html b/src/app/pages/component-page-header/component-page-header.html index 40aba8b9c..7056b3ed6 100644 --- a/src/app/pages/component-page-header/component-page-header.html +++ b/src/app/pages/component-page-header/component-page-header.html @@ -3,5 +3,5 @@ menu -

{{getTitle()}}

+

{{getTitle()}}

diff --git a/src/app/pages/component-sidenav/component-sidenav.html b/src/app/pages/component-sidenav/component-sidenav.html index c36bc03ea..db3c77278 100644 --- a/src/app/pages/component-sidenav/component-sidenav.html +++ b/src/app/pages/component-sidenav/component-sidenav.html @@ -1,9 +1,9 @@ - -