From 777e73ab89721f4c3abc38754c901613c9db0a76 Mon Sep 17 00:00:00 2001 From: Egor Volvachev Date: Sun, 19 Feb 2023 10:34:35 +0300 Subject: [PATCH] feat(primeng/p-dynamicDialog): add new property to dynamic dialog configs for autoFocus Fixes #12643. --- src/app/components/contextmenu/contextmenu.ts | 4 ++-- src/app/components/dynamicdialog/dynamicdialog-config.ts | 1 + src/app/components/dynamicdialog/dynamicdialog.ts | 4 ++++ src/app/showcase/doc/dynamicdialog/propsdoc.ts | 6 ++++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/app/components/contextmenu/contextmenu.ts b/src/app/components/contextmenu/contextmenu.ts index 5798d21c76a..bcf36634f97 100755 --- a/src/app/components/contextmenu/contextmenu.ts +++ b/src/app/components/contextmenu/contextmenu.ts @@ -342,7 +342,7 @@ export class ContextMenu implements AfterViewInit, OnDestroy { if (this.global) { const documentTarget: any = this.el ? this.el.nativeElement.ownerDocument : 'document'; this.triggerEventListener = this.renderer.listen(documentTarget, this.triggerEvent, (event) => { - if(this.containerViewChild && this.containerViewChild.nativeElement.style.display !== 'none') { + if (this.containerViewChild && this.containerViewChild.nativeElement.style.display !== 'none') { this.hide(); } this.show(event); @@ -350,7 +350,7 @@ export class ContextMenu implements AfterViewInit, OnDestroy { }); } else if (this.target) { this.triggerEventListener = this.renderer.listen(this.target, this.triggerEvent, (event) => { - if(this.containerViewChild && this.containerViewChild.nativeElement.style.display !== 'none') { + if (this.containerViewChild && this.containerViewChild.nativeElement.style.display !== 'none') { this.hide(); } this.show(event); diff --git a/src/app/components/dynamicdialog/dynamicdialog-config.ts b/src/app/components/dynamicdialog/dynamicdialog-config.ts index 48f0f05cba0..432cd80a165 100755 --- a/src/app/components/dynamicdialog/dynamicdialog-config.ts +++ b/src/app/components/dynamicdialog/dynamicdialog-config.ts @@ -26,4 +26,5 @@ export class DynamicDialogConfig { maximizeIcon?: string; minimizeIcon?: string; position?: string; + autoFocus?: boolean; } diff --git a/src/app/components/dynamicdialog/dynamicdialog.ts b/src/app/components/dynamicdialog/dynamicdialog.ts index 20ab474c46a..750d938218f 100755 --- a/src/app/components/dynamicdialog/dynamicdialog.ts +++ b/src/app/components/dynamicdialog/dynamicdialog.ts @@ -341,6 +341,10 @@ export class DynamicDialogComponent implements AfterViewInit, OnDestroy { } focus() { + if (this.config?.autoFocus === false) { + return; + } + const focusable = DomHandler.getFocusableElements(this.container as HTMLDivElement); if (focusable && focusable.length > 0) { this.zone.runOutsideAngular(() => { diff --git a/src/app/showcase/doc/dynamicdialog/propsdoc.ts b/src/app/showcase/doc/dynamicdialog/propsdoc.ts index b49256e47dd..a01196b0988 100644 --- a/src/app/showcase/doc/dynamicdialog/propsdoc.ts +++ b/src/app/showcase/doc/dynamicdialog/propsdoc.ts @@ -165,6 +165,12 @@ import { Component, Input } from '@angular/core'; true Enables dragging to change the position using header. + + autoFocus + boolean + true + Whether to automatically focus. +