본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

ConfirmPopup 컴포넌트

원문 보기 위키 갱신

ConfirmPopup 컴포넌트 (Angular ConfirmPopup Component)

ConfirmPopup은 버튼 같은 대상 요소를 기준으로 확인용 오버레이를 띄워 사용자의 승인이나 거절을 받는 컴포넌트예요. p-confirmpopup 태그로 선언하고 ConfirmationService의 confirm 메서드를 호출해서 화면에 표시해요. 이 문서에서는 기본 사용법부터 접근성(스크린 리더·키보드 지원), 템플릿, Props, Pass Through, 테마까지 차근차근 다뤄요. Headless 모드로 팝업 UI를 직접 구성하는 방법도 함께 소개해요

출처: 문서

본문

접근성

스크린 리더 ConfirmPopup 컴포넌트는 alertdialog 역할을 사용해요. 모든 속성이 루트 엘리먼트에 전달되기 때문에, 팝업 내용을 설명하는 aria-label이나 aria-labelledby 같은 속성을 정의할 수 있어요. 또한 포커스가 팝업 안에 유지되기 때문에 aria-modal이 추가돼요. 버튼처럼 키보드로 접근할 수 있는 트리거 컴포넌트를 사용하는 게 권장되고, 그렇지 않으면 tabIndex를 추가해야 해요. ConfirmPopup은 트리거와 팝업 사이의 관계가 정의되도록 트리거에 aria-expanded 상태 속성과 aria-controls를 추가해요. 오버레이 키보드 지원 팝업이 열리면 첫 번째 포커스 가능한 엘리먼트가 포커스를 받는데, 팝업 내부의 엘리먼트에 autofocus를 추가해서 이를 커스터마이즈할 수 있어요. 키 기능 tab 팝업 안에서 포커스 가능한 다음 엘리먼트로 포커스를 이동해요. shift + tab 팝업 안에서 포커스 가능한 이전 엘리먼트로 포커스를 이동해요. escape 팝업을 닫고 트리거로 포커스를 이동해요. 버튼 키보드 지원 키 기능 enter 액션을 실행하고, 팝업을 닫고, 트리거로 포커스를 이동해요. space 액션을 실행하고, 팝업을 닫고, 트리거로 포커스를 이동해요.

기본

ConfirmPopup은 p-confirmPopup 태그로 정의되고, confirm 메서드를 호출해서 이를 표시하려면 ConfirmationService 인스턴스가 필요해요.

import { Component, inject } from '@angular/core';
import { ButtonModule } from 'primeng/button';
import { ConfirmPopupModule } from 'primeng/confirmpopup';
import { ToastModule } from 'primeng/toast';
import { MessageService, ConfirmationService } from 'primeng/api';

@Component({
    template: `
        <div class="card flex justify-center gap-2">
            <p-toast />
            <p-confirmpopup />
            <p-button (onClick)="confirm1($event)" label="Save" [outlined]="true" />
            <p-button (onClick)="confirm2($event)" label="Delete" severity="danger" [outlined]="true" />
        </div>
    `,
    standalone: true,
    imports: [ButtonModule, ConfirmPopupModule, ToastModule],
    providers: [ConfirmationService, MessageService]
})
export class ConfirmpopupBasicDemo {
    private confirmationService = inject(ConfirmationService);
    private messageService = inject(MessageService);

    confirm2(event: Event) {
        this.confirmationService.confirm({
            target: event.currentTarget as EventTarget,
            message: 'Do you want to delete this record?',
            icon: 'pi pi-info-circle',
            rejectButtonProps: {
                label: 'Cancel',
                severity: 'secondary',
                outlined: true
            },
            acceptButtonProps: {
                label: 'Delete',
                severity: 'danger'
            },
            accept: () => {
                this.messageService.add({ severity: 'info', summary: 'Confirmed', detail: 'Record deleted', life: 3000 });
            },
            reject: () => {
                this.messageService.add({ severity: 'error', summary: 'Rejected', detail: 'You have rejected', life: 3000 });
            }
        });
    }
}

confirmationapi-doc

import { Component } from '@angular/core';

