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 Jun 12, 2023
1 parent 5b5b95d commit 51ddb43
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/app/components/dynamicdialog/dynamicdialog-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,8 @@ export class DynamicDialogConfig<T = any> {
* Position of the dialog, options are "center", "top", "bottom", "left", "right", "top-left", "top-right", "bottom-left" or "bottom-right".
*/
position?: string;
/**
* Whether to automatically focus.
*/
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
7 changes: 7 additions & 0 deletions src/app/showcase/doc/apidoc/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -9356,6 +9356,13 @@
"readonly": false,
"type": "string",
"description": "Position of the dialog, options are \"center\", \"top\", \"bottom\", \"left\", \"right\", \"top-left\", \"top-right\", \"bottom-left\" or \"bottom-right\"."
},
{
"name": "autoFocus",
"optional": true,
"readonly": false,
"type": "boolean",
"description": "Whether to automatically focus."
}
]
}
Expand Down

0 comments on commit 51ddb43

Please sign in to comment.