1 | /**
|
---|
2 | * @license
|
---|
3 | * Copyright Google LLC All Rights Reserved.
|
---|
4 | *
|
---|
5 | * Use of this source code is governed by an MIT-style license that can be
|
---|
6 | * found in the LICENSE file at https://angular.io/license
|
---|
7 | */
|
---|
8 | import { Attribute, Directive, ElementRef, InjectionToken, Input } from '@angular/core';
|
---|
9 | let nextUniqueId = 0;
|
---|
10 | /**
|
---|
11 | * Injection token that can be used to reference instances of `MatError`. It serves as
|
---|
12 | * alternative token to the actual `MatError` class which could cause unnecessary
|
---|
13 | * retention of the class and its directive metadata.
|
---|
14 | */
|
---|
15 | export const MAT_ERROR = new InjectionToken('MatError');
|
---|
16 | /** Single error message to be shown underneath the form field. */
|
---|
17 | export class MatError {
|
---|
18 | constructor(ariaLive, elementRef) {
|
---|
19 | this.id = `mat-error-${nextUniqueId++}`;
|
---|
20 | // If no aria-live value is set add 'polite' as a default. This is preferred over setting
|
---|
21 | // role='alert' so that screen readers do not interrupt the current task to read this aloud.
|
---|
22 | if (!ariaLive) {
|
---|
23 | elementRef.nativeElement.setAttribute('aria-live', 'polite');
|
---|
24 | }
|
---|
25 | }
|
---|
26 | }
|
---|
27 | MatError.decorators = [
|
---|
28 | { type: Directive, args: [{
|
---|
29 | selector: 'mat-error',
|
---|
30 | host: {
|
---|
31 | 'class': 'mat-error',
|
---|
32 | '[attr.id]': 'id',
|
---|
33 | 'aria-atomic': 'true',
|
---|
34 | },
|
---|
35 | providers: [{ provide: MAT_ERROR, useExisting: MatError }],
|
---|
36 | },] }
|
---|
37 | ];
|
---|
38 | MatError.ctorParameters = () => [
|
---|
39 | { type: String, decorators: [{ type: Attribute, args: ['aria-live',] }] },
|
---|
40 | { type: ElementRef }
|
---|
41 | ];
|
---|
42 | MatError.propDecorators = {
|
---|
43 | id: [{ type: Input }]
|
---|
44 | };
|
---|
45 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXJyb3IuanMiLCJzb3VyY2VSb290IjoiIiwic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