@Component({
    template: `
        <div class="doc-tablewrapper">
            <table class="doc-table">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Type</th>
                        <th>Default</th>
                        <th>Description</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>message</td>
                        <td>string</td>
                        <td>null</td>
                        <td>Message of the confirmation.</td>
                    </tr>
                    <tr>
                        <td>key</td>
                        <td>string</td>
                        <td>null</td>
                        <td>Optional key to match the key of the confirm popup, necessary to use when component tree has multiple confirm popups.</td>
                    </tr>
                    <tr>
                        <td>icon</td>
                        <td>string</td>
                        <td>null</td>
                        <td>Icon to display next to the message.</td>
                    </tr>
                    <tr>
                        <td>accept</td>
                        <td>Function</td>
                        <td>null</td>
                        <td>Callback to execute when action is confirmed.</td>
                    </tr>
                    <tr>
                        <td>reject</td>
                        <td>Function</td>
                        <td>null</td>
                        <td>Callback to execute when action is rejected.</td>
                    </tr>
                    <tr>
                        <td>acceptLabel</td>
                        <td>string</td>
                        <td>null</td>
                        <td>Label of the accept button.</td>
                    </tr>
                    <tr>
                        <td>rejectLabel</td>
                        <td>string</td>
                        <td>null</td>
                        <td>Label of the reject button.</td>
                    </tr>
                    <tr>
                        <td>acceptIcon</td>
                        <td>string</td>
                        <td>null</td>
                        <td>Icon of the accept button.</td>
                    </tr>
                    <tr>
                        <td>rejectIcon</td>
                        <td>string</td>
                        <td>null</td>
                        <td>Icon of the reject button.</td>
                    </tr>
                    <tr>
                        <td>acceptVisible</td>
                        <td>boolean</td>
                        <td>true</td>
                        <td>Visibility of the accept button.</td>
                    </tr>
                    <tr>
                        <td>rejectVisible</td>
                        <td>boolean</td>
                        <td>true</td>
                        <td>Visibility of the reject button.</td>
                    </tr>
                    <tr>
                        <td>acceptButtonStyleClass</td>
                        <td>string</td>
                        <td>null</td>
                        <td>Style class of the accept button.</td>
                    </tr>
                    <tr>
                        <td>rejectButtonStyleClass</td>
                        <td>string</td>
                        <td>null</td>
                        <td>Style class of the reject button.</td>
                    </tr>
                    <tr>
                        <td>defaultFocus</td>
                        <td>string</td>
                        <td>accept</td>
                        <td>Element to receive the focus when the popup gets visible, valid values are "accept", "reject", and "none".</td>
                    </tr>
                </tbody>
            </table>
        </div>
    `,
    standalone: true,
    imports: []
})
export class ConfirmpopupConfirmationapiDemo {}

헤드리스

헤드리스 모드를 사용하면 기본 엘리먼트 대신 전체 사용자 인터페이스를 커스터마이즈할 수 있어요.

import { Component, inject } from '@angular/core';
import { ButtonModule } from 'primeng/button';
import { ConfirmPopupModule } from 'primeng/confirmpopup';
import { ToastModule } from 'primeng/toast';
import { MessageService, ConfirmationService } from 'primeng/api';

@Component({
    template: `
        <div class="card flex justify-center">
            <p-toast />
            <p-confirmpopup #cp>
                <ng-template #headless let-message>
                    <div class="rounded p-4">
                        <span>{{ message.message }}</span>
                        <div class="flex items-center gap-2 mt-4">
                            <p-button (onClick)="cp.onAccept()" label="Save" size="small" [autofocus]="true" />
                            <p-button (onClick)="cp.onReject()" label="Cancel" [text]="true" size="small" severity="secondary" />
                        </div>
                    </div>
                </ng-template>
            </p-confirmpopup>
            <p-button (onClick)="confirm($event)" label="Save" />
        </div>
    `,
    standalone: true,
    imports: [ButtonModule, ConfirmPopupModule, ToastModule],
    providers: [ConfirmationService, MessageService]
})
export class ConfirmpopupHeadlessDemo {
    private confirmationService = inject(ConfirmationService);
    private messageService = inject(MessageService);
}

props-doc

import { Component } from '@angular/core';

