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

탭

원문 보기 위키 갱신

탭 (Tabs)

같은 페이지에서 관련 패널 사이를 전환하는 고품질의 비스타일 React 탭 컴포넌트예요.

출처: Base UI Tabs

본문

같은 페이지에서 관련 패널 사이를 전환하기 위한 고품질의 비스타일 React 탭 컴포넌트예요.

데모 (Demo)

Tailwind

이 예시는 Tailwind CSS로 컴포넌트를 구현하는 방법을 보여줘요.

/* index.tsx */
import { Tabs } from '@base-ui/react/tabs';

const tabClassName =
  'flex h-[calc(2rem+1px)] items-center justify-center bg-transparent px-2 py-0 font-inherit text-sm font-normal leading-5 break-keep whitespace-nowrap text-neutral-600 outline-none select-none hover:text-neutral-950 focus-visible:outline-2 focus-visible:outline-solid focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white data-active:text-neutral-950 dark:text-neutral-300 dark:hover:text-white dark:data-active:text-white';

const panelClassName =
  'col-start-1 row-start-1 flex w-full items-center justify-center bg-white p-4 text-center text-sm text-neutral-950 outline-none focus-visible:z-1 focus-visible:outline-2 focus-visible:outline-solid focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white dark:bg-neutral-950 dark:text-white [[hidden]]:hidden';

export default function ExampleTabs() {
  return (
    <Tabs.Root className="w-full max-w-xs" defaultValue="overview">
      <Tabs.List className="relative z-1 -mb-px flex gap-1">
        <Tabs.Tab className={tabClassName} value="overview">
          Overview
        </Tabs.Tab>
        <Tabs.Tab className={tabClassName} value="projects">
          Projects
        </Tabs.Tab>
        <Tabs.Tab className={tabClassName} value="account">
          Account
        </Tabs.Tab>
        <Tabs.Indicator className="absolute top-0 left-0 -z-1 h-full w-(--active-tab-width) translate-x-(--active-tab-left) border-x border-t border-neutral-950 bg-white transition-[translate,width] duration-150 ease-in-out dark:border-white dark:bg-neutral-950" />
      </Tabs.List>
      <div className="grid w-full min-h-32 grid-cols-1 border border-neutral-950 dark:border-white">
        <Tabs.Panel className={panelClassName} value="overview">
          <p>Workspace stats and activity.</p>
        </Tabs.Panel>
        <Tabs.Panel className={panelClassName} value="projects">
          <p>Milestones and deadlines.</p>
        </Tabs.Panel>
        <Tabs.Panel className={panelClassName} value="account">
          <p>Profile and preferences.</p>
        </Tabs.Panel>
      </div>
    </Tabs.Root>
  );
}

CSS Modules

이 예시는 CSS Modules로 컴포넌트를 구현하는 방법을 보여줘요.

/* index.module.css */
.Root {
  box-sizing: border-box;
  width: 100%;
  max-width: 20rem;
}

.List {
  display: flex;
  position: relative;
  z-index: 1;
  gap: 0.25rem;
  margin-bottom: -1px;
}

