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

Toolbar

원문 보기 위키 갱신

품질이 높고 비스타일(unstyled)인 React 툴바 컴포넌트로, 버튼과 컨트롤 집합을 묶어 줘요.

출처: Base UI Toolbar

본문

Demo

Tailwind

이 예시는 Tailwind CSS를 사용해 컴포넌트를 구현하는 방법을 보여줄게요.

/* index.tsx */
import * as React from 'react';
import { Toolbar } from '@base-ui/react/toolbar';
import { ToggleGroup } from '@base-ui/react/toggle-group';
import { Toggle } from '@base-ui/react/toggle';
import { Select } from '@base-ui/react/select';

export default function ExampleToolbar() {
  return (
    <Toolbar.Root className="flex w-150 items-center gap-px border border-neutral-950 bg-white p-px dark:border-white dark:bg-neutral-950">
      <ToggleGroup className="flex gap-px" aria-label="Alignment">
        <Toolbar.Button
          render={<Toggle />}
          aria-label="Align left"
          value="align-left"
          className="flex h-8 min-w-8 items-center justify-center gap-2 border-0 bg-transparent px-3 font-[inherit] text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:not-data-pressed:bg-neutral-200 data-pressed:bg-neutral-950 data-pressed:text-white data-pressed:hover:not-data-disabled:bg-neutral-950 data-pressed:hover:not-data-disabled:text-white dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:not-data-pressed:bg-neutral-700 dark:data-pressed:bg-white dark:data-pressed:text-neutral-950 dark:data-pressed:hover:not-data-disabled:bg-white dark:data-pressed:hover:not-data-disabled:text-neutral-950 focus-visible:bg-transparent focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
        >
          Align Left
        </Toolbar.Button>
        <Toolbar.Button
          render={<Toggle />}
          aria-label="Align right"
          value="align-right"
          className="flex h-8 min-w-8 items-center justify-center gap-2 border-0 bg-transparent px-3 font-[inherit] text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:not-data-pressed:bg-neutral-200 data-pressed:bg-neutral-950 data-pressed:text-white data-pressed:hover:not-data-disabled:bg-neutral-950 data-pressed:hover:not-data-disabled:text-white dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:not-data-pressed:bg-neutral-700 dark:data-pressed:bg-white dark:data-pressed:text-neutral-950 dark:data-pressed:hover:not-data-disabled:bg-white dark:data-pressed:hover:not-data-disabled:text-neutral-950 focus-visible:bg-transparent focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
        >
          Align Right
        </Toolbar.Button>
      </ToggleGroup>
      <Toolbar.Separator className="m-1 h-4 w-px bg-neutral-950 dark:bg-white" />
      <Toolbar.Group className="flex gap-px" aria-label="Numerical format">
        <Toolbar.Button
          className="flex h-8 min-w-8 items-center justify-center gap-2 border-0 bg-transparent font-[inherit] text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:not-data-pressed:bg-neutral-200 data-pressed:bg-neutral-950 data-pressed:text-white data-pressed:hover:not-data-disabled:bg-neutral-950 data-pressed:hover:not-data-disabled:text-white dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:not-data-pressed:bg-neutral-700 dark:data-pressed:bg-white dark:data-pressed:text-neutral-950 dark:data-pressed:hover:not-data-disabled:bg-white dark:data-pressed:hover:not-data-disabled:text-neutral-950 focus-visible:bg-transparent focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
          aria-label="Format as currency"
        >
          $
        </Toolbar.Button>
        <Toolbar.Button
          className="flex h-8 min-w-8 items-center justify-center gap-2 border-0 bg-transparent font-[inherit] text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:not-data-pressed:bg-neutral-200 data-pressed:bg-neutral-950 data-pressed:text-white data-pressed:hover:not-data-disabled:bg-neutral-950 data-pressed:hover:not-data-disabled:text-white dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:not-data-pressed:bg-neutral-700 dark:data-pressed:bg-white dark:data-pressed:text-neutral-950 dark:data-pressed:hover:not-data-disabled:bg-white dark:data-pressed:hover:not-data-disabled:text-neutral-950 focus-visible:bg-transparent focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
          aria-label="Format as percent"
        >
          %
        </Toolbar.Button>
      </Toolbar.Group>
      <Toolbar.Separator className="m-1 h-4 w-px bg-neutral-950 dark:bg-white" />
      <Select.Root defaultValue="Helvetica">
        <Toolbar.Button
          render={<Select.Trigger />}
          className="flex h-8 min-w-32 cursor-default items-center justify-between gap-2 border-0 bg-transparent px-2 font-[inherit] text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:not-data-pressed:bg-neutral-200 data-pressed:bg-neutral-100 data-pressed:text-neutral-950 dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:not-data-pressed:bg-neutral-700 dark:data-pressed:bg-neutral-800 dark:data-pressed:text-white focus-visible:bg-transparent focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
        >
          <Select.Value />
          <Select.Icon>
            <CaretUpDownIcon />
          </Select.Icon>
        </Toolbar.Button>
        <Select.Portal>
          <Select.Positioner className="z-10 outline-none select-none" sideOffset={4}>
            <Select.Popup className="group max-h-[var(--available-height)] min-w-[var(--anchor-width)] origin-[var(--transform-origin)] overflow-y-auto border border-neutral-950 bg-white bg-clip-padding text-neutral-950 shadow-[0.25rem_0.25rem_0] shadow-black/12 outline-none transition-[scale,opacity] duration-100 ease-out data-ending-style:scale-[0.98] data-ending-style:opacity-0 data-[side=none]:min-w-[calc(var(--anchor-width)+1.75rem)] data-[side=none]:translate-y-px data-[side=none]:scale-100 data-[side=none]:opacity-100 data-[side=none]:transition-none data-starting-style:scale-[0.98] data-starting-style:opacity-0 data-[side=none]:data-starting-style:scale-100 data-[side=none]:data-starting-style:opacity-100 dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none">
              <Select.Item
                value="Helvetica"
                className="grid cursor-default grid-cols-[1rem_1fr] items-center gap-2 py-1.5 pr-4 pl-2.5 text-sm outline-none select-none data-highlighted:bg-neutral-950 data-highlighted:text-white pointer-coarse:py-2.5 dark:data-highlighted:bg-white dark:data-highlighted:text-neutral-950"
              >
                <Select.ItemIndicator className="col-start-1">
                  <CheckIcon />
                </Select.ItemIndicator>
                <Select.ItemText className="col-start-2">Helvetica</Select.ItemText>
              </Select.Item>
              <Select.Item
                value="Arial"
                className="grid cursor-default grid-cols-[1rem_1fr] items-center gap-2 py-1.5 pr-4 pl-2.5 text-sm outline-none select-none data-highlighted:bg-neutral-950 data-highlighted:text-white pointer-coarse:py-2.5 dark:data-highlighted:bg-white dark:data-highlighted:text-neutral-950"
              >
                <Select.ItemIndicator className="col-start-1">
                  <CheckIcon />
                </Select.ItemIndicator>
                <Select.ItemText className="col-start-2">Arial</Select.ItemText>
              </Select.Item>
            </Select.Popup>
          </Select.Positioner>
        </Select.Portal>
      </Select.Root>
      <Toolbar.Separator className="m-1 h-4 w-px bg-neutral-950 dark:bg-white" />
      <Toolbar.Link
        className="mr-[0.875rem] ml-auto flex-none self-center font-[inherit] text-sm text-neutral-500 no-underline hover:text-blue-700 dark:text-neutral-400 dark:hover:text-blue-500 focus-visible:outline-2 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
        href="#"
      >
        Edited 51m ago
      </Toolbar.Link>
    </Toolbar.Root>
  );
}