@Component({
    template: `
        <div class="doc-tablewrapper">
            <table class="doc-table">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Type</th>
                        <th>Default</th>
                        <th>Description</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>key</td>
                        <td>string</td>
                        <td>null</td>
                        <td>Optional key to match the key of confirm object, necessary to use when component tree has multiple confirm dialogs.</td>
                    </tr>
                    <tr>
                        <td>showTransitionOptions</td>
                        <td>string</td>
                        <td>.12s cubic-bezier(0, 0, 0.2, 1)</td>
                        <td>Transition options of the show animation.</td>
                    </tr>
                    <tr>
                        <td>hideTransitionOptions</td>
                        <td>string</td>
                        <td>.1s linear</td>
                        <td>Transition options of the hide animation.</td>
                    </tr>
                    <tr>
                        <td>autoZIndex</td>
                        <td>boolean</td>
                        <td>true</td>
                        <td>Whether to automatically manage layering.</td>
                    </tr>
                    <tr>
                        <td>baseZIndex</td>
                        <td>number</td>
                        <td>0</td>
                        <td>Base zIndex value to use in layering.</td>
                    </tr>
                    <tr>
                        <td>style</td>
                        <td>string</td>
                        <td>null</td>
                        <td>Inline style of the component.</td>
                    </tr>
                    <tr>
                        <td>styleClass</td>
                        <td>string</td>
                        <td>null</td>
                        <td>Style class of the component.</td>
                    </tr>
                </tbody>
            </table>
        </div>
    `,
    standalone: true,
    imports: []
})
export class ConfirmpopupPropsDemo {}

템플릿

content 템플릿을 사용해서 콘텐츠 섹션을 커스터마이즈할 수 있어요.

import { Component, inject } from '@angular/core';
import { ButtonModule } from 'primeng/button';
import { ConfirmPopupModule } from 'primeng/confirmpopup';
import { ToastModule } from 'primeng/toast';
import { MessageService, ConfirmationService } from 'primeng/api';

@Component({
    template: `
        <div class="card flex justify-center">
            <p-toast />
            <p-confirmpopup>
                <ng-template #content let-message>
                    <div class="flex flex-col items-center w-full gap-4 border-b border-surface-200 dark:border-surface-700 p-4 mb-4 pb-0">
                        <i [class]="message.icon" class="!text-6xl text-primary-500"></i>
                        <p>{{ message.message }}</p>
                    </div>
                </ng-template>
            </p-confirmpopup>
            <p-button (click)="confirm($event)" label="Save" />
        </div>
    `,
    standalone: true,
    imports: [ButtonModule, ConfirmPopupModule, ToastModule],
    providers: [ConfirmationService, MessageService]
})
export class ConfirmpopupTemplateDemo {
    private confirmationService = inject(ConfirmationService);
    private messageService = inject(MessageService);
}

templates-doc

import { Component } from '@angular/core';

@Component({
    template: `
        <div class="doc-tablewrapper">
            <table class="doc-table">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Parameters</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>accepticon</td>
                        <td>-</td>
                    </tr>
                    <tr>
                        <td>rejecticon</td>
                        <td>-</td>
                    </tr>
                </tbody>
            </table>
        </div>
    `,
    standalone: true,
    imports: []
})
export class ConfirmpopupTemplatesDemo {}

Confirm Popup

ConfirmPopup은 대상을 기준으로 상대적으로 표시되는 확인 오버레이를 보여줘요.

프로퍼티