.Tab {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  margin: 0;
  outline: 0;
  background: none;
  color: oklch(43.9% 0 0deg);
  font-family: inherit;
  font-size: 0.875rem;
  line-height: 1.25rem;
  font-weight: 400;
  -webkit-user-select: none;
  user-select: none;
  white-space: nowrap;
  word-break: keep-all;
  padding-inline: 0.5rem;
  padding-block: 0;
  height: calc(2rem + 1px);

  @media (prefers-color-scheme: dark) {
    color: oklch(87% 0 0deg);
  }

  @media (hover: hover) {
    &:hover {
      color: oklch(14.5% 0 0deg);

      @media (prefers-color-scheme: dark) {
        color: white;
      }
    }
  }

  &[data-active] {
    color: oklch(14.5% 0 0deg);

    @media (prefers-color-scheme: dark) {
      color: white;
    }
  }

  &:focus-visible {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: -1px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}

.Indicator {
  box-sizing: border-box;
  position: absolute;
  z-index: -1;
  left: 0;
  top: 0;
  translate: var(--active-tab-left);
  width: var(--active-tab-width);
  height: 100%;
  transition-property: translate, width;
  transition-duration: 150ms;
  transition-timing-function: ease-in-out;
  border-top: 1px solid oklch(14.5% 0 0deg);
  border-inline: 1px solid oklch(14.5% 0 0deg);
  background-color: white;

  @media (prefers-color-scheme: dark) {
    border-top: 1px solid white;
    border-inline: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
  }
}

.PanelViewport {
  box-sizing: border-box;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  width: 100%;
  min-height: 8rem;
  border-inline: 1px solid oklch(14.5% 0 0deg);
  border-block: 1px solid oklch(14.5% 0 0deg);

  @media (prefers-color-scheme: dark) {
    border-inline: 1px solid white;
    border-block: 1px solid white;
  }
}

.Panel {
  box-sizing: border-box;
  grid-area: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 1rem;

  outline: 0;
  font-size: 0.875rem;
  line-height: 1.25rem;
  text-align: center;
  color: oklch(14.5% 0 0deg);
  background-color: white;

  @media (prefers-color-scheme: dark) {
    color: white;
    background-color: oklch(14.5% 0 0deg);
  }

  &:focus-visible {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: -1px;
    z-index: 1;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }

  &[hidden] {
    display: none;
  }
}

.Paragraph {
  margin: 0;
}
/* index.tsx */
import { Tabs } from '@base-ui/react/tabs';
import styles from './index.module.css';

export default function ExampleTabs() {
  return (
    <Tabs.Root className={styles.Root} defaultValue="overview">
      <Tabs.List className={styles.List}>
        <Tabs.Tab className={styles.Tab} value="overview">
          Overview
        </Tabs.Tab>
        <Tabs.Tab className={styles.Tab} value="projects">
          Projects
        </Tabs.Tab>
        <Tabs.Tab className={styles.Tab} value="account">
          Account
        </Tabs.Tab>
        <Tabs.Indicator className={styles.Indicator} />
      </Tabs.List>
      <div className={styles.PanelViewport}>
        <Tabs.Panel className={styles.Panel} value="overview">
          <p className={styles.Paragraph}>Workspace stats and activity.</p>
        </Tabs.Panel>
        <Tabs.Panel className={styles.Panel} value="projects">
          <p className={styles.Paragraph}>Milestones and deadlines.</p>
        </Tabs.Panel>
        <Tabs.Panel className={styles.Panel} value="account">
          <p className={styles.Paragraph}>Profile and preferences.</p>
        </Tabs.Panel>
      </div>
    </Tabs.Root>
  );
}

구조 (Anatomy)

컴포넌트를 임포트하고 파트들을 조립하세요.

import { Tabs } from '@base-ui/react/tabs';

<Tabs.Root>
  <Tabs.List>
    <Tabs.Tab />
    <Tabs.Indicator />
  </Tabs.List>
  <Tabs.Panel />
</Tabs.Root>;

예시 (Examples)

애니메이션 패널 (Animated panels)

패널이 활성화될 때 data-starting-style과 data-ending-style 속성을 사용해 애니메이션을 적용할 수 있어요. data-activation-direction 속성은 새로 활성화된 탭이 이전 활성 탭과 비교해 어느 방향에 있는지 나타내므로, 패널이 올바른 쪽에서 슬라이드되어 들어올 수 있어요.

데모 (Demo)

Tailwind

이 예시는 Tailwind CSS로 컴포넌트를 구현하는 방법을 보여줘요.

/* index.tsx */
import { Tabs } from '@base-ui/react/tabs';

export default function ExampleAnimatedTabs() {
  return (
    <Tabs.Root className="w-full max-w-xs" defaultValue="overview">
      <Tabs.List className="relative z-1 -mb-px flex gap-1">
        <Tabs.Tab className={tabClassName} value="overview">
          Overview
        </Tabs.Tab>
        <Tabs.Tab className={tabClassName} value="projects">
          Projects
        </Tabs.Tab>
        <Tabs.Tab className={tabClassName} value="account">
          Account
        </Tabs.Tab>
        <Tabs.Indicator className="absolute top-0 left-0 -z-1 h-full w-(--active-tab-width) translate-x-(--active-tab-left) border-x border-t border-neutral-950 bg-white transition-[translate,width] duration-150 ease-in-out dark:border-white dark:bg-neutral-950" />
      </Tabs.List>
      <div className="relative grid min-h-32 w-full grid-cols-1 overflow-hidden border border-neutral-950 bg-white dark:border-white dark:bg-neutral-950">
        <Tabs.Panel className={panelClassName} value="overview">
          <p>Workspace stats and activity.</p>
        </Tabs.Panel>
        <Tabs.Panel className={panelClassName} value="projects">
          <p>Milestones and deadlines.</p>
        </Tabs.Panel>
        <Tabs.Panel className={panelClassName} value="account">
          <p>Profile and preferences.</p>
        </Tabs.Panel>
      </div>
    </Tabs.Root>
  );
}

const tabClassName =
  'flex h-[calc(2rem+1px)] items-center justify-center bg-transparent px-2 py-0 font-inherit text-sm font-normal leading-5 break-keep whitespace-nowrap text-neutral-600 outline-none select-none hover:text-neutral-950 focus-visible:outline-2 focus-visible:outline-solid focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white data-active:text-neutral-950 dark:text-neutral-300 dark:hover:text-white dark:data-active:text-white';

const panelClassName =
  'col-start-1 row-start-1 flex w-full items-center justify-center p-4 text-center text-sm text-neutral-950 outline-none focus-visible:z-1 focus-visible:outline-2 focus-visible:outline-solid focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white dark:text-white ' +
  '[transition:opacity_175ms_ease,translate_350ms_cubic-bezier(0.22,1,0.36,1)] ' +
  'data-starting-style:opacity-0 data-ending-style:opacity-0 ' +
  'motion-safe:data-starting-style:data-[activation-direction=left]:translate-x-[-50%] ' +
  'motion-safe:data-starting-style:data-[activation-direction=right]:translate-x-[50%] ' +
  'motion-safe:data-ending-style:data-[activation-direction=left]:translate-x-[50%] ' +
  'motion-safe:data-ending-style:data-[activation-direction=right]:translate-x-[-50%]';

CSS Modules

이 예시는 CSS Modules로 컴포넌트를 구현하는 방법을 보여줘요.

/* index.module.css */
.Root {
  box-sizing: border-box;
  width: 100%;
  max-width: 20rem;
}

.List {
  display: flex;
  position: relative;
  z-index: 1;
  gap: 0.25rem;
  margin-bottom: -1px;
}

.Tab {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  margin: 0;
  outline: 0;
  background: none;
  color: oklch(43.9% 0 0deg);
  font-family: inherit;
  font-size: 0.875rem;
  line-height: 1.25rem;
  font-weight: 400;
  -webkit-user-select: none;
  user-select: none;
  white-space: nowrap;
  word-break: keep-all;
  padding-inline: 0.5rem;
  padding-block: 0;
  height: calc(2rem + 1px);

  @media (prefers-color-scheme: dark) {
    color: oklch(87% 0 0deg);
  }

  @media (hover: hover) {
    &:hover {
      color: oklch(14.5% 0 0deg);

      @media (prefers-color-scheme: dark) {
        color: white;
      }
    }
  }

  &[data-active] {
    color: oklch(14.5% 0 0deg);

    @media (prefers-color-scheme: dark) {
      color: white;
    }
  }

  &:focus-visible {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: -1px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}

.Indicator {
  box-sizing: border-box;
  position: absolute;
  z-index: -1;
  left: 0;
  top: 0;
  translate: var(--active-tab-left);
  width: var(--active-tab-width);
  height: 100%;
  transition-property: translate, width;
  transition-duration: 150ms;
  transition-timing-function: ease-in-out;
  border-top: 1px solid oklch(14.5% 0 0deg);
  border-inline: 1px solid oklch(14.5% 0 0deg);
  background-color: white;

  @media (prefers-color-scheme: dark) {
    border-top: 1px solid white;
    border-inline: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
  }
}

.PanelViewport {
  box-sizing: border-box;
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  width: 100%;
  min-height: 8rem;
  overflow: hidden;
  border-inline: 1px solid oklch(14.5% 0 0deg);
  border-block: 1px solid oklch(14.5% 0 0deg);
  background-color: white;

  @media (prefers-color-scheme: dark) {
    border-inline: 1px solid white;
    border-block: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
  }
}

.Panel {
  box-sizing: border-box;
  grid-area: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 1rem;

  outline: 0;
  font-size: 0.875rem;
  line-height: 1.25rem;
  text-align: center;
  color: oklch(14.5% 0 0deg);

  transition:
    opacity 175ms ease,
    transform 350ms cubic-bezier(0.22, 1, 0.36, 1);

  @media (prefers-color-scheme: dark) {
    color: white;
  }

  &:focus-visible {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: -1px;
    z-index: 1;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }

  &[data-starting-style],
  &[data-ending-style] {
    opacity: 0;
  }

  @media (prefers-reduced-motion: no-preference) {
    &[data-starting-style] {
      &[data-activation-direction='left'] {
        transform: translateX(-50%);
      }
      &[data-activation-direction='right'] {
        transform: translateX(50%);
      }
    }

    &[data-ending-style] {
      &[data-activation-direction='left'] {
        transform: translateX(50%);
      }
      &[data-activation-direction='right'] {
        transform: translateX(-50%);
      }
    }
  }
}

.Paragraph {
  margin: 0;
}
/* index.tsx */
import { Tabs } from '@base-ui/react/tabs';
import styles from './index.module.css';

export default function ExampleAnimatedTabs() {
  return (
    <Tabs.Root className={styles.Root} defaultValue="overview">
      <Tabs.List className={styles.List}>
        <Tabs.Tab className={styles.Tab} value="overview">
          Overview
        </Tabs.Tab>
        <Tabs.Tab className={styles.Tab} value="projects">
          Projects
        </Tabs.Tab>
        <Tabs.Tab className={styles.Tab} value="account">
          Account
        </Tabs.Tab>
        <Tabs.Indicator className={styles.Indicator} />
      </Tabs.List>
      <div className={styles.PanelViewport}>
        <Tabs.Panel className={styles.Panel} value="overview">
          <p className={styles.Paragraph}>Workspace stats and activity.</p>
        </Tabs.Panel>
        <Tabs.Panel className={styles.Panel} value="projects">
          <p className={styles.Paragraph}>Milestones and deadlines.</p>
        </Tabs.Panel>
        <Tabs.Panel className={styles.Panel} value="account">
          <p className={styles.Paragraph}>Profile and preferences.</p>
        </Tabs.Panel>
      </div>
    </Tabs.Root>
  );
}

<Tabs.Tab>에서 render prop을 사용하고 nativeButton={false}를 설정하면 탭을 앵커 요소로 렌더링할 수 있어요.

import { Tabs } from '@base-ui/react/tabs';
import Link from 'next/link';

<Tabs.Root>
  <Tabs.List>
    {/* @highlight-start */}
    {/* @highlight-text "nativeButton={false}" "render" */}
    <Tabs.Tab nativeButton={false} render={<Link href="/overview" />} value="overview">
      Overview
    </Tabs.Tab>
    {/* @highlight-end */}
  </Tabs.List>
  {/* ... */}
</Tabs.Root>;

API 레퍼런스 (API reference)

Root

탭과 해당 패널들을 그룹화해요. <div> 요소를 렌더링해요.

Root Props:

Prop Type Default Description
defaultValue Tabs.Tab.Value 0 기본값이에요. 컴포넌트가 비제어일 때 사용하세요. 값이 null이면 활성 탭이 없어요.
value Tabs.Tab.Value - 현재 활성 Tab의 값이에요. 컴포넌트가 제어일 때 사용하세요. 값이 null이면 활성 탭이 없어요.
onValueChange ((value: Tabs.Tab.Value, eventDetails: Tabs.Root.ChangeEventDetails) => void) - 새 값이 설정될 때 호출되는 콜백이에요. 이벤트 reason은 클릭이나 키보드 내비게이션 같은 사용자 시작 변경의 경우 'none'이고, 비제어 root에서 defaultValue를 생략하거나 undefined로 둘 때(암시적 초기값이 비활성화되거나 없을 때 포함)의 첫 번째 자동 선택 또는 폴백의 경우 'initial', 비제어 root에서 선택된 탭이 비활성화됐을 때 자동 폴백의 경우 'disabled', 선택된 탭이 제거되거나 명시적 defaultValue가 비제어 root에서 마운트된 탭과 결코 일치하지 않을 때 자동 폴백의 경우 'missing'이에요. 자동 변경의 경우 폴백으로 사용 가능한 활성화된 Tab이 없으면 선택된 값이 null일 수 있어요. 자동 변경은 취소할 수 없어요. 'initial', 'disabled', 'missing'의 경우 eventDetails.cancel()을 호출해도 효과가 없어요.
orientation Tabs.Root.Orientation 'horizontal' 컴포넌트의 방향(레이아웃 흐름 방향)이에요.
className string | ((state: Tabs.Root.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태를 기반으로 클래스를 반환하는 함수예요.
style React.CSSProperties | ((state: Tabs.Root.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태를 기반으로 스타일 객체를 반환하는 함수예요.
render ReactElement | ((props: HTMLProps, state: Tabs.Root.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Root Data Attributes:

Attribute Type Description
data-orientation 'horizontal' | 'vertical' 탭의 방향을 나타내요.
data-activation-direction 'left' | 'right' | 'up' | 'down' | 'none' 활성화 방향(이전 활성 탭 기준)을 나타내요.

Root.Props

Root props의 재내보내기(re-export)예요.

Root.State

type TabsRootState = {
  /** The component orientation. */
  orientation: Tabs.Root.Orientation;
  /** The direction used for tab activation. */
  tabActivationDirection: Tabs.Tab.ActivationDirection;
};

Root.ChangeEventReason

type TabsRootChangeEventReason = 'none' | 'disabled' | 'missing' | 'initial';

Root.ChangeEventDetails

type TabsRootChangeEventDetails = (
  { reason: 'none' } | { reason: 'disabled' } | { reason: 'missing' } | { reason: 'initial' }
) & {
  /** The native event associated with the custom event. */
  event: Event;
  /** Cancels Base UI from handling the event. */
  cancel: () => void;
  /** Allows the event to propagate in cases where Base UI will stop the propagation. */
  allowPropagation: () => void;
  /** Indicates whether the event has been canceled. */
  isCanceled: boolean;
  /** Indicates whether the event is allowed to propagate. */
  isPropagationAllowed: boolean;
  /** The element that triggered the event, if applicable. */
  trigger: Element | undefined;
  activationDirection: Tabs.Tab.ActivationDirection;
};

Root.Orientation

type TabsRootOrientation = 'horizontal' | 'vertical';

List

개별 탭 버튼들을 그룹화해요. <div> 요소를 렌더링해요.

List Props:

Prop Type Default Description
activateOnFocus boolean false 화살표 키 포커스 시 활성 탭을 자동으로 변경할지 여부예요. 그렇지 않으면 Enter 또는 Space 키를 눌러 탭을 활성화해요.
loopFocus boolean true 화살표 키로 목록의 끝에 도달했을 때 키보드 포커스를 첫 번째 항목으로 순환할지 여부예요.
className string | ((state: Tabs.List.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태를 기반으로 클래스를 반환하는 함수예요.
style React.CSSProperties | ((state: Tabs.List.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태를 기반으로 스타일 객체를 반환하는 함수예요.
render ReactElement | ((props: HTMLProps, state: Tabs.List.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

List Data Attributes:

Attribute Type Description
data-orientation 'horizontal' | 'vertical' 탭의 방향을 나타내요.
data-activation-direction 'left' | 'right' | 'up' | 'down' | 'none' 활성화 방향(이전 활성 탭 기준)을 나타내요.

List.Props

List props의 재내보내기(re-export)예요.

List.State

type TabsListState = {
  /** The component orientation. */
  orientation: Tabs.Root.Orientation;
  /** The direction used for tab activation. */
  tabActivationDirection: Tabs.Tab.ActivationDirection;
};

Panel

해당 탭이 활성화됐을 때 표시되는 패널이에요. <div> 요소를 렌더링해요.

Panel Props:

Prop Type Default Description
value* Tabs.Tab.Value - TabPanel의 값이에요. 해당 값의 Tab이 활성화됐을 때 표시돼요.
className string | ((state: Tabs.Panel.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태를 기반으로 클래스를 반환하는 함수예요.
style React.CSSProperties | ((state: Tabs.Panel.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태를 기반으로 스타일 객체를 반환하는 함수예요.
keepMounted boolean false 패널이 숨겨져 있는 동안 HTML 요소를 DOM에 유지할지 여부예요.
render ReactElement | ((props: HTMLProps, state: Tabs.Panel.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Panel Data Attributes:

Attribute Type Description
data-orientation 'horizontal' | 'vertical' 탭의 방향을 나타내요.
data-activation-direction 'left' | 'right' | 'up' | 'down' | 'none' 활성화 방향(이전 활성 탭 기준)을 나타내요.
data-hidden - 패널이 숨겨져 있을 때 존재해요.
data-index - 탭 패널의 인덱스를 나타내요.
data-starting-style - 패널이 들어오는 애니메이션을 시작할 때 존재해요.
data-ending-style - 패널이 나가는 애니메이션 중일 때 존재해요.

Panel.Props

Panel props의 재내보내기(re-export)예요.

Panel.State

type TabsPanelState = {
  /** Whether the component is hidden. */
  hidden: boolean;
  /** The transition status of the component. */
  transitionStatus: TransitionStatus;
  /** The component orientation. */
  orientation: Tabs.Root.Orientation;
  /** The direction used for tab activation. */
  tabActivationDirection: Tabs.Tab.ActivationDirection;
};

Panel.Metadata

type TabsPanelMetadata = { id?: string; value: Tabs.Tab.Value };

Indicator

현재 활성 탭의 위치에 맞게 스타일링할 수 있는 시각적 표시자예요. <span> 요소를 렌더링해요.

Indicator Props:

Prop Type Default Description
renderBeforeHydration boolean false React가 하이드레이션되기 전에 자신을 렌더링할지 여부예요. 이렇게 하면 서버 사이드 렌더링 후 지표가 보이지 않는 시간을 최소화해요.
className string | ((state: Tabs.Indicator.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태를 기반으로 클래스를 반환하는 함수예요.
style React.CSSProperties | ((state: Tabs.Indicator.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태를 기반으로 스타일 객체를 반환하는 함수예요.
render ReactElement | ((props: HTMLProps, state: Tabs.Indicator.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Indicator Data Attributes:

Attribute Type Description
data-orientation 'horizontal' | 'vertical' 탭의 방향을 나타내요.
data-activation-direction 'left' | 'right' | 'up' | 'down' | 'none' 활성화 방향(이전 활성 탭 기준)을 나타내요.

Indicator CSS Variables:

Variable Type Description
--active-tab-bottom number 탭이 활성화됐을 때 부모 컨테이너의 아래쪽으로부터의 거리를 나타내요.
--active-tab-height number 탭이 활성화됐을 때의 탭 높이를 나타내요.
--active-tab-left number 탭이 활성화됐을 때 부모 컨테이너의 왼쪽으로부터의 거리를 나타내요.
--active-tab-right number 탭이 활성화됐을 때 부모 컨테이너의 오른쪽으로부터의 거리를 나타내요.
--active-tab-top number 탭이 활성화됐을 때 부모 컨테이너의 위쪽으로부터의 거리를 나타내요.
--active-tab-width number 탭이 활성화됐을 때의 탭 너비를 나타내요.

Indicator.Props

Indicator props의 재내보내기(re-export)예요.

Indicator.State

type TabsIndicatorState = {
  /** The active tab position. */
  activeTabPosition: Tabs.Tab.Position | null;
  /** The active tab size. */
  activeTabSize: Tabs.Tab.Size | null;
  /** The component orientation. */
  orientation: Tabs.Root.Orientation;
  /** The direction used for tab activation. */
  tabActivationDirection: Tabs.Tab.ActivationDirection;
};

Tab

해당 패널을 토글하는 개별 대화형 탭 버튼이에요. <button> 요소를 렌더링해요.

Tab Props:

Prop Type Default Description
value* Tabs.Tab.Value - Tab의 값이에요.
nativeButton boolean true render prop으로 요소를 대체할 때 네이티브 <button> 요소를 렌더링할지 여부예요. 렌더링되는 요소가 버튼이 아닐 때(예: <div>) false로 설정하세요.
disabled boolean - Tab이 비활성화됐는지 여부예요. <Tabs.List>의 첫 Tab이 비활성화되면 처음에 선택되지 않아요. 대신 다음 활성화된 Tab이 선택돼요. 단, 사전 렌더링 중에는 어떤 Tab이 비활성화됐는지 알 수 없으므로 서버 사이드 렌더링에서는 이렇게 동작하지 않아요. 이를 우회하려면 <Tabs.Root>의 defaultValue 또는 value가 활성화된 Tab의 값으로 설정되도록 하세요.
className string | ((state: Tabs.Tab.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태를 기반으로 클래스를 반환하는 함수예요.
style React.CSSProperties | ((state: Tabs.Tab.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태를 기반으로 스타일 객체를 반환하는 함수예요.
render ReactElement | ((props: HTMLProps, state: Tabs.Tab.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Tab Data Attributes:

Attribute Type Description
data-orientation 'horizontal' | 'vertical' 탭의 방향을 나타내요.
data-disabled - 탭이 비활성화됐을 때 존재해요.
data-activation-direction 'left' | 'right' | 'up' | 'down' | 'none' 활성화 방향(이전 활성 탭 기준)을 나타내요.
data-active - 탭이 활성화됐을 때 존재해요.

Tab.Props

Tab props의 재내보내기(re-export)예요.

Tab.State

type TabsTabState = {
  /** Whether the component should ignore user interaction. */
  disabled: boolean;
  /** Whether the component is active. */
  active: boolean;
  /** The component orientation. */
  orientation: Tabs.Root.Orientation;
  /** The direction used for tab activation. */
  tabActivationDirection: Tabs.Tab.ActivationDirection;
};

Tab.Value

type TabsTabValue = Tabs.Tab.Value;

Tab.ActivationDirection

type TabsTabActivationDirection = 'left' | 'right' | 'up' | 'down' | 'none';

Tab.Metadata

type TabsTabMetadata = {
  disabled: boolean;
  id: string | undefined;
  value: Tabs.Tab.Value | undefined;
};

Tab.Position

type TabsTabPosition = { left: number; right: number; top: number; bottom: number };

Tab.Size

type TabsTabSize = { width: number; height: number };

Export Groups

  • Tabs.Root: Tabs.Root, Tabs.Root.State, Tabs.Root.Props, Tabs.Root.Orientation, Tabs.Root.ChangeEventReason, Tabs.Root.ChangeEventDetails
  • Tabs.Tab: Tabs.Tab, Tabs.Tab.Value, Tabs.Tab.ActivationDirection, Tabs.Tab.Position, Tabs.Tab.Size, Tabs.Tab.Metadata, Tabs.Tab.State, Tabs.Tab.Props
  • Tabs.Indicator: Tabs.Indicator, Tabs.Indicator.State, Tabs.Indicator.Props
  • Tabs.Panel: Tabs.Panel, Tabs.Panel.Metadata, Tabs.Panel.State, Tabs.Panel.Props
  • Tabs.List: Tabs.List, Tabs.List.State, Tabs.List.Props
  • Default: TabsRootOrientation, TabsRootState, TabsRootProps, TabsRootChangeEventReason, TabsRootChangeEventDetails, TabsIndicatorState, TabsIndicatorProps, TabsTabValue, TabsTabActivationDirection, TabsTabPosition, TabsTabSize, TabsTabMetadata, TabsTabState, TabsTabProps, TabsPanelMetadata, TabsPanelState, TabsPanelProps, TabsListState, TabsListProps

Canonical Types

Canonical: Alias 매핑 — Canonical의 네임스페이스가 이미 임포트되어 있으면 Canonical을, 아니면 Alias를 사용하세요.

  • Tabs.Root.State: TabsRootState
  • Tabs.Root.Props: TabsRootProps
  • Tabs.Root.Orientation: TabsRootOrientation
  • Tabs.Root.ChangeEventReason: TabsRootChangeEventReason
  • Tabs.Root.ChangeEventDetails: TabsRootChangeEventDetails
  • Tabs.Tab.Value: TabsTabValue
  • Tabs.Tab.ActivationDirection: TabsTabActivationDirection
  • Tabs.Tab.Position: TabsTabPosition
  • Tabs.Tab.Size: TabsTabSize
  • Tabs.Tab.Metadata: TabsTabMetadata
  • Tabs.Tab.State: TabsTabState
  • Tabs.Tab.Props: TabsTabProps
  • Tabs.Indicator.State: TabsIndicatorState
  • Tabs.Indicator.Props: TabsIndicatorProps
  • Tabs.Panel.Metadata: TabsPanelMetadata
  • Tabs.Panel.State: TabsPanelState
  • Tabs.Panel.Props: TabsPanelProps
  • Tabs.List.State: TabsListState
  • Tabs.List.Props: TabsListProps

더 알아보기 (Learn more)