function CaretUpDownIcon(props: React.ComponentProps<'svg'>) {
  return (
    <svg
      width="16"
      height="16"
      viewBox="0 0 16 16"
      fill="currentColor"
      {...props}
      style={{ display: 'block', ...props.style }}
    >
      <path d="M11 10H5l3 3.5zm0-4H5l3-3.5z" />
    </svg>
  );
}

function CheckIcon(props: React.ComponentProps<'svg'>) {
  return (
    <svg
      width="16"
      height="16"
      viewBox="0 0 16 16"
      fill="none"
      stroke="currentColor"
      {...props}
      style={{ display: 'block', ...props.style }}
    >
      <path d="m2.5 8.5 4 4 7-9" />
    </svg>
  );
}

CSS Modules

이 예시는 CSS Modules를 사용해 컴포넌트를 구현하는 방법을 보여줄게요.

/* index.module.css */
.Toolbar {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 1px;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  padding: 1px;
  width: 37.5rem;

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

.Group {
  display: flex;
  gap: 1px;
}

.Button {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-width: 2rem;
  height: 2rem;
  padding: 0;
  margin: 0;
  border: 0;
  background-color: transparent;
  color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1;
  white-space: nowrap;

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

  @media (hover: hover) {
    &:hover:not([data-disabled], [data-pressed]) {
      background-color: oklch(97% 0 0deg);

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

  &:active:not([data-disabled], [data-pressed]) {
    background-color: oklch(92.2% 0 0deg);

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

  &[aria-pressed] {
    padding: 0 0.75rem;
  }

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

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

  @media (hover: hover) {
    &[data-pressed]:hover:not([data-disabled], [role='combobox']) {
      background-color: oklch(14.5% 0 0deg);
      color: white;

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

  &[role='combobox'] {
    min-width: 8rem;
    justify-content: space-between;
    padding: 0 0.5rem;

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

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

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

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

.Separator {
  width: 1px;
  height: 16px;
  margin: 0.25rem;
  background-color: oklch(14.5% 0 0deg);

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

.Link {
  color: oklch(55.6% 0 0deg);
  font-family: inherit;
  font-size: 0.875rem;
  line-height: 1.25rem;
  text-decoration: none;
  align-self: center;
  flex: 0 0 auto;
  margin-inline: auto 0.875rem;

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

  @media (hover: hover) {
    &:hover {
      color: oklch(48.8% 0.243 264.376deg);

      @media (prefers-color-scheme: dark) {
        color: oklch(62.3% 0.214 259.815deg);
      }
    }
  }

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

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

.Positioner {
  outline: none;
  -webkit-user-select: none;
  user-select: none;
  z-index: 10;
}

.Popup {
  box-sizing: border-box;
  outline: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  background-clip: padding-box;
  color: oklch(14.5% 0 0deg);
  min-width: var(--anchor-width);
  transform-origin: var(--transform-origin);
  box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
  transition:
    transform 100ms ease-out,
    opacity 100ms ease-out;
  overflow-y: auto;
  max-height: var(--available-height);

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

  &[data-starting-style],
  &[data-ending-style] {
    opacity: 0;
    transform: scale(0.98);
  }

  &[data-side='none'] {
    transition: none;
    transform: translateY(1px);
    opacity: 1;
    min-width: calc(var(--anchor-width) + 1.75rem);
  }
}

.Item {
  box-sizing: border-box;
  outline: 0;
  font-size: 0.875rem;
  line-height: 1.25rem;
  padding-block: 0.375rem;
  padding-left: 0.625rem;
  padding-right: 1rem;
  display: grid;
  gap: 0.5rem;
  align-items: center;
  grid-template-columns: 1rem 1fr;
  cursor: default;
  -webkit-user-select: none;
  user-select: none;

  @media (pointer: coarse) {
    padding-block: 0.625rem;
  }

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

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

.ItemIndicator {
  grid-column-start: 1;
}

.ItemText {
  grid-column-start: 2;
}
/* index.tsx */
import * as React from 'react';
import { Toolbar } from '@base-ui/react/toolbar';
import { ToggleGroup } from '@base-ui/react/toggle-group';
import { Toggle } from '@base-ui/react/toggle';
import { Select } from '@base-ui/react/select';
import styles from './index.module.css';

export default function ExampleToolbar() {
  return (
    <Toolbar.Root className={styles.Toolbar}>
      <ToggleGroup className={styles.Group} aria-label="Alignment">
        <Toolbar.Button
          render={<Toggle />}
          aria-label="Align left"
          value="align-left"
          className={styles.Button}
        >
          Align Left
        </Toolbar.Button>
        <Toolbar.Button
          render={<Toggle />}
          aria-label="Align right"
          value="align-right"
          className={styles.Button}
        >
          Align Right
        </Toolbar.Button>
      </ToggleGroup>
      <Toolbar.Separator className={styles.Separator} />
      <Toolbar.Group className={styles.Group} aria-label="Numerical format">
        <Toolbar.Button className={styles.Button} aria-label="Format as currency">
          $
        </Toolbar.Button>
        <Toolbar.Button className={styles.Button} aria-label="Format as percent">
          %
        </Toolbar.Button>
      </Toolbar.Group>
      <Toolbar.Separator className={styles.Separator} />
      <Select.Root defaultValue="Helvetica">
        <Toolbar.Button render={<Select.Trigger />} className={styles.Button}>
          <Select.Value />
          <Select.Icon>
            <CaretUpDownIcon />
          </Select.Icon>
        </Toolbar.Button>
        <Select.Portal>
          <Select.Positioner
            className={styles.Positioner}
            sideOffset={4}
            alignItemWithTrigger={false}
          >
            <Select.Popup className={styles.Popup}>
              <Select.Item className={styles.Item} value="Helvetica">
                <Select.ItemIndicator className={styles.ItemIndicator}>
                  <CheckIcon />
                </Select.ItemIndicator>
                <Select.ItemText className={styles.ItemText}>Helvetica</Select.ItemText>
              </Select.Item>
              <Select.Item className={styles.Item} value="Arial">
                <Select.ItemIndicator className={styles.ItemIndicator}>
                  <CheckIcon />
                </Select.ItemIndicator>
                <Select.ItemText className={styles.ItemText}>Arial</Select.ItemText>
              </Select.Item>
            </Select.Popup>
          </Select.Positioner>
        </Select.Portal>
      </Select.Root>
      <Toolbar.Separator className={styles.Separator} />
      <Toolbar.Link className={styles.Link} href="#">
        Edited 51m ago
      </Toolbar.Link>
    </Toolbar.Root>
  );
}

function CaretUpDownIcon(props: React.ComponentProps<'svg'>) {
  return (
    <svg
      width="16"
      height="16"
      viewBox="0 0 16 16"
      fill="currentColor"
      {...props}
      style={{ display: 'block', ...props.style }}
    >
      <path d="M11 10H5l3 3.5zm0-4H5l3-3.5z" />
    </svg>
  );
}

function CheckIcon(props: React.ComponentProps<'svg'>) {
  return (
    <svg
      width="16"
      height="16"
      viewBox="0 0 16 16"
      fill="none"
      stroke="currentColor"
      {...props}
      style={{ display: 'block', ...props.style }}
    >
      <path d="m2.5 8.5 4 4 7-9" />
    </svg>
  );
}

Usage guidelines

툴바가 접근 가능하고 유용하게 동작하도록 다음 지침을 따라 주세요:

  • 입력 컨트롤을 아껴 쓰세요: 왼쪽/오른쪽 화살표 키는 입력 컨트롤에서 텍스트 삽입 커서를 옮기는 데도, 가로 툴바에서 컨트롤 사이를 탐색하는 데도 쓰여요. 가로 툴바에서 입력 컨트롤을 사용할 때는 하나만 사용하고, 툴바의 마지막 요소로 배치하세요.

Anatomy

컴포넌트를 불러와서 각 부분을 조립해요:

import { Toolbar } from '@base-ui/react/toolbar';

<Toolbar.Root>
  <Toolbar.Button />
  <Toolbar.Link />
  <Toolbar.Separator />
  <Toolbar.Group>
    <Toolbar.Button />
    <Toolbar.Button />
  </Toolbar.Group>
  <Toolbar.Input />
</Toolbar.Root>;

Examples

Using with Menu

Trigger 컴포넌트를 제공하는 모든 Base UI 팝업 컴포넌트는 트리거를 render prop으로 <Toolbar.Button>에 넘겨서 툴바와 통합할 수 있어요:

return (
  <Toolbar.Root>
    <Menu.Root>
      {/* @highlight */}
      <Toolbar.Button render={<Menu.Trigger />} />
      <Menu.Portal>
        {/* prettier-ignore */}
        {/* Compose the rest of the menu */}
      </Menu.Portal>
    </Menu.Root>
  </Toolbar.Root>;
)

이 방식은 <AlertDialog>, <Dialog>, <Menu>, <Popover>, <Select>에 적용돼요.

Using with Tooltip

다른 팝업과 달리, <Tooltip.Trigger>의 render prop에 툴바 항목을 넘겨야 해요:

return (
  <Toolbar.Root>
    <Tooltip.Root>
      {/* @highlight */}
      <Tooltip.Trigger render={<Toolbar.Button />} />
      <Tooltip.Portal>
        {/* prettier-ignore */}
        {/* Compose the rest of the tooltip */}
      </Tooltip.Portal>
    </Tooltip.Root>
  </Toolbar.Root>;
)

Using with NumberField

툴바에서 NumberField를 사용하려면 render prop을 사용해 <NumberField.Input>을 <Toolbar.Input>에 넘겨 주세요:

return (
  <Toolbar.Root>
    <NumberField.Root>
      <NumberField.Group>
        <NumberField.Decrement />
        {/* @highlight */}
        <Toolbar.Input render={<NumberField.Input />} />
        <NumberField.Increment />
      </NumberField.Group>
    </NumberField.Root>
  </Toolbar.Root>;
)

API reference

Root

버튼, 토글 그룹, 메뉴 같은 일련의 컨트롤을 묶어 주는 컨테이너예요. <div> 요소를 렌더링해요.

Root Props:

Prop Type Default Description
loopFocus boolean true If true, using keyboard navigation will wrap focus to the other end of the toolbar once the end is reached.
disabled boolean - -
orientation Toolbar.Root.Orientation 'horizontal' The orientation of the toolbar.
className string | ((state: Toolbar.Root.State) => string | undefined) - CSS class applied to the element, or a function that returns a class based on the component's state.
style React.CSSProperties | ((state: Toolbar.Root.State) => React.CSSProperties | undefined) - Style applied to the element, or a function that returns a style object based on the component's state.
render ReactElement | ((props: HTMLProps, state: Toolbar.Root.State) => ReactElement) - Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Root Data Attributes:

Attribute Type Description
data-orientation 'horizontal' | 'vertical' Indicates the orientation of the toolbar.
data-disabled - Present when the toolbar is disabled.

Root.Props

Root props의 재-export예요.

Root.State

type ToolbarRootState = {
  /** Whether the component is disabled. */
  disabled: boolean;
  /** The component orientation. */
  orientation: Toolbar.Root.Orientation;
};

Root.Orientation

type ToolbarRootOrientation = 'horizontal' | 'vertical';

Root.ItemMetadata

type ToolbarRootItemMetadata = { disabled: boolean; focusableWhenDisabled: boolean };

Input

Toolbar 키보드 탐색과 통합되는 네이티브 입력 요소예요. <input> 요소를 렌더링해요.

Input Props:

Prop Type Default Description
defaultValue string | number | string[] - -
focusableWhenDisabled boolean true When true the item remains focusable when disabled.
disabled boolean false When true the item is disabled.
className string | ((state: Toolbar.Input.State) => string | undefined) - CSS class applied to the element, or a function that returns a class based on the component's state.
style React.CSSProperties | ((state: Toolbar.Input.State) => React.CSSProperties | undefined) - Style applied to the element, or a function that returns a style object based on the component's state.
render ReactElement | ((props: HTMLProps, state: Toolbar.Input.State) => ReactElement) - Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Input Data Attributes:

Attribute Type Description
data-orientation 'horizontal' | 'vertical' Indicates the orientation of the toolbar.
data-disabled - Present when the input is disabled.
data-focusable - Present when the input remains focusable when disabled.

Input.Props

Input props의 재-export예요.

Input.State

type ToolbarInputState = {
  /** Whether the component is disabled. */
  disabled: boolean;
  /** Whether the component remains focusable when disabled. */
  focusable: boolean;
  /** The component orientation. */
  orientation: Toolbar.Root.Orientation;
};

Group

여러 툴바 항목이나 토글을 묶어 줘요. <div> 요소를 렌더링해요.

Group Props:

Prop Type Default Description
disabled boolean false When true all toolbar items in the group are disabled.
className string | ((state: Toolbar.Group.State) => string | undefined) - CSS class applied to the element, or a function that returns a class based on the component's state.
style React.CSSProperties | ((state: Toolbar.Group.State) => React.CSSProperties | undefined) - Style applied to the element, or a function that returns a style object based on the component's state.
render ReactElement | ((props: HTMLProps, state: Toolbar.Group.State) => ReactElement) - Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Group Data Attributes:

Attribute Type Description
data-orientation 'horizontal' | 'vertical' Indicates the orientation of the toolbar.
data-disabled - Present when the group is disabled.

Group.Props

Group props의 재-export예요.

Group.State

type ToolbarGroupState = {
  /** Whether the component is disabled. */
  disabled: boolean;
  /** The component orientation. */
  orientation: Toolbar.Root.Orientation;
};

Separator

스크린 리더가 접근할 수 있는 구분선 요소예요. <div> 요소를 렌더링해요.

Separator Props:

Prop Type Default Description
orientation Orientation - The orientation of the separator. Defaults to the opposite of the toolbar's orientation, so a horizontal toolbar renders vertical separators.
className string | ((state: Toolbar.Separator.State) => string | undefined) - CSS class applied to the element, or a function that returns a class based on the component's state.
style React.CSSProperties | ((state: Toolbar.Separator.State) => React.CSSProperties | undefined) - Style applied to the element, or a function that returns a style object based on the component's state.
render ReactElement | ((props: HTMLProps, state: Toolbar.Separator.State) => ReactElement) - Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Separator Data Attributes:

Attribute Type Description
data-orientation 'horizontal' | 'vertical' Indicates the orientation of the separator, which is perpendicular to the toolbar.

Separator.Props

Separator props의 재-export예요.

Separator.State

type ToolbarSeparatorState = {
  /** The orientation of the separator. */
  orientation: Orientation;
};

Button

그대로 쓰거나 다른 컴포넌트의 트리거로 쓸 수 있는 버튼이에요. <button> 요소를 렌더링해요.

Button Props:

Prop Type Default Description
focusableWhenDisabled boolean true When true the item remains focusable when disabled.
nativeButton boolean true Whether the component renders a native <button> element when replacing it via the render prop. Set to false if the rendered element is not a button (for example, <div>).
disabled boolean false When true the item is disabled.
className string | ((state: Toolbar.Button.State) => string | undefined) - CSS class applied to the element, or a function that returns a class based on the component's state.
style React.CSSProperties | ((state: Toolbar.Button.State) => React.CSSProperties | undefined) - Style applied to the element, or a function that returns a style object based on the component's state.
render ReactElement | ((props: HTMLProps, state: Toolbar.Button.State) => ReactElement) - Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Button Data Attributes:

Attribute Type Description
data-orientation 'horizontal' | 'vertical' Indicates the orientation of the toolbar.
data-disabled - Present when the button is disabled.
data-focusable - Present when the button remains focusable when disabled.

Button.Props

Button props의 재-export예요.

Button.State

type ToolbarButtonState = {
  /** Whether the component is disabled. */
  disabled: boolean;
  /** Whether the component remains focusable when disabled. */
  focusable: boolean;
  /** The component orientation. */
  orientation: Toolbar.Root.Orientation;
};

링크 컴포넌트예요. <a> 요소를 렌더링해요.

Link Props:

Prop Type Default Description
className string | ((state: Toolbar.Link.State) => string | undefined) - CSS class applied to the element, or a function that returns a class based on the component's state.
style React.CSSProperties | ((state: Toolbar.Link.State) => React.CSSProperties | undefined) - Style applied to the element, or a function that returns a style object based on the component's state.
render ReactElement | ((props: React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>, state: Toolbar.Link.State) => ReactElement) - Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Link Data Attributes:

Attribute Type Description
data-orientation 'horizontal' | 'vertical' Indicates the orientation of the toolbar.

Link.Props

Link props의 재-export예요.

Link.State

type ToolbarLinkState = {
  /** The component orientation. */
  orientation: Toolbar.Root.Orientation;
};

Additional Types

Toolbar.Orientation

type ToolbarOrientation = 'horizontal' | 'vertical';

Export Groups

  • Toolbar.Separator: Toolbar.Separator, Toolbar.Separator.State, Toolbar.Separator.Props
  • Toolbar.Root: Toolbar.Root, Toolbar.Root.ItemMetadata, Toolbar.Root.Orientation, Toolbar.Root.State, Toolbar.Root.Props
  • Toolbar.Group: Toolbar.Group, Toolbar.Group.State, Toolbar.Group.Props
  • Toolbar.Button: Toolbar.Button, Toolbar.Button.State, Toolbar.Button.Props
  • Toolbar.Link: Toolbar.Link, Toolbar.Link.State, Toolbar.Link.Props
  • Toolbar.Input: Toolbar.Input, Toolbar.Input.State, Toolbar.Input.Props
  • Default: Toolbar.Orientation, Orientation, ToolbarRootItemMetadata, ToolbarRootOrientation, ToolbarRootState, ToolbarRootProps, ToolbarGroupState, ToolbarGroupProps, ToolbarButtonState, ToolbarButtonProps, ToolbarLinkState, ToolbarLinkProps, ToolbarInputState, ToolbarInputProps, ToolbarSeparatorState, ToolbarSeparatorProps

Canonical Types

Canonical: Alias 매핑이에요. 네임스페이스가 이미 import되어 있을 때는 Canonical을, 그렇지 않으면 Alias를 사용해요.

  • Toolbar.Separator.State: ToolbarSeparatorState
  • Toolbar.Separator.Props: ToolbarSeparatorProps
  • Toolbar.Root.ItemMetadata: ToolbarRootItemMetadata
  • Toolbar.Root.Orientation: ToolbarRootOrientation
  • Toolbar.Root.State: ToolbarRootState
  • Toolbar.Root.Props: ToolbarRootProps
  • Toolbar.Group.State: ToolbarGroupState
  • Toolbar.Group.Props: ToolbarGroupProps
  • Toolbar.Button.State: ToolbarButtonState
  • Toolbar.Button.Props: ToolbarButtonProps
  • Toolbar.Link.State: ToolbarLinkState
  • Toolbar.Link.Props: ToolbarLinkProps
  • Toolbar.Input.State: ToolbarInputState
  • Toolbar.Input.Props: ToolbarInputProps

더 알아보기