이름 타입 기본값 설명
dt InputSignal undefined 컴포넌트의 스코프 디자인 토큰을 정의해요.
unstyled InputSignal undefined 컴포넌트를 스타일 없이 렌더링할지 여부를 나타내요.
pt InputSignal undefined 컴포넌트 내부의 DOM 요소에 속성을 전달할 때 사용해요.
ptOptions InputSignal undefined 컴포넌트의 passthrough(pt) 옵션을 구성할 때 사용해요.
key string - confirm 객체의 키와 일치시키기 위한 선택적 키예요. 컴포넌트 트리에 confirm 다이얼로그가 여러 개 있을 때는 꼭 지정해야 해요.
defaultFocus string accept 팝업이 표시될 때 포커스를 받을 요소예요. 유효한 값은 "accept", "reject", "none"이에요.
showTransitionOptions string .12s cubic-bezier(0, 0, 0.2, 1) show 애니메이션의 트랜지션 옵션이에요. (지원 중단됨)
hideTransitionOptions string .1s linear hide 애니메이션의 트랜지션 옵션이에요. (지원 중단됨)
autoZIndex boolean true 레이어링을 자동으로 관리할지 여부예요.
baseZIndex number 0 레이어링에 사용할 기본 zIndex 값이에요.
style { [klass: string]: any } - 컴포넌트의 인라인 스타일이에요.
styleClass string - 컴포넌트의 스타일 클래스예요.
visible InputSignal ... 컴포넌트가 보이는지 여부를 정의해요.
motionOptions InputSignal ... 모션 옵션이에요.
appendTo InputSignal 'body' 오버레이를 붙일 대상 요소예요. 유효한 값은 "body" 또는 다른 요소의 지역 ng-template 변수예요 (참고: 템플릿 변수에는 대괄호를 사용한 바인딩을 쓰세요. 예를 들어 변수 이름이 #mydiv인 div 요소라면 [appendTo]="mydiv"처럼 지정해요).

템플릿

이름 타입 설명
content TemplateRef 커스텀 콘텐츠 템플릿이에요.
accepticon TemplateRef 커스텀 수락 아이콘 템플릿이에요.
rejecticon TemplateRef 커스텀 거절 아이콘 템플릿이에요.
headless TemplateRef 커스텀 headless 템플릿이에요.

Pass Through 옵션

이름 타입 설명
host PassThroughOption<HTMLElement, I> 호스트의 DOM 요소에 속성을 전달할 때 사용해요.
root PassThroughOption<HTMLDivElement, I> 루트의 DOM 요소에 속성을 전달할 때 사용해요.
content PassThroughOption<HTMLDivElement, I> 콘텐츠의 DOM 요소에 속성을 전달할 때 사용해요.
icon PassThroughOption<HTMLElement, I> 아이콘의 DOM 요소에 속성을 전달할 때 사용해요.
message PassThroughOption<HTMLSpanElement, I> 메시지의 DOM 요소에 속성을 전달할 때 사용해요.
footer PassThroughOption<HTMLDivElement, I> 푸터의 DOM 요소에 속성을 전달할 때 사용해요.
pcRejectButton ButtonPassThrough reject Button 컴포넌트에 속성을 전달할 때 사용해요.
pcAcceptButton ButtonPassThrough accept Button 컴포넌트에 속성을 전달할 때 사용해요.
motion MotionOptions motion 컴포넌트/디렉티브에 옵션을 전달할 때 사용해요.

테밍

CSS 클래스

클래스 설명
p-confirmpopup 루트 요소의 클래스 이름이에요
p-confirmpopup-content 콘텐츠 요소의 클래스 이름이에요
p-confirmpopup-icon 아이콘 요소의 클래스 이름이에요
p-confirmpopup-message 메시지 요소의 클래스 이름이에요
p-confirmpopup-footer 푸터 요소의 클래스 이름이에요
p-confirmpopup-reject-button 거절 버튼 요소의 클래스 이름이에요
p-confirmpopup-accept-button 수락 버튼 요소의 클래스 이름이에요

디자인 토큰

토큰 CSS 변수 설명
confirmpopup.background --p-confirmpopup-background 루트의 배경이에요
confirmpopup.border.color --p-confirmpopup-border-color 루트의 테두리 색상이에요
confirmpopup.color --p-confirmpopup-color 루트의 색상이에요
confirmpopup.border.radius --p-confirmpopup-border-radius 루트의 테두리 반경이에요
confirmpopup.shadow --p-confirmpopup-shadow 루트의 그림자예요
confirmpopup.gutter --p-confirmpopup-gutter 루트의 거터예요
confirmpopup.arrow.offset --p-confirmpopup-arrow-offset 루트의 화살표 오프셋이에요
confirmpopup.content.padding --p-confirmpopup-content-padding 콘텐츠의 패딩이에요
confirmpopup.content.gap --p-confirmpopup-content-gap 콘텐츠의 간격이에요
confirmpopup.icon.size --p-confirmpopup-icon-size 아이콘의 크기예요
confirmpopup.icon.color --p-confirmpopup-icon-color 아이콘의 색상이에요
confirmpopup.footer.gap --p-confirmpopup-footer-gap 푸터의 간격이에요
confirmpopup.footer.padding --p-confirmpopup-footer-padding 푸터의 패딩이에요

더 알아보기 (Learn more)

이 문서에는 원문에서 추출한 별도의 관련 문서 링크가 없어요.