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

Vue ConfirmPopup 컴포넌트

원문 보기 위키 갱신

ConfirmPopup은 대상(target)을 기준으로 표시되는 확인 오버레이예요. 삭제 같은 중요한 작업 전에 버튼 옆에서 바로 확인을 받을 때 쓰기 좋아요.

출처: 문서

본문

Vue Confirmation Popup Component

ConfirmPopup displays a confirmation overlay displayed relatively to its target.

Import

import ConfirmPopup from 'primevue/confirmpopup';

Accessibility

Screen Reader ConfirmPopup 컴포넌트는 alertdialog role을 사용하고, 모든 속성이 루트 요소로 전달되기 때문에 팝업 내용을 설명하는 aria-label이나 aria-labelledby 같은 속성을 정의할 수 있어요. 또한 포커스가 팝업 안에 유지되기 때문에 aria-modal이 추가돼요. $confirm 인스턴스의 require 메서드를 사용하고 파라미터로 트리거를 전달하면, ConfirmPopup은 트리거와 대화상자의 관계를 정의하기 위해 트리거에 aria-expanded 상태 속성과 aria-controls를 추가해요. Overlay Keyboard Support Key Function tab 팝업 안의 다음 포커스 가능 요소로 포커스를 옮겨요. shift + tab 팝업 안의 이전 포커스 가능 요소로 포커스를 옮겨요. escape 팝업을 닫고 트리거로 포커스를 옮겨요. Buttons Keyboard Support Key Function enter 액션을 트리거하고, 팝업을 닫고, 트리거로 포커스를 옮겨요. space 액션을 트리거하고, 팝업을 닫고, 트리거로 포커스를 옮겨요.

Basic

ConfirmPopup은 $confirm 인스턴스의 require 메서드를 호출하면서 Popup을 커스터마이징하는 옵션을 전달해 표시해요. 팝업을 호출한 곳에 맞춰 정렬하려면 target 속성이 필수예요.

<ConfirmPopup></ConfirmPopup>
<Button @click="confirm1($event)" label="Save" variant="outlined"></Button>
<Button @click="confirm2($event)" label="Delete" severity="danger" variant="outlined"></Button>

ConfirmationServiceDoc

ConfirmPopup은 애플리케이션 플러그인으로 설치해야 하는 ConfirmationService를 통해 제어돼요.

Headless

container 슬롯을 정의하면 headless 모드가 활성화되어 기본 요소 대신 확인 UI 전체를 직접 구현할 수 있어요.

<ConfirmPopup group="headless">
    <template #container="{ message, acceptCallback, rejectCallback }">
        <div class="rounded p-4">
            <span>{{ message.message }}</span>
            <div class="flex items-center gap-2 mt-4">
                <Button label="Save" @click="acceptCallback" size="small"></Button>
                <Button label="Cancel" variant="outlined" @click="rejectCallback" severity="secondary" size="small" text></Button>
            </div>
        </div>
    </template>
</ConfirmPopup>
<Button @click="requireConfirmation($event)" label="Save"></Button>
Composition API Example
<template>
    <Toast />
    <ConfirmPopup group="headless">
        <template #container="{ message, acceptCallback, rejectCallback }">
            <div class="rounded p-4">
                <span>{{ message.message }}</span>
                <div class="flex items-center gap-2 mt-4">
                    <Button label="Save" @click="acceptCallback" size="small"></Button>
                    <Button label="Cancel" variant="outlined" @click="rejectCallback" severity="secondary" size="small" text></Button>
                </div>
            </div>
        </template>
    </ConfirmPopup>
    <div class="card flex justify-center">
        <Button @click="requireConfirmation($event)" label="Save"></Button>
    </div>
</template>

<script setup>
import { useConfirm } from "primevue/useconfirm";
import { useToast } from "primevue/usetoast";

const confirm = useConfirm();
const toast = useToast();

const requireConfirmation = (event) => {
    confirm.require({
        target: event.currentTarget,
        group: 'headless',
        message: 'Save your current process?',
        accept: () => {
            toast.add({severity:'info', summary:'Confirmed', detail:'You have accepted', life: 3000});
        },
        reject: () => {
            toast.add({severity:'error', summary:'Rejected', detail:'You have rejected', life: 3000});
        }
    });
}
<\/script>

Template

