Skip to content

Commit

Permalink
Merge pull request #13644 from SoyDiego/possible-fix-dialog-error
Browse files Browse the repository at this point in the history
dialog: Possible fix ExpressionChangedAfterItHasBeenCheckedError with attr.aria-labelledby
  • Loading branch information
cetincakiroglu authored Sep 30, 2023
2 parents 58a8169 + c09848b commit 4dda67c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/app/components/dialog/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
PLATFORM_ID,
QueryList,
Renderer2,
SimpleChanges,
TemplateRef,
ViewChild,
ViewEncapsulation,
Expand Down Expand Up @@ -73,13 +74,13 @@ const hideAnimation = animation([animate('{{transition}}', style({ transform: '{
(@animation.start)="onAnimationStart($event)"
(@animation.done)="onAnimationEnd($event)"
role="dialog"
[attr.aria-labelledby]="getAriaLabelledBy()"
[attr.aria-labelledby]="ariaLabelledBy"
[attr.aria-modal]="true"
>
<div *ngIf="resizable" class="p-resizable-handle" style="z-index: 90;" (mousedown)="initResize($event)"></div>
<div #titlebar class="p-dialog-header" (mousedown)="initDrag($event)" *ngIf="showHeader">
<span [id]="getAriaLabelledBy()" class="p-dialog-title" *ngIf="!headerFacet && !headerTemplate">{{ header }}</span>
<span [id]="getAriaLabelledBy()" class="p-dialog-title" *ngIf="headerFacet">
<span [id]="ariaLabelledBy + '_title'" class="p-dialog-title" *ngIf="!headerFacet && !headerTemplate">{{ header }}</span>
<span [id]="ariaLabelledBy + '_title'" class="p-dialog-title" *ngIf="headerFacet">
<ng-content select="p-header"></ng-content>
</span>
<ng-container *ngTemplateOutlet="headerTemplate"></ng-container>
Expand Down Expand Up @@ -464,6 +465,8 @@ export class Dialog implements AfterContentInit, OnInit, OnDestroy {

dragging: boolean | undefined;

ariaLabelledBy: string | undefined;

documentDragListener: VoidListener;

documentDragEndListener: VoidListener;
Expand Down Expand Up @@ -554,6 +557,12 @@ export class Dialog implements AfterContentInit, OnInit, OnDestroy {
}
}

ngOnChanges(changes: SimpleChanges): void {
if (changes.header) {
this.ariaLabelledBy = this.getAriaLabelledBy();
}
}

getAriaLabelledBy() {
return this.header !== null ? UniqueComponentId() + '_header' : null;
}
Expand Down

1 comment on commit 4dda67c

@vercel
Copy link

@vercel vercel bot commented on 4dda67c Sep 30, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.