This repository was archived by the owner on Dec 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 397
chore(accessibility): Add aria attributes to aid screen reader flow #117
Open
riavalon
wants to merge
1
commit into
angular:main
Choose a base branch
from
riavalon:feat-a11y-additions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 11 additions & 10 deletions
21
src/app/pages/component-category-list/component-category-list.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
<div class="docs-component-category-list"> | ||
<md-card | ||
*ngFor="let category of docItems.getItemsInCategories()" | ||
class="docs-component-category-list-card" | ||
[routerLink]="['/categories/', category.id]"> | ||
<md-card-title>{{category.name}}</md-card-title> | ||
<p class="docs-component-category-list-card-summary">{{category.summary}}</p> | ||
<docs-svg-viewer class="docs-component-category-list-card-image" | ||
[src]="'../../../assets/img/component-categories/' + category.id + '.svg'"> | ||
</docs-svg-viewer> | ||
</md-card> | ||
<a | ||
*ngFor="let category of docItems.getItemsInCategories()" | ||
[routerLink]="['/components/category/', category.id]"> | ||
<md-card class="docs-component-category-list-card"> | ||
<md-card-title>{{category.name}}</md-card-title> | ||
<p class="docs-component-category-list-card-summary">{{category.summary}}</p> | ||
<docs-svg-viewer class="docs-component-category-list-card-image" | ||
[src]="'../../../assets/img/component-categories/' + category.id + '.svg'"> | ||
</docs-svg-viewer> | ||
</md-card> | ||
</a> | ||
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
<div class="docs-primary-header"> | ||
<h1>Guides</h1> | ||
</div> | ||
|
||
<md-nav-list class="docs-guide-list"> | ||
<a md-list-item *ngFor="let guide of guideItems.getAllItems()" | ||
<div class="docs-guides-container" role="main"> | ||
<div class="docs-primary-header"> | ||
<h1 [attr.aria-alert]="'Guides'">Guides</h1> | ||
</div> | ||
<md-nav-list class="docs-guide-list"> | ||
<a md-list-item | ||
class="docs-guide-item" | ||
*ngFor="let guide of guideItems.getAllItems()" | ||
[routerLink]="['/guide/', guide.id]"> | ||
{{guide.name}} | ||
</a> | ||
</md-nav-list> | ||
{{guide.name}} | ||
</a> | ||
</md-nav-list> | ||
</div> | ||
|
||
<app-footer></app-footer> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
:host { | ||
:host, .docs-guides-container { | ||
display: flex; | ||
flex-direction: column; | ||
flex-grow: 1; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import {async, TestBed, ComponentFixture} from '@angular/core/testing'; | ||
import {ViewChild, Component, CUSTOM_ELEMENTS_SCHEMA} from '@angular/core'; | ||
import {MaterialModule} from '@angular/material'; | ||
|
||
import {FocusElementDirective} from './focus-element'; | ||
|
||
|
||
@Component({ | ||
selector: 'test-component', | ||
template: '<h1 focusElement>Whoa!</h1>' | ||
}) | ||
class TestComponent { | ||
} | ||
|
||
|
||
describe('FocusElementDirective', () => { | ||
let fixture: ComponentFixture<TestComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
schemas: [CUSTOM_ELEMENTS_SCHEMA], | ||
declarations: [FocusElementDirective, TestComponent] | ||
}); | ||
|
||
fixture = TestBed.createComponent(TestComponent); | ||
})); | ||
|
||
it('should set the tabindex of the host component to 0', () => { | ||
fixture.detectChanges(); | ||
const tabindex = fixture | ||
.nativeElement | ||
.querySelector('h1') | ||
.getAttribute('tabindex'); | ||
expect(tabindex).toEqual('0'); | ||
}); | ||
|
||
it('should call focus to the host components nativeElement', () => { | ||
const el = fixture.nativeElement.querySelector('h1'); | ||
spyOn(el, 'focus'); | ||
fixture.detectChanges(); | ||
expect(el).not.toBeNull(); | ||
expect(el.focus).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import {Renderer, Directive, ElementRef} from '@angular/core'; | ||
|
||
|
||
@Directive({ | ||
selector: '[focusElement]' | ||
}) | ||
|
||
export class FocusElementDirective { | ||
|
||
constructor( | ||
private _element: ElementRef, | ||
private _renderer: Renderer | ||
) { } | ||
|
||
ngAfterViewInit() { | ||
// Add tabindex 0 so element is focusable by keyboard | ||
this | ||
._renderer | ||
.setElementAttribute(this._element.nativeElement, 'tabindex', '0'); | ||
|
||
// Focus host element after view loads | ||
// so screen readers will be alerted | ||
// the page has changed. | ||
this._element.nativeElement.focus(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a very risky change to make; generally having an element grab focus to itself without user input can cause problems. I'll try to look into alternate approaches
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We mostly just need to find a way to signify that the page has changed after a user navigates with a screen reader. At the moment, there is no indication that anything has happened. It was recommended that we focus a heading in the main content area of the page, though I definitely agree that it does feel like there should be a better way to signify this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@riavalon have you tried setting a document title? I would expect a screen reader to notice and announce a change in the title. Have a look here: https://angular.io/docs/ts/latest/cookbook/set-document-title.html
Can you see if this is a better solution?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually tried this already, @naomiblack. Even with a title change the screen reader does not announce anything else. Though, updating the document title during navigation seems like a good thing to have anyway. I can add that back in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is definitely weird. I'll see if I can get some help on this one -- yes -- please do add a document title change back in.