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

Button — 버튼

원문 보기 위키 갱신

복합(compound) 구성과 그룹 지원이 있는 스타일 없는 버튼 컴포넌트예요.

출처: 문서

본문

레이아웃과 스타일링을 완전히 제어하며 완전히 커스텀한 버튼 요소를 만들어 보세요.

기능 (Features)

  • 여러 버튼을 묶는 ButtonGroup을 제공하는 단일 컴포넌트
  • 전체 HTML 속성 지원을 갖춘 네이티브 <button> 의미론
  • children을 통한 아이콘 구성 — 텍스트 앞이나 뒤에 아이콘 컴포넌트를 배치해요

사용법 (Usage)

import { Button } from 'primereact/button';
import { ButtonGroup } from 'primereact/buttongroup';
<Button></Button>

<ButtonGroup>
    <Button></Button>
    <Button></Button>
</ButtonGroup>

동작 (Behavior)

아이콘 구성 (Icon Composition)

아이콘 컴포넌트를 텍스트와 함께 children으로 배치해요. DOM 순서가 아이콘 위치를 결정해요.

import { Check } from '@primeicons/react/check';

/* Icon before text */
<Button>
    <Check />
    Confirm
</Button>;

/* Icon after text */
<Button>
    Save
    <Check />
</Button>;

다형성 렌더링 (Polymorphic Rendering)

as를 사용해 렌더링되는 HTML 요소를 바꾸거나 커스텀 React 컴포넌트를 사용해요.

<Button as="a" href="/home">
    Home
</Button>

렌더 함수 children (Render Function Children)

Button은 children으로 렌더 함수를 받아 컴포넌트 인스턴스에 접근할 수 있게 해줘요.

<Button>{(instance) => <span>Custom render</span>}</Button>

패스 스루 (Pass Through)

<DocPTViewer name="button-pt" components={['Button']} />

API

Button

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

접근성 (Accessibility)

스크린 리더 (Screen Reader)

Button은 기본적으로 네이티브 <button> 요소를 렌더링하고 내장 의미론을 사용해요. 보이는 텍스트, aria-label, 또는 aria-labelledby로 접근 가능한 이름을 제공해요. 아이콘 전용 버튼은 접근 가능한 이름을 보장하기 위해 aria-label을 반드시 사용해야 해요.

키보드 지원 (Keyboard Support)

Key Function
tab Moves focus to button.
enter Activates the button.
space Activates the button.

더 알아보기 (Learn more)