Skip to content

demo(dialog): Add accessibility demo page for dialog #6360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/demo-app/a11y/a11y-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ import {ButtonAccessibilityDemo} from './button/button-a11y';
import {ButtonToggleAccessibilityDemo} from './button-toggle/button-toggle-a11y';
import {CheckboxAccessibilityDemo} from './checkbox/checkbox-a11y';
import {ChipsAccessibilityDemo} from './chips/chips-a11y';
import {
DialogAccessibilityDemo,
DialogAddressFormDialog,
DialogFruitExampleDialog,
DialogNeptuneExampleDialog,
DialogNeptuneIFrameDialog,
DialogWelcomeExampleDialog
} from './dialog/dialog-a11y';

import {GridListAccessibilityDemo} from './grid-list/grid-list-a11y';
import {RadioAccessibilityDemo} from './radio/radio-a11y';
import {DatepickerAccessibilityDemo} from './datepicker/datepicker-a11y';
Expand Down Expand Up @@ -48,6 +57,12 @@ export class AccessibilityRoutingModule {}
CheckboxAccessibilityDemo,
ChipsAccessibilityDemo,
DatepickerAccessibilityDemo,
DialogAccessibilityDemo,
DialogAddressFormDialog,
DialogFruitExampleDialog,
DialogNeptuneExampleDialog,
DialogNeptuneIFrameDialog,
DialogWelcomeExampleDialog,
GridListAccessibilityDemo,
IconAccessibilityDemo,
InputAccessibilityDemo,
Expand All @@ -56,6 +71,14 @@ export class AccessibilityRoutingModule {}
SliderAccessibilityDemo,
SnackBarAccessibilityDemo,
SelectAccessibilityDemo,
],
entryComponents: [
DialogAccessibilityDemo,
DialogAddressFormDialog,
DialogFruitExampleDialog,
DialogNeptuneExampleDialog,
DialogNeptuneIFrameDialog,
DialogWelcomeExampleDialog,
]
})
export class AccessibilityDemoModule {}
1 change: 1 addition & 0 deletions src/demo-app/a11y/a11y.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class AccessibilityDemo {
{name: 'Checkbox', route: 'checkbox'},
{name: 'Chips', route: 'chips'},
{name: 'Datepicker', route: 'datepicker'},
{name: 'Dialog', route: 'dialog'},
{name: 'Grid list', route: 'grid-list'},
{name: 'Icon', route: 'icon'},
{name: 'Input', route: 'input'},
Expand Down
31 changes: 31 additions & 0 deletions src/demo-app/a11y/dialog/dialog-a11y.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<section>
<h2>Welcome message</h2>
<p>Activate the button to see a welcome dialog with a simple message and a close button.</p>
<button md-button (click)="openWelcomeDialog()">Welcome</button>
</section>

<section>
<h2>Choose a fruit</h2>
<p>Active the button to choose apple or peach in a dialog.</p>
<button md-button (click)="openFruitDialog()">Fruit</button>
<p *ngIf="fruitSelectedOption">
You chose: {{fruitSelectedOption}}
</p>
</section>

<section>
<h2>Neptune</h2>
<p>
Active the button to see a dialog showing information of Neptune.
A Uncyclopedia page can be opened either in a new tab or in a stacked dialog.
</p>
<button md-button (click)="openNeptuneDialog()">Learn Neptune</button>
</section>

<section>
<h2>Address form</h2>
<p>
Active the button to fill out shipping address information in a dialog.
</p>
<button md-button (click)="openAddressDialog()">Add address</button>
</section>
Empty file.
80 changes: 80 additions & 0 deletions src/demo-app/a11y/dialog/dialog-a11y.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import {Component} from '@angular/core';
import {MdDialog} from '@angular/material';


@Component({
moduleId: module.id,
selector: 'dialog-a11y',
templateUrl: 'dialog-a11y.html',
styleUrls: ['dialog-a11y.css'],
})
export class DialogAccessibilityDemo {
fruitSelectedOption: string = '';

constructor(public dialog: MdDialog) {}

openFruitDialog() {
let dialogRef = this.dialog.open(DialogFruitExampleDialog);
dialogRef.afterClosed().subscribe(result => {
this.fruitSelectedOption = result;
});
}

openWelcomeDialog() {
this.dialog.open(DialogWelcomeExampleDialog);
}

openNeptuneDialog() {
this.dialog.open(DialogNeptuneExampleDialog);
}

openAddressDialog() {
this.dialog.open(DialogAddressFormDialog);
}
}

@Component({
moduleId: module.id,
selector: 'dialog-fruit-a11y',
templateUrl: 'dialog-fruit-a11y.html'
})
export class DialogFruitExampleDialog {}

@Component({
moduleId: module.id,
selector: 'dialog-welcome-a11y',
templateUrl: 'dialog-welcome-a11y.html'
})
export class DialogWelcomeExampleDialog {}

@Component({
moduleId: module.id,
selector: 'dialog-neptune-a11y-dialog',
templateUrl: './dialog-neptune-a11y.html'
})
export class DialogNeptuneExampleDialog {
constructor(public dialog: MdDialog) { }

showInStackedDialog() {
this.dialog.open(DialogNeptuneIFrameDialog);
}
}

@Component({
moduleId: module.id,
selector: 'dialog-neptune-iframe-dialog',
styles: [
`iframe {
width: 800px;
}`
],
templateUrl: './dialog-neptune-iframe-a11y.html'
})
export class DialogNeptuneIFrameDialog {}

@Component({
moduleId: module.id,
selector: 'dialog-address-form-a11y',
templateUrl: 'dialog-address-form-a11y.html'
})
export class DialogAddressFormDialog {}
45 changes: 45 additions & 0 deletions src/demo-app/a11y/dialog/dialog-address-form-a11y.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<h2 md-dialog-title>Company</h2>

<md-dialog-content>
<form class="example-form">
<md-form-field class="example-full-width">
<input mdInput placeholder="Company (disabled)" disabled value="Google">
</md-form-field>

<table class="example-full-width" cellspacing="0"><tr>
<td><md-form-field class="example-full-width">
<input mdInput placeholder="First name">
</md-form-field></td>
<td><md-form-field class="example-full-width">
<input mdInput placeholder="Long Last Name That Will Be Truncated">
</md-form-field></td>
</tr></table>

<p>
<md-form-field class="example-full-width">
<textarea mdInput placeholder="Address">1600 Amphitheatre Pkwy</textarea>
</md-form-field>
<md-form-field class="example-full-width">
<textarea mdInput placeholder="Address 2"></textarea>
</md-form-field>
</p>

<table class="example-full-width" cellspacing="0"><tr>
<td><md-form-field class="example-full-width">
<input mdInput placeholder="City">
</md-form-field></td>
<td><md-form-field class="example-full-width">
<input mdInput placeholder="State">
</md-form-field></td>
<td><md-form-field class="example-full-width">
<input mdInput #postalCode maxlength="5" placeholder="Postal Code" value="94043">
<md-hint align="end">{{postalCode.value.length}} / 5</md-hint>
</md-form-field></td>
</tr></table>
</form>
</md-dialog-content>

<md-dialog-actions>
<button md-raised-button color="primary" md-dialog-close>Submit</button>
<button md-raised-button md-dialog-close>Close</button>
</md-dialog-actions>
6 changes: 6 additions & 0 deletions src/demo-app/a11y/dialog/dialog-fruit-a11y.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h2 md-dialog-title>Fruit</h2>
<div md-dialog-content>Which would you like to choose?</div>
<div md-dialog-actions>
<button md-button md-dialog-close="apple" aria-label="Apple">Apple</button>
<button md-button md-dialog-close="peach" aria-label="Peach">Peach</button>
</div>
27 changes: 27 additions & 0 deletions src/demo-app/a11y/dialog/dialog-neptune-a11y.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<h2 md-dialog-title>Neptune</h2>

<md-dialog-content>
<img src="https://upload.wikimedia.org/wikipedia/commons/5/56/Neptune_Full.jpg"
alt="Neptune"/>

<p>
Neptune is the eighth and farthest known planet from the Sun in the Solar System. In the
Solar System, it is the fourth-largest planet by diameter, the third-most-massive planet,
and the densest giant planet. Neptune is 17 times the mass of Earth and is slightly more
massive than its near-twin Uranus, which is 15 times the mass of Earth and slightly larger
than Neptune. Neptune orbits the Sun once every 164.8 years at an average distance of 30.1
astronomical units (4.50×109 km). It is named after the Roman god of the sea and has the
astronomical symbol ♆, a stylised version of the god Neptune's trident.
</p>
</md-dialog-content>

<md-dialog-actions>
<button md-raised-button color="primary" md-dialog-close>Close</button>

<a md-button color="primary" href="https://en.wikipedia.org/wiki/Neptune" target="_blank">
Read more on Uncyclopedia
</a>

<button md-button color="secondary" (click)="showInStackedDialog()">
Show in dialog</button>
</md-dialog-actions>
9 changes: 9 additions & 0 deletions src/demo-app/a11y/dialog/dialog-neptune-iframe-a11y.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h2 md-dialog-title>Neptune</h2>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does the focus go when this dialog is opened?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "Close" button in the dialog.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect that having the focus start after all of the dialog content is weird

@tinayuangao @crisbeto what do you think of adding a dialog config option like focusDialogElementOnOpen (and also ariaLabel) to help with dialogs like this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does make sense, although specifying what element takes precedence in the focus trap should already be possible through the cdk-focus-initial attribute.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't give a way to focus the role="dialog" element, though, which I think is what we'd want (but I'm not 100% sure).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a config option makes sense to me.

I added another example for forms. The focus goes to the first input box in the form when the dialog is opened.


<md-dialog-content>
<iframe frameborder="0" src="https://en.wikipedia.org/wiki/Neptune"></iframe>
</md-dialog-content>

<md-dialog-actions>
<button md-raised-button color="primary" md-dialog-close>Close</button>
</md-dialog-actions>
13 changes: 13 additions & 0 deletions src/demo-app/a11y/dialog/dialog-welcome-a11y.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<h2>Welcome to Angular Material dialog demo page!</h2>

<p>
The Web is fundamentally designed to work for all people, whatever their hardware, software,
language, culture, location, or physical or mental ability. When the Web meets this goal, it is
accessible to people with a diverse range of hearing, movement, sight, and cognitive ability.
</p>
<p>
The mission of the Web Accessibility Initiative (WAI) is to lead the Web to its full potential to
be accessible, enabling people with disabilities to participate equally on the Web.
</p>

<button md-button color="primary" md-dialog-close>Close</button>
2 changes: 2 additions & 0 deletions src/demo-app/a11y/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {ButtonAccessibilityDemo} from './button/button-a11y';
import {ButtonToggleAccessibilityDemo} from './button-toggle/button-toggle-a11y';
import {CheckboxAccessibilityDemo} from './checkbox/checkbox-a11y';
import {ChipsAccessibilityDemo} from './chips/chips-a11y';
import {DialogAccessibilityDemo} from './dialog/dialog-a11y';
import {GridListAccessibilityDemo} from './grid-list/grid-list-a11y';
import {RadioAccessibilityDemo} from './radio/radio-a11y';
import {AccessibilityHome} from './a11y';
Expand All @@ -23,6 +24,7 @@ export const ACCESSIBILITY_DEMO_ROUTES: Routes = [
{path: 'checkbox', component: CheckboxAccessibilityDemo},
{path: 'chips', component: ChipsAccessibilityDemo},
{path: 'datepicker', component: DatepickerAccessibilityDemo},
{path: 'dialog', component: DialogAccessibilityDemo},
{path: 'grid-list', component: GridListAccessibilityDemo},
{path: 'icon', component: IconAccessibilityDemo},
{path: 'input', component: InputAccessibilityDemo},
Expand Down
1 change: 1 addition & 0 deletions src/lib/dialog/dialog-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@ export class MdDialogConfig {
/** ID of the element that describes the dialog. */
ariaDescribedBy?: string | null = null;


// TODO(jelbourn): add configuration for lifecycle hooks, ARIA labelling.
}