Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

p-dialog [focusOnShow]="true" Maximum call stack size exceeded #15978

Closed
kubedan opened this issue Jul 8, 2024 · 0 comments · Fixed by #15979 · 4 remaining pull requests
Closed

p-dialog [focusOnShow]="true" Maximum call stack size exceeded #15978

kubedan opened this issue Jul 8, 2024 · 0 comments · Fixed by #15979 · 4 remaining pull requests
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@kubedan
Copy link
Contributor

kubedan commented Jul 8, 2024

Describe the bug

If I set the property [focusOnShow]="true" in the p-dialog component and the body of the dialog and the p-footer of the dialog do not contain a focusable element, it results in a "Maximum call stack size exceeded" error.

<p-dialog
  [visible]="true"  
  [focusOnShow]="true">
  Body:  Any focusable element.
  <p-footer>Footer:  Any focusable element.</p-footer>
</p-dialog>

The problem is here
(https://github.com/primefaces/primeng/blob/e804cd63eeadcb6cede73aab108fdd167dc28d5f/src/app/components/dialog/dialog.ts#L601C5-L619C1) where this.focus(this.footerViewChild.nativeElement); is called infinitely.

Environment

Doesnt matter

Reproducer

https://github-seqmj3.stackblitz.io/

Angular version

17.3.11

PrimeNG version

17.18.3

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

v18.20.3

Browser(s)

No response

Steps to reproduce the behavior

  1. Go to https://github-seqmj3.stackblitz.io/ or https://stackblitz.com/edit/github-seqmj3
  2. See error in console.
    image

Expected behavior

The component does not crash even if it does not have a focusable

Proposed Fix

--- a/src/app/components/dialog/dialog.ts	
+++ b/src/app/components/dialog/dialog.ts	
@@ -611,7 +611,7 @@
             this.zone.runOutsideAngular(() => {
                 setTimeout(() => focusableElement.focus(), 5);
             });
-        } else if (this.footerViewChild) {
+        } else if (this.footerViewChild && focusParentElement !== this.footerViewChild.nativeElement) {
             // If the content section is empty try to focus on footer
             this.focus(this.footerViewChild.nativeElement);
         }

@kubedan kubedan added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Jul 8, 2024
kubedan added a commit to kubedan/primeng that referenced this issue Jul 8, 2024
@cetincakiroglu cetincakiroglu added this to the 17.18.4 milestone Jul 11, 2024
@cetincakiroglu cetincakiroglu added Type: Bug Issue contains a bug related to a specific component. Something about the component is not working and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Jul 11, 2024
cetincakiroglu added a commit that referenced this issue Jul 11, 2024
Fixed #15978 - Doesn't call this.focus infinitely.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment