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

fix(confirm-dialog): add reject-on-close flag #17600

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/primeng/src/api/confirmation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ export interface Confirmation {
* Specifies whether the confirmation dialog should be closed when the escape key is pressed.
*/
closeOnEscape?: boolean;
/**
* Determines wheter the rejection event should be triggered
* when the confirmation dialog is closed programmatically using the `close` method
* - `true`: the `reject` event will be emitted when the dialog is closed
* - `false` (default): The dialog will close without triggering the `reject` event.
*/
rejectOnClose?: boolean;
/**
* Specifies whether clicking outside the confirmation dialog should dismiss it.
*/
Expand Down
8 changes: 3 additions & 5 deletions packages/primeng/src/confirmdialog/confirmdialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const hideAnimation = animation([animate('{{transition}}', style({ transform: '{
[appendTo]="option('appendTo')"
[position]="position"
[style]="style"
(visibleChange)="_rejectOnClose($event)"
>
@if (headlessTemplate || _headlessTemplate) {
<ng-template #headless>
Expand Down Expand Up @@ -555,13 +556,10 @@ export class ConfirmDialog extends BaseComponent implements OnInit, OnDestroy {
}
}

close(event: Event) {
if (this.confirmation?.rejectEvent) {
_rejectOnClose(visible: boolean) {
if (this.confirmation?.rejectEvent && this.confirmation?.rejectOnClose && !visible) {
this.confirmation.rejectEvent.emit(ConfirmEventType.CANCEL);
}

this.hide(ConfirmEventType.CANCEL);
event.preventDefault();
}

hide(type?: ConfirmEventType) {
Expand Down
Loading