Skip to content
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

feature(dialogs): better a11y + exposed open/closeAll methods from MdDialog. closes(#170 and #171) #190

Merged
merged 5 commits into from
Dec 16, 2016
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
10 changes: 10 additions & 0 deletions src/app/components/components/dialogs/dialogs.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ export class DialogsDemoComponent {
description: `Opens a prompt dialog with the provided config.`,
name: 'openPrompt',
type: 'function(IPromptConfig): MdDialogRef<TdPromptDialogComponent>',
}, {
description: `Wrapper function over the open() method in MdDialog.
Opens a modal dialog containing the given component.`,
name: 'open',
type: 'function<T>(component: ComponentType<T>, config: MdDialogConfig): MdDialogRef<T>',
}, {
description: `Wrapper function over the closeAll() method in MdDialog.
Closes all of the currently-open dialogs.`,
name: 'closeAll',
type: 'function()',
}];

constructor(private _dialogService: TdDialogService) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
{{message}}
</td-dialog-content>
<td-dialog-actions>
<button md-button (click)="cancel()">{{cancelButton}}</button>
<button md-button color="accent" (click)="accept()">{{acceptButton}}</button>
<button md-button
#closeBtn
(keydown.arrowright)="acceptBtn.focus()"
(click)="cancel()">{{cancelButton}}</button>
<button md-button
color="accent"
#acceptBtn
(keydown.arrowleft)="closeBtn.focus()"
(click)="accept()">{{acceptButton}}</button>
</td-dialog-actions>
</td-dialog>
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,25 @@
</td-dialog-title>
<td-dialog-content layout="column" class="md-subhead tc-grey-700">
{{message}}
<form #form="ngForm" layout="row" flex>
<md-input [(ngModel)]="value" name="value" required flex></md-input>
<form #form="ngForm" layout="row" novalidate flex>
<md-input (keydown.enter)="$event.preventDefault(); form.valid && accept()"
[(ngModel)]="value"
name="value"
required
flex
></md-input>
</form>
</td-dialog-content>
<td-dialog-actions>
<button md-button (click)="cancel()">{{cancelButton}}</button>
<button md-button color="accent" [disabled]="!form.valid" (click)="accept()">{{acceptButton}}</button>
<button md-button
#closeBtn
(keydown.arrowright)="acceptBtn.focus()"
(click)="cancel()">{{cancelButton}}</button>
<button md-button
color="accent"
#acceptBtn
(keydown.arrowleft)="closeBtn.focus()"
[disabled]="!form.valid"
(click)="accept()">{{acceptButton}}</button>
</td-dialog-actions>
</td-dialog>
21 changes: 20 additions & 1 deletion src/platform/core/dialogs/services/dialog.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable, ViewContainerRef } from '@angular/core';
import { MdDialog, MdDialogRef, MdDialogConfig } from '@angular/material';
import { MdDialog, MdDialogRef, MdDialogConfig, ComponentType } from '@angular/material';

import { TdAlertDialogComponent } from '../alert-dialog/alert-dialog.component';
import { TdConfirmDialogComponent } from '../confirm-dialog/confirm-dialog.component';
Expand Down Expand Up @@ -30,6 +30,25 @@ export class TdDialogService {

constructor(private _dialogService: MdDialog) {}

/**
* params:
* - component: ComponentType<T>
* - config: MdDialogConfig
* Wrapper function over the open() method in MdDialog.
* Opens a modal dialog containing the given component.
*/
public open<T>(component: ComponentType<T>, config?: MdDialogConfig): MdDialogRef<T> {
return this._dialogService.open(component, config);
}

/**
* Wrapper function over the closeAll() method in MdDialog.
* Closes all of the currently-open dialogs.
*/
public closeAll(): void {
this._dialogService.closeAll();
}

/**
* params:
* - viewContainerRef: ViewContainerRef
Expand Down