dialog-content-directives.ts (material2-7.3.6) | : | dialog-content-directives.ts (material2-7.3.7) | ||
---|---|---|---|---|
skipping to change at line 32 | skipping to change at line 32 | |||
let dialogElementUid = 0; | let dialogElementUid = 0; | |||
/** | /** | |||
* Button that will close the current dialog. | * Button that will close the current dialog. | |||
*/ | */ | |||
@Directive({ | @Directive({ | |||
selector: `button[mat-dialog-close], button[matDialogClose]`, | selector: `button[mat-dialog-close], button[matDialogClose]`, | |||
exportAs: 'matDialogClose', | exportAs: 'matDialogClose', | |||
host: { | host: { | |||
'(click)': 'dialogRef.close(dialogResult)', | '(click)': 'dialogRef.close(dialogResult)', | |||
'[attr.aria-label]': '_hasAriaLabel ? ariaLabel : null', | '[attr.aria-label]': 'ariaLabel || null', | |||
'type': 'button', // Prevents accidental form submits. | 'type': 'button', // Prevents accidental form submits. | |||
} | } | |||
}) | }) | |||
export class MatDialogClose implements OnInit, OnChanges { | export class MatDialogClose implements OnInit, OnChanges { | |||
/** Screenreader label for the button. */ | /** Screenreader label for the button. */ | |||
@Input('aria-label') ariaLabel: string = 'Close dialog'; | @Input('aria-label') ariaLabel: string; | |||
/** Dialog close input. */ | /** Dialog close input. */ | |||
@Input('mat-dialog-close') dialogResult: any; | @Input('mat-dialog-close') dialogResult: any; | |||
@Input('matDialogClose') _matDialogClose: any; | @Input('matDialogClose') _matDialogClose: any; | |||
/** | ||||
* Whether the button should have an `aria-label`. Used for clearing the | ||||
* attribute to prevent it from being read instead of the button's text. | ||||
*/ | ||||
_hasAriaLabel?: boolean; | ||||
constructor( | constructor( | |||
@Optional() public dialogRef: MatDialogRef<any>, | @Optional() public dialogRef: MatDialogRef<any>, | |||
private _elementRef: ElementRef<HTMLElement>, | private _elementRef: ElementRef<HTMLElement>, | |||
private _dialog: MatDialog) {} | private _dialog: MatDialog) {} | |||
ngOnInit() { | ngOnInit() { | |||
if (!this.dialogRef) { | if (!this.dialogRef) { | |||
// When this directive is included in a dialog via TemplateRef (rather tha n being | // When this directive is included in a dialog via TemplateRef (rather tha n being | |||
// in a Component), the DialogRef isn't available via injection because em bedded | // in a Component), the DialogRef isn't available via injection because em bedded | |||
// views cannot be given a custom injector. Instead, we look up the Dialog Ref by | // views cannot be given a custom injector. Instead, we look up the Dialog Ref by | |||
// ID. This must occur in `onInit`, as the ID binding for the dialog conta iner won't | // ID. This must occur in `onInit`, as the ID binding for the dialog conta iner won't | |||
// be resolved at constructor time. | // be resolved at constructor time. | |||
this.dialogRef = getClosestDialog(this._elementRef, this._dialog.openDialo gs)!; | this.dialogRef = getClosestDialog(this._elementRef, this._dialog.openDialo gs)!; | |||
} | } | |||
if (typeof this._hasAriaLabel === 'undefined') { | ||||
const element = this._elementRef.nativeElement; | ||||
if (element.hasAttribute('mat-icon-button')) { | ||||
this._hasAriaLabel = true; | ||||
} else { | ||||
const buttonTextContent = element.textContent; | ||||
this._hasAriaLabel = !buttonTextContent || buttonTextContent.trim().leng | ||||
th === 0; | ||||
} | ||||
} | ||||
} | } | |||
ngOnChanges(changes: SimpleChanges) { | ngOnChanges(changes: SimpleChanges) { | |||
const proxiedChange = | const proxiedChange = changes['_matDialogClose'] || changes['_matDialogClose | |||
changes['_matDialogClose'] || changes['_matDialogCloseResult']; | Result']; | |||
if (proxiedChange) { | if (proxiedChange) { | |||
this.dialogResult = proxiedChange.currentValue; | this.dialogResult = proxiedChange.currentValue; | |||
} | } | |||
if (changes.ariaLabel) { | ||||
this._hasAriaLabel = !!changes.ariaLabel.currentValue; | ||||
} | ||||
} | } | |||
} | } | |||
/** | /** | |||
* Title of a dialog element. Stays fixed to the top of the dialog when scrollin g. | * Title of a dialog element. Stays fixed to the top of the dialog when scrollin g. | |||
*/ | */ | |||
@Directive({ | @Directive({ | |||
selector: '[mat-dialog-title], [matDialogTitle]', | selector: '[mat-dialog-title], [matDialogTitle]', | |||
exportAs: 'matDialogTitle', | exportAs: 'matDialogTitle', | |||
host: { | host: { | |||
End of changes. 6 change blocks. | ||||
26 lines changed or deleted | 4 lines changed or added |