Popconfirm

Ask "Are you sure?" next to a button before its action runs.

Installation

Import the class, and @use the entry point in your global styles: without it the component renders unstyled.

import { Component } from '@angular/core';
import { WrPopconfirm } from 'ngwr/popconfirm';

@Component({ imports: [WrPopconfirm] })
export class MyComponent {}

Basic usage

(confirmed) fires on confirm; (cancelled) on cancel, Escape or a click outside.

Last result: —
<wr-btn
  color="danger"
  wrPopconfirm="Delete this item?"
  confirmText="Delete"
  confirmColor="danger"
  (confirmed)="remove()"
  (cancelled)="onCancel()"
>Delete</wr-btn>

Positions

position picks the side; the panel flips when there is no room.

<wr-btn wrPopconfirm="Delete this item?" position="bottom" (confirmed)="remove()">Delete</wr-btn>

Template reference

Export as wrPopconfirm to open it from another control.

<wr-btn wrPopconfirm="Delete this file?" #ask="wrPopconfirm" (confirmed)="remove()">
  Delete
</wr-btn>

<!-- Anywhere else in the same template -->
<wr-btn [disabled]="ask.isOpen()" (click)="ask.open()">Ask again</wr-btn>

API

NameDescriptionTypeDefault
wrPopconfirmrequiredConfirmation message.string—
positionAnchor side; the panel flips to another side when this one has no room.WrPopconfirmPosition'top'
confirmTextConfirm button text. Falls back to popconfirm.confirm.string | nullnull
cancelTextCancel button text. Falls back to popconfirm.cancel.string | nullnull
ariaLabelAccessible name of the confirmation dialog. role="dialog" with no name announces as a bare "dialog". Falls back to popconfirm.label.string | nullnull
confirmColorColor of the confirm button.WrColor'primary'
panelClassExtra CSS classes for the confirmation bubble's overlay pane. The pane is appended to the overlay container, not to this component, so nothing in the consumer's own template encloses it and no descendant rule written around the trigger can reach it. This input is the only per-instance handle on it. A space-separated string works as well as an array.WrClassInputnull
(confirmed)Fires when the user clicks confirm.void—
(cancelled)Fires when the user clicks cancel or dismisses the overlay.void—

CSS variables

Set these on the component's selector or a wrapper, not on :root: the defaults are declared on ngwr/popconfirm's own element.

VariableDefaultDeclared on
--wr-popconfirm-actions-gapvar(--wr-space-sm).wr-popconfirm
--wr-popconfirm-bordervar(--wr-border-base).wr-popconfirm
--wr-popconfirm-font-familyvar(--wr-font-family-base).wr-popconfirm
--wr-popconfirm-message-font-sizevar(--wr-text-sm).wr-popconfirm
--wr-popconfirm-message-line-heightvar(--wr-text-sm-leading).wr-popconfirm
--wr-popconfirm-message-margin-block-endvar(--wr-space-md).wr-popconfirm
--wr-popconfirm-paddingvar(--wr-space-lg).wr-popconfirm
--wr-popconfirm-radiusvar(--wr-border-radius-base).wr-popconfirm

Dependencies

Angular CDKoverlay, portal
Built onButton, Overlay

See also