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

Tabs

원문 보기 위키 갱신

키보드 탐색과 스크롤 가능한 오버플로 지원을 가진 스타일 없는 탭 컴포넌트예요.

출처: 문서

본문

특징 (Features)

  • 서브 컴포넌트(Root, List, Content, Tab, Indicator, Panels, Panel, Prev, Next)를 가진 복합 컴포넌트 API
  • 화살표 키, Home, End로 탭 사이를 자동으로 순환하는 키보드 포커스
  • 애니메이션 포지셔닝을 위한 CSS 커스텀 프로퍼티를 가진 활성 바(active bar) 표시기(Indicator)
  • 오버플로 탭 리스트를 위한 Prev/Next 버튼의 내장 스크롤 탐색
  • 구성 가능한 스크롤 전략: nearest, center, disabled 또는 커스텀 함수

사용법 (Usage)

import { Tabs } from 'primereact/tabs';
<Tabs.Root defaultValue="tab1">
    <Tabs.List>
        <Tabs.Prev></Tabs.Prev>
        <Tabs.Content>
            <Tabs.Tab value="tab1"></Tabs.Tab>
            <Tabs.Indicator />
        </Tabs.Content>
        <Tabs.Next></Tabs.Next>
    </Tabs.List>
    <Tabs.Panels>
        <Tabs.Panel value="tab1"></Tabs.Panel>
    </Tabs.Panels>
</Tabs.Root>

동작 (Behavior)

다형 렌더링 (Polymorphic Rendering)

어떤 서브 컴포넌트든 as를 사용해 렌더링되는 HTML 요소를 바꿀 수 있어요.

<Tabs.Root as="section">
    <Tabs.List as="nav">...</Tabs.List>
</Tabs.Root>

렌더 함수 자식 (Render Function Children)

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

<Tabs.Tab value="tab1">{(instance) => <span className={instance.active ? 'active' : ''}>{instance.props.value}</span>}</Tabs.Tab>

Pass Through

<DocPTViewer name="tabs-pt" components={['TabsRoot']} />

API

TabsRoot

Label Type Description
root TabsRootPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.
list TabsRootPassThroughType<HTMLAttributes> Used to pass attributes to the list's DOM element.
content TabsRootPassThroughType<HTMLAttributes> Used to pass attributes to the content's DOM element.
tab TabsRootPassThroughType<HTMLAttributes> Used to pass attributes to the tab's DOM element.
indicator TabsRootPassThroughType<HTMLAttributes> Used to pass attributes to the indicator's DOM element.
panels TabsRootPassThroughType<HTMLAttributes> Used to pass attributes to the panels' DOM element.
panel TabsRootPassThroughType<HTMLAttributes> Used to pass attributes to the panel's DOM element.
prev TabsRootPassThroughType<HTMLAttributes> Used to pass attributes to the prev button's DOM element.
next TabsRootPassThroughType<HTMLAttributes> Used to pass attributes to the next button's DOM element.

TabsList

Label Type Description
root TabsListPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

TabsContent

Label Type Description
root TabsContentPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

TabsTab

Attribute Value
data-active Present when active
data-disabled Present when disabled
Label Type Description
root TabsTabPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

TabsIndicator

CSS Custom Properties

표시기(Indicator) 요소는 활성 탭을 기준으로 한 애니메이션 포지셔닝을 위한 CSS 커스텀 프로퍼티를 노출해요.

CSS Variable Description
--active-bar-width Width of the active tab in pixels
--active-bar-height Height of the active tab in pixels
--active-bar-left Left offset of the active tab
--active-bar-top Top offset of the active tab
Label Type Description
root TabsIndicatorPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

TabsPanels

Label Type Description
root TabsPanelsPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

TabsPanel

Attribute Value
data-active Present when active
Label Type Description
root TabsPanelPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

TabsPrev

Attribute Value
data-disabled Present when disabled
Label Type Description
root TabsPrevPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

TabsNext

Attribute Value
data-disabled Present when disabled
Label Type Description
root TabsNextPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

접근성 (Accessibility)

스크린 리더 (Screen Reader)

Tabs는 탭 컨테이너에 role="tablist", 각 탭 트리거에 role="tab", 각 패널에 role="tabpanel"을 사용해요. 활성 탭은 aria-selected="true"를 설정해요. 패널은 aria-controls와 aria-labelledby로 자신의 탭과 연결돼요. 비활성 탭은 aria-disabled="true"를 설정해요.

키보드 지원 (Keyboard Support)

Key Function
tab Moves focus into the tab list, then to the panel.
right arrow Moves focus to the next tab.
left arrow Moves focus to the previous tab.
home Moves focus to the first tab.
end Moves focus to the last tab.
enter Activates the focused tab.
space Activates the focused tab.

더 알아보기 (Learn more)