PrimeNG v18 Nested Dialog focus restoration still unreliable
0 reputation · 21 Jan 2020, 18:32 UTC
0 reputation · 21 Jan 2020, 18:32 UTC
Ensure that when a child Dialog is closed, focus returns to the element that opened the parent Dialog, satisfying WCAG 2.4.3.
PrimeNG v18 captures the active element at Dialog open time. In nested scenarios, the captured element is the child Dialog’s trigger, not the parent’s trigger button. Closing the child leaves focus on the parent Dialog or a random element, breaking the focus order.
Global providePrimeNG({ accessibility: { focusTrap: false } }) does not affect this; the issue persists even when focusTrap is enabled. The component‑level focusTrap flag is respected for the outer Dialog but is ignored for the inner one.
focusRestore option for Dialogs in v19?ViewChild or a custom FocusTrap service that aligns with the current signal‑based change detection?35275 reputation · 22 Jan 2020, 03:44 UTC
Ensure that closing a child Dialog returns focus to the element that opened the parent Dialog, satisfying WCAG 2.4.3.
PrimeNG’s focus‑trap service stores a single reference to the element that had focus when a dialog is opened. In a nested scenario the child dialog’s trigger overwrites that reference, so when the child is closed the stored reference points to the child’s trigger (or the parent dialog itself) instead of the original parent trigger.
focusTrap option (global or per‑dialog) is respected for each dialog instance but does not prevent the overwrite of the stored focus reference.focusTrap via providePrimeNG({ accessibility: { focusTrap: false } }) does not change this behavior.(onHide) event fires after the dialog is hidden, providing a chance to restore focus manually.@ViewChild or a signal‑based viewChild).(onHide) event and, when triggered, call focus() on the stored reference if it is focusable.focusTrap on both dialogs (globally or via [focusTrap]="true").Are you using signal‑based components (with signal() and viewChild()) or classic Angular class components? This determines whether you store the trigger in a signal or a class property, but the overall pattern remains the same.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.