Skip to content

Commit

Permalink
address cr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbubernak committed Feb 20, 2021
1 parent 0a3ece4 commit 9c0e1ae
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 45 deletions.
27 changes: 7 additions & 20 deletions src/material-experimental/mdc-form-field/directives/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {
AfterViewInit,
Attribute,
Directive,
ElementRef,
InjectionToken,
Input
} from '@angular/core';
import {Attribute, Directive, ElementRef, InjectionToken, Input} from '@angular/core';

let nextUniqueId = 0;

Expand All @@ -34,20 +27,14 @@ export const MAT_ERROR = new InjectionToken<MatError>('MatError');
},
providers: [{provide: MAT_ERROR, useExisting: MatError}],
})
export class MatError implements AfterViewInit {
export class MatError {
@Input() id: string = `mat-mdc-error-${nextUniqueId++}`;

/**
* Aria live value of the error. By default we set this to 'polite', instead of using
* role='alert', so that the screen readers do not interrupt the current task to read this aloud.
*/
@Input('aria-live') ariaLive: string = this._ariaLive ?? 'polite';

constructor(@Attribute('aria-live') private _ariaLive: string, private _elementRef: ElementRef) {}

ngAfterViewInit() {
if (!this._elementRef.nativeElement.ariaLive) {
this._elementRef.nativeElement.setAttribute('aria-live', this.ariaLive);
constructor(@Attribute('aria-live') ariaLive: string, elementRef: ElementRef) {
// If no aria-live value is set add 'polite' as a default. This is preferred over setting
// role='alert' so that screen readers do not interrupt the current task to read this aloud.
if (!ariaLive) {
elementRef.nativeElement.setAttribute('aria-live', 'polite');
}
}
}
27 changes: 7 additions & 20 deletions src/material/form-field/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {
AfterViewInit,
Attribute,
Directive,
ElementRef,
InjectionToken,
Input
} from '@angular/core';
import {Attribute, Directive, ElementRef, InjectionToken, Input} from '@angular/core';

let nextUniqueId = 0;

Expand All @@ -34,20 +27,14 @@ export const MAT_ERROR = new InjectionToken<MatError>('MatError');
},
providers: [{provide: MAT_ERROR, useExisting: MatError}],
})
export class MatError implements AfterViewInit {
export class MatError {
@Input() id: string = `mat-error-${nextUniqueId++}`;

/**
* Aria live value of the error. By default we set this to 'polite', instead of using
* role='alert', so that the screen readers do not interrupt the current task to read this aloud.
*/
@Input('aria-live') ariaLive: string = this._ariaLive ?? 'polite';

constructor(@Attribute('aria-live') private _ariaLive: string, private _elementRef: ElementRef) {}

ngAfterViewInit() {
if (!this._elementRef.nativeElement.ariaLive) {
this._elementRef.nativeElement.setAttribute('aria-live', this.ariaLive);
constructor(@Attribute('aria-live') ariaLive: string, elementRef: ElementRef) {
// If no aria-live value is set add 'polite' as a default. This is preferred over setting
// role='alert' so that screen readers do not interrupt the current task to read this aloud.
if (!ariaLive) {
elementRef.nativeElement.setAttribute('aria-live', 'polite');
}
}
}
8 changes: 3 additions & 5 deletions tools/public_api_guard/material/form-field.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ export declare const MAT_PREFIX: InjectionToken<MatPrefix>;

export declare const MAT_SUFFIX: InjectionToken<MatSuffix>;

export declare class MatError implements AfterViewInit {
ariaLive: string;
export declare class MatError {
id: string;
constructor(_ariaLive: string, _elementRef: ElementRef);
ngAfterViewInit(): void;
static ɵdir: i0.ɵɵDirectiveDefWithMeta<MatError, "mat-error", never, { "id": "id"; "ariaLive": "aria-live"; }, {}, never>;
constructor(ariaLive: string, elementRef: ElementRef);
static ɵdir: i0.ɵɵDirectiveDefWithMeta<MatError, "mat-error", never, { "id": "id"; }, {}, never>;
static ɵfac: i0.ɵɵFactoryDef<MatError, [{ attribute: "aria-live"; }, null]>;
}

Expand Down

0 comments on commit 9c0e1ae

Please sign in to comment.