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

Message

원문 보기 위키 갱신

Message는 닫기(close)와 자동 숨김(auto-dismiss)을 지원하는 인라인 알림 표시용 styled가 없는 메시지 컴포넌트예요. 레이아웃과 스타일을 완전히 제어해 커스텀한 인라인 메시지를 만들 수 있어요.

출처: 문서

본문

기능 (Features)

  • 5개의 하위 컴포넌트(Root, Content, Icon, Text, Close)로 구성된 compound 컴포넌트 API
  • 설정 가능한 life 시간으로 자동 닫힘
  • 닫힘(dismissal) 시 close 콜백

사용법 (Usage)

import { Message } from 'primereact/message';
<Message.Root>
    <Message.Content>
        <Message.Icon />
        <Message.Text></Message.Text>
        <Message.Close />
    </Message.Content>
</Message.Root>

동작 (Behavior)

다형적 렌더링 (Polymorphic Rendering)

아무 하위 컴포넌트에 as를 사용해 렌더링되는 HTML 요소를 바꿀 수 있어요.

<Message.Root as="section"></Message.Root>
<Message.Text as="span"></Message.Text>

기본 요소: Root=div, Content=div, Icon=span, Text=p, Close=button.

렌더 함수 자식 (Render Function Children)

하위 컴포넌트는 렌더 함수를 자식으로 받아 컴포넌트 인스턴스에 접근할 수 있게 해 줘요.

<Message.Text>{(instance) => <span>{instance.message?.state.visible ? 'Visible' : 'Hidden'}</span>}</Message.Text>

패스 스루 (Pass Through)

<DocPTViewer name="message-pt" components={['MessageRoot']} />

API

MessageRoot

Attribute Value
data-scope "message"
data-part "root"
Label Type Description
root MessageRootPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.
content MessageRootPassThroughType<HTMLAttributes> Used to pass attributes to the content's DOM element.
icon MessageRootPassThroughType<HTMLAttributes> Used to pass attributes to the icon's DOM element.
text MessageRootPassThroughType<HTMLAttributes> Used to pass attributes to the text's DOM element.
close MessageRootPassThroughType<HTMLAttributes> Used to pass attributes to the close's DOM element.

MessageContent

Attribute Value
data-scope "message"
data-part "content"
Label Type Description
root MessageContentPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

MessageIcon

Attribute Value
data-scope "message"
data-part "icon"
Label Type Description
root MessageIconPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

MessageText

Attribute Value
data-scope "message"
data-part "text"
Label Type Description
root MessageTextPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

MessageClose

Attribute Value
data-scope "message"
data-part "close"
Label Type Description
root MessageClosePassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

접근성 (Accessibility)

스크린 리더 (Screen Reader)

Message는 alert 역할을 사용하며, 이는 암묵적으로 aria-live="assertive"와 aria-atomic="true"를 설정해 메시지 내용이 스크린 리더에 의해 즉시 발표되도록 보장해요. 닫기 버튼은 네이티브 <button> 요소이며, 접근 가능한 라벨을 위해 aria-label을 제공해 주세요.

키보드 지원 (Keyboard Support)

Key Function
tab Moves focus to the close button.
enter Closes the message.
space Closes the message.

더 알아보기 (Learn more)