템플릿으로 메시지 콘텐츠를 커스터마이징할 수 있어요.

<ConfirmPopup group="templating">
    <template #message="slotProps">
        <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="slotProps.message.icon" class="!text-6xl text-primary-500"></i>
            <p>{{ slotProps.message.message }}</p>
        </div>
    </template>
</ConfirmPopup>
<Button @click="showTemplate($event)" label="Save"></Button>
Composition API Example
<template>
    <Toast />
    <ConfirmPopup group="templating">
        <template #message="slotProps">
            <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="slotProps.message.icon" class="!text-6xl text-primary-500"></i>
                <p>{{ slotProps.message.message }}</p>
            </div>
        </template>
    </ConfirmPopup>
    <div class="card flex justify-center">
        <Button @click="showTemplate($event)" label="Save"></Button>
    </div>
</template>

<script setup>
import { useConfirm } from "primevue/useconfirm";
import { useToast } from "primevue/usetoast";

const confirm = useConfirm();
const toast = useToast();

const showTemplate = (event) => {
    confirm.require({
        target: event.currentTarget,
        group: 'templating',
        message: 'Please confirm to proceed moving forward.',
        icon: 'pi pi-exclamation-circle',
        rejectProps: {
            icon: 'pi pi-times',
            label: 'Cancel',
            outlined: true
        },
        acceptProps: {
            icon: 'pi pi-check',
            label: 'Confirm'
        },
        accept: () => {
            toast.add({severity:'info', summary:'Confirmed', detail:'You have accepted', life: 3000});
        },
        reject: () => {
            toast.add({severity:'error', summary:'Rejected', detail:'You have rejected', life: 3000});
        }
    });
}
<\/script>

Confirm Popup

Props

Name Type Default Description
group string - Optional key to match the key of the confirmation, useful to target a specific confirm dialog instance.
dt any - It generates scoped CSS variables using design tokens for the component.
pt PassThrough - Used to pass attributes to DOM elements inside the component.
ptOptions any - Used to configure passthrough(pt) options of the component.
unstyled boolean false When enabled, it removes component related styles in the core.

Pass Through Options

Name Type Description
root ConfirmPopupPassThroughOptionType Used to pass attributes to the root's DOM element.
content ConfirmPopupPassThroughOptionType Used to pass attributes to the content's DOM element.
icon ConfirmPopupPassThroughOptionType Used to pass attributes to the icon's DOM element.
message ConfirmPopupPassThroughOptionType Used to pass attributes to the message's DOM element.
footer ConfirmPopupPassThroughOptionType Used to pass attributes to the footer's DOM element.
pcRejectButton any Used to pass attributes to the Button component.
pcAcceptButton any Used to pass attributes to the Button component.
hooks any Used to manage all lifecycle hooks.
transition ConfirmPopupPassThroughTransitionType Used to control Vue Transition API.

Theming

CSS Classes

Class Description
p-confirmpopup Class name of the root element
p-confirmpopup-content Class name of the content element
p-confirmpopup-icon Class name of the icon element
p-confirmpopup-message Class name of the message element
p-confirmpopup-footer Class name of the footer element
p-confirmpopup-reject-button Class name of the reject button element
p-confirmpopup-accept-button Class name of the accept button element

Design Tokens

Token CSS Variable Description
confirmpopup.background --p-confirmpopup-background Background of root
confirmpopup.border.color --p-confirmpopup-border-color Border color of root
confirmpopup.color --p-confirmpopup-color Color of root
confirmpopup.border.radius --p-confirmpopup-border-radius Border radius of root
confirmpopup.shadow --p-confirmpopup-shadow Shadow of root
confirmpopup.gutter --p-confirmpopup-gutter Gutter of root
confirmpopup.arrow.offset --p-confirmpopup-arrow-offset Arrow offset of root
confirmpopup.content.padding --p-confirmpopup-content-padding Padding of content
confirmpopup.content.gap --p-confirmpopup-content-gap Gap of content
confirmpopup.icon.size --p-confirmpopup-icon-size Size of icon
confirmpopup.icon.color --p-confirmpopup-icon-color Color of icon
confirmpopup.footer.gap --p-confirmpopup-footer-gap Gap of footer
confirmpopup.footer.padding --p-confirmpopup-footer-padding Padding of footer

더 알아보기 (Learn more)