Skip to content

Commit

Permalink
Fixed #17001 - Component: ConfirmDialog focus recursion error
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Dec 18, 2024
1 parent bf433bc commit 7e413fd
Show file tree
Hide file tree
Showing 2 changed files with 253 additions and 246 deletions.
45 changes: 26 additions & 19 deletions packages/primeng/src/dialog/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,24 +672,32 @@ export class Dialog extends BaseComponent implements OnInit, AfterContentInit, O
return totalMilliseconds;
}

focus(focusParentElement = this.contentViewChild.nativeElement) {
const timeoutDuration = this.parseDurationToMilliseconds(this.transitionOptions);
let focusable = DomHandler.getFocusableElement(focusParentElement, '[autofocus]');

if (focusable) {
this.zone.runOutsideAngular(() => {
setTimeout(() => focusable.focus(), timeoutDuration || 5);
});
return;
_focus(focusParentElement?: HTMLElement): boolean {
if (focusParentElement) {
const timeoutDuration = this.parseDurationToMilliseconds(this.transitionOptions);
let _focusableElements = DomHandler.getFocusableElements(focusParentElement);
if (_focusableElements && _focusableElements.length > 0) {
this.zone.runOutsideAngular(() => {
setTimeout(() => _focusableElements[0].focus(), timeoutDuration || 5);
});
return true;
}
}
const focusableElement = DomHandler.getFocusableElement(focusParentElement);
if (focusableElement) {
this.zone.runOutsideAngular(() => {
setTimeout(() => focusableElement.focus(), timeoutDuration || 5);
});
} else if (this.footerViewChild) {
// If the content section is empty try to focus on footer
this.focus(this.footerViewChild.nativeElement);

return false;
}

focus(focusParentElement?: HTMLElement) {
let focused = this._focus(focusParentElement);

if (!focused) {
focused = this._focus(this.footerViewChild?.nativeElement);
if (!focused) {
focused = this._focus(this.headerViewChild?.nativeElement);
if (!focused) {
this._focus(this.contentViewChild?.nativeElement);
}
}
}
}

Expand Down Expand Up @@ -1034,8 +1042,7 @@ export class Dialog extends BaseComponent implements OnInit, AfterContentInit, O
// }

if (this.focusOnShow) {
const el = this.contentViewChild?.nativeElement || this.container;
this.focus(el);
this.focus();
}
break;

Expand Down
Loading

0 comments on commit 7e413fd

Please sign in to comment.