포지셔닝, 포커스 관리, 외부 클릭으로 닫기(dismiss)를 지원하는 스타일 없는 팝오버 컴포넌트예요.
출처: 문서
본문
특징 (Features)
- 서브 컴포넌트(
Root, Trigger, Portal, Positioner, Popup, Arrow, Header, Title, Close, Content, Description, Footer)를 가진 복합 컴포넌트 API
- 구성 가능한
side, align, offset 옵션으로 트리거를 기준으로 자동 포지셔닝
- 선택적 포커스 트래핑과 함께 외부 클릭 및 escape 키로 닫기
- 트리거와의 시각적 연결을 위한 화살표(Arrow) 요소 지원
사용법 (Usage)
import { Popover } from 'primereact/popover';
<Popover.Root>
<Popover.Trigger></Popover.Trigger>
<Popover.Portal>
<Popover.Positioner side="bottom" sideOffset={8}>
<Popover.Popup>
<Popover.Arrow />
<Popover.Header>
<Popover.Title></Popover.Title>
<Popover.Close></Popover.Close>
</Popover.Header>
<Popover.Content>
<Popover.Description></Popover.Description>
</Popover.Content>
<Popover.Footer></Popover.Footer>
</Popover.Popup>
</Popover.Positioner>
</Popover.Portal>
</Popover.Root>
동작 (Behavior)
모션 애니메이션 (Motion Animation)
<Popover.Popup motionProps={{ name: 'p-popover' }}>...</Popover.Popup>
애니메이션 단계, CSS 변수, 숨김 전략에 대해서는 Motion을 참고하세요.
다형 렌더링 (Polymorphic Rendering)
어떤 서브 컴포넌트든 as를 사용해 렌더링되는 HTML 요소를 바꿀 수 있어요.
<Popover.Trigger as="div">...</Popover.Trigger>
렌더 함수 자식 (Render Function Children)
서브 컴포넌트는 자식으로 렌더 함수를 받아 컴포넌트 인스턴스에 접근할 수 있게 해줘요.
<Popover.Trigger>{(instance) => <span>{instance.popover?.state.open ? 'Close' : 'Open'}</span>}</Popover.Trigger>
Pass Through
<DocPTViewer name="popover-pt" components={['PopoverRoot']} />
API
PopoverRoot
| Label |
Type |
Description |
| root |
PopoverRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
| trigger |
PopoverRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the trigger's DOM element. |
| positioner |
PopoverRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the positioner's DOM element. |
| popup |
PopoverRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the popup's DOM element. |
| arrow |
PopoverRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the arrow's DOM element. |
| header |
PopoverRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the header's DOM element. |
| title |
PopoverRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the title's DOM element. |
| description |
PopoverRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the description's DOM element. |
| content |
PopoverRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the content's DOM element. |
| footer |
PopoverRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the footer's DOM element. |
| close |
PopoverRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the close's DOM element. |
PopoverTrigger
| Attribute |
Value |
data-positioner-open |
Present when popover is open |
| Label |
Type |
Description |
| root |
PopoverTriggerPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
PopoverPortal
| Label |
Type |
Description |
| root |
PopoverPortalPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
PopoverPositioner
| Attribute |
Value |
data-side |
"top" | "bottom" | "left" | "right", placement |
data-align |
"start" | "center" | "end", alignment |
CSS Custom Properties
포지셔너 요소는 레이아웃과 transform 제어를 위한 CSS 커스텀 프로퍼티를 노출해요.
| CSS Variable |
Description |
--available-height |
Available vertical space in pixels |
--available-width |
Available horizontal space in pixels |
--transform-origin |
Computed transform origin for animations |
--positioner-anchor-width |
Width of the anchor/trigger element |
| Label |
Type |
Description |
| root |
PopoverPositionerPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
| Attribute |
Value |
data-open |
Present when popover is open |
| Label |
Type |
Description |
| root |
PopoverPopupPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
PopoverArrow
| Attribute |
Value |
data-side |
"top" | "bottom" | "left" | "right", placement |
data-align |
"start" | "center" | "end", alignment |
CSS Custom Properties
화살표 요소는 동적 포지셔닝을 위한 CSS 커스텀 프로퍼티를 노출해요.
| CSS Variable |
Description |
--placer-arrow-x |
Horizontal offset of arrow |
--placer-arrow-y |
Vertical offset of arrow |
--placer-arrow-left |
Left position of arrow element |
--placer-arrow-top |
Top position of arrow element |
| Label |
Type |
Description |
| root |
PopoverArrowPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
| Label |
Type |
Description |
| root |
PopoverHeaderPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
PopoverTitle
| Label |
Type |
Description |
| root |
PopoverTitlePassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
PopoverClose
| Label |
Type |
Description |
| root |
PopoverClosePassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
PopoverContent
| Label |
Type |
Description |
| root |
PopoverContentPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
PopoverDescription
| Label |
Type |
Description |
| root |
PopoverDescriptionPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
| Label |
Type |
Description |
| root |
PopoverFooterPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
접근성 (Accessibility)
스크린 리더 (Screen Reader)
스크린 리더가 동작을 식별할 수 있도록 트리거 콘텐츠에 명확한 레이블을 사용하세요.
팝업 내부에 의미론적 구조를 제공하려면 Popover.Title과 선택적인 Popover.Description을 사용하세요.
트리거는 aria-expanded, aria-controls, aria-haspopup 같은 ARIA 속성으로 팝업 상태를 전달해요.
키보드 지원 (Keyboard Support)
| Key |
Function |
enter |
Activates the trigger button. |
space |
Activates the trigger button. |
escape |
Closes the popover when closeOnEscape is enabled. |
tab |
Moves focus to the next focusable element. |
shift + tab |
Moves focus to the previous focusable element. |
더 알아보기 (Learn more)