Skip to content

Commit

Permalink
feat(primeng/p-dynamicDialog): add new property to dynamic dialog con…
Browse files Browse the repository at this point in the history
…figs for autoFocus

Fixes primefaces#12643.
  • Loading branch information
volvachev committed May 23, 2023
1 parent 2e57322 commit 777e73a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/app/components/contextmenu/contextmenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,15 +342,15 @@ 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);
event.preventDefault();
});
} 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);
Expand Down
1 change: 1 addition & 0 deletions src/app/components/dynamicdialog/dynamicdialog-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ export class DynamicDialogConfig<T = any> {
maximizeIcon?: string;
minimizeIcon?: string;
position?: string;
autoFocus?: boolean;
}
4 changes: 4 additions & 0 deletions src/app/components/dynamicdialog/dynamicdialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
6 changes: 6 additions & 0 deletions src/app/showcase/doc/dynamicdialog/propsdoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ import { Component, Input } from '@angular/core';
<td>true</td>
<td>Enables dragging to change the position using header.</td>
</tr>
<tr>
<td>autoFocus</td>
<td>boolean</td>
<td>true</td>
<td>Whether to automatically focus.</td>
</tr>
</tbody>
</table>
</div>
Expand Down

0 comments on commit 777e73a

Please sign in to comment.