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

컨텍스트 메뉴

원문 보기 위키 갱신

컨텍스트 메뉴 (Context Menu)

오른쪽 클릭이나 길게 누르면 포인터 위치에 나타나는 고품질의 비스타일 React 컨텍스트 메뉴 컴포넌트예요. 서브메뉴, 라디오·체크박스 항목까지 지원해서 풍부한 메뉴를 만들 수 있어요.

출처: Base UI 컨텍스트 메뉴

본문

오른쪽 클릭이나 길게 누르면 포인터 위치에 나타나는 고품질의 비스타일 React 컨텍스트 메뉴 컴포넌트예요.

데모

Tailwind

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

/* index.tsx */
import { ContextMenu } from '@base-ui/react/context-menu';

export default function ExampleMenu() {
  return (
    <ContextMenu.Root>
      <ContextMenu.Trigger className="flex aspect-5/3 w-full max-w-64 items-center justify-center rounded-none border border-neutral-950 bg-white text-neutral-950 select-none text-sm dark:border-white dark:bg-neutral-950 dark:text-white">
        Right click here
      </ContextMenu.Trigger>
      <ContextMenu.Portal>
        <ContextMenu.Positioner className="outline-hidden">
          <ContextMenu.Popup className="origin-[var(--transform-origin)] border border-neutral-950 bg-white py-1 text-neutral-950 shadow-[0.25rem_0.25rem_0] shadow-black/12 outline-hidden transition-[scale,opacity] duration-100 ease-out data-ending-style:scale-[0.98] data-ending-style:opacity-0 data-starting-style:scale-[0.98] data-starting-style:opacity-0 dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none">
            <ContextMenu.Item className={itemClass}>Add to Library</ContextMenu.Item>
            <ContextMenu.Item className={itemClass}>Add to Playlist</ContextMenu.Item>
            <ContextMenu.Separator className="mx-1 my-1 h-px bg-neutral-950 dark:bg-white" />
            <ContextMenu.Item className={itemClass}>Play Next</ContextMenu.Item>
            <ContextMenu.Item className={itemClass}>Play Last</ContextMenu.Item>
            <ContextMenu.Separator className="mx-1 my-1 h-px bg-neutral-950 dark:bg-white" />
            <ContextMenu.Item className={itemClass}>Favorite</ContextMenu.Item>
            <ContextMenu.Item className={itemClass}>Share</ContextMenu.Item>
          </ContextMenu.Popup>
        </ContextMenu.Positioner>
      </ContextMenu.Portal>
    </ContextMenu.Root>
  );
}

const itemClass =
  "flex cursor-default py-2 pr-8 pl-4 text-sm leading-4 outline-hidden select-none data-highlighted:relative data-highlighted:z-0 data-highlighted:text-white data-highlighted:before:absolute data-highlighted:before:inset-x-1 data-highlighted:before:inset-y-0 data-highlighted:before:z-[-1] data-highlighted:before:bg-neutral-950 data-highlighted:before:content-[''] data-disabled:text-neutral-500 dark:data-highlighted:text-neutral-950 dark:data-highlighted:before:bg-white dark:data-disabled:text-neutral-400";

CSS Modules

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

/* index.module.css */
.Trigger {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 16rem;
  aspect-ratio: 5 / 3;
  outline: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  background-color: white;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

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

.Positioner {
  outline: 0;
}

.Popup {
  box-sizing: border-box;
  outline: 0;
  padding-block: 0.25rem;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  background-color: white;
  color: oklch(14.5% 0 0deg);
  box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
  transform-origin: var(--transform-origin);
  transition:
    transform 100ms ease-out,
    opacity 100ms ease-out;

  @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);
  }
}

.Item {
  outline: 0;
  cursor: default;
  -webkit-user-select: none;
  user-select: none;
  padding-block: 0.5rem;
  padding-left: 1rem;
  padding-right: 2rem;
  display: flex;
  font-size: 0.875rem;
  line-height: 1rem;

  &[data-highlighted] {
    z-index: 0;
    position: relative;
    color: white;

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

  &[data-highlighted]::before {
    content: '';
    z-index: -1;
    position: absolute;
    inset-block: 0;
    inset-inline: 0.25rem;
    background-color: oklch(14.5% 0 0deg);

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

  &[data-disabled] {
    color: oklch(55.6% 0 0deg);

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

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

  @media (prefers-color-scheme: dark) {
    background-color: white;
  }
}
/* index.tsx */
import { ContextMenu } from '@base-ui/react/context-menu';
import styles from './index.module.css';

export default function ExampleMenu() {
  return (
    <ContextMenu.Root>
      <ContextMenu.Trigger className={styles.Trigger}>Right click here</ContextMenu.Trigger>
      <ContextMenu.Portal>
        <ContextMenu.Positioner className={styles.Positioner}>
          <ContextMenu.Popup className={styles.Popup}>
            <ContextMenu.Item className={styles.Item}>Add to Library</ContextMenu.Item>
            <ContextMenu.Item className={styles.Item}>Add to Playlist</ContextMenu.Item>
            <ContextMenu.Separator className={styles.Separator} />
            <ContextMenu.Item className={styles.Item}>Play Next</ContextMenu.Item>
            <ContextMenu.Item className={styles.Item}>Play Last</ContextMenu.Item>
            <ContextMenu.Separator className={styles.Separator} />
            <ContextMenu.Item className={styles.Item}>Favorite</ContextMenu.Item>
            <ContextMenu.Item className={styles.Item}>Share</ContextMenu.Item>
          </ContextMenu.Popup>
        </ContextMenu.Positioner>
      </ContextMenu.Portal>
    </ContextMenu.Root>
  );
}

사용 가이드라인

  • 컨텍스트 메뉴는 보조 수단으로 사용하세요: 컨텍스트 메뉴를 동작을 수행하는 유일한 방법으로 만들지 마세요. 특히 터치 기기나 보조 기술을 사용하는 사용자는 컨텍스트 메뉴를 발견하지 못하거나 열 수 없을 수 있어요. 컨텍스트 메뉴에 있는 동작에는 항상 눈에 보이는 컨트롤도 함께 제공하세요.

구조 (Anatomy)

컴포넌트를 임포트하고 함께 배치해요.

import { ContextMenu } from '@base-ui/react/context-menu';

<ContextMenu.Root>
  <ContextMenu.Trigger />
  <ContextMenu.Portal>
    <ContextMenu.Backdrop />
    <ContextMenu.Positioner>
      <ContextMenu.Popup>
        <ContextMenu.Arrow />
        <ContextMenu.Item />
        <ContextMenu.LinkItem />
        <ContextMenu.Separator />

        <ContextMenu.SubmenuRoot>
          <ContextMenu.SubmenuTrigger />
        </ContextMenu.SubmenuRoot>

        <ContextMenu.Group>
          <ContextMenu.GroupLabel />
        </ContextMenu.Group>

        <ContextMenu.RadioGroup>
          <ContextMenu.RadioItem>
            <ContextMenu.RadioItemIndicator />
          </ContextMenu.RadioItem>
        </ContextMenu.RadioGroup>

        <ContextMenu.CheckboxItem>
          <ContextMenu.CheckboxItemIndicator />
        </ContextMenu.CheckboxItem>
      </ContextMenu.Popup>
    </ContextMenu.Positioner>
  </ContextMenu.Portal>
</ContextMenu.Root>;

예시

Menu에는 추가 데모가 있는데, 그중 상당수가 컨텍스트 메뉴에도 적용돼요.

컨텍스트 메뉴는 같은 동작을 수행할 수 있는 기본 방법을 보완해야 해요. 이 이미지 카드는 눈에 보이는 메뉴 버튼으로 동작을 노출하고, 오른쪽 클릭·길게 누르기 사용자를 위해 컨텍스트 메뉴에서도 그 동작을 재사용해요.

데모

Tailwind

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

/* index.tsx */
'use client';
import * as React from 'react';
import { ContextMenu } from '@base-ui/react/context-menu';
import { Menu } from '@base-ui/react/menu';

export default function ContextMenuWithMenuDemo() {
  return (
    <div className="group relative w-full max-w-64 overflow-hidden border border-neutral-950 bg-white text-left text-neutral-950 select-none dark:border-white dark:bg-neutral-950 dark:text-white">
      <ContextMenu.Root>
        <ContextMenu.Trigger>
          <img
            width="512"
            height="288"
            className="h-36 w-full object-cover"
            src="https://images.unsplash.com/photo-1619615391095-dfa29e1672ef?q=80&w=512&h=288"
            alt=""
          />
          <div className="p-2">
            <p className="text-sm leading-5">Station Hofplein</p>
            <p className="text-xs leading-4 text-neutral-500 dark:text-neutral-400">JPG, 2.4 MB</p>
          </div>
        </ContextMenu.Trigger>

        <ContextMenu.Portal>
          <ContextMenu.Positioner className="outline-hidden">
            <ContextMenu.Popup className={popupClass}>
              <SharedMenuItems type="context-menu" />
            </ContextMenu.Popup>
          </ContextMenu.Positioner>
        </ContextMenu.Portal>
      </ContextMenu.Root>

      <Menu.Root>
        <Menu.Trigger
          aria-label="Image actions"
          className="absolute top-2 right-2 flex size-8 items-center justify-center border border-neutral-950 bg-white text-neutral-950 opacity-0 select-none group-hover:opacity-100 data-pressed:opacity-100 any-pointer-coarse:opacity-100 hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:bg-neutral-200 data-pressed:bg-neutral-100 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:bg-neutral-700 dark:data-pressed:bg-neutral-800 focus-visible:opacity-100 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
        >
          <MoreVertIcon />
        </Menu.Trigger>
        <Menu.Portal>
          <Menu.Positioner align="end" sideOffset={8} className="outline-hidden">
            <Menu.Popup className={popupClass}>
              <SharedMenuItems />
            </Menu.Popup>
          </Menu.Positioner>
        </Menu.Portal>
      </Menu.Root>
    </div>
  );
}

const popupClass =
  'origin-[var(--transform-origin)] border border-neutral-950 bg-white py-1 text-neutral-950 shadow-[0.25rem_0.25rem_0] shadow-black/12 outline-hidden transition-[scale,opacity] duration-100 ease-out data-ending-style:scale-[0.98] data-ending-style:opacity-0 data-starting-style:scale-[0.98] data-starting-style:opacity-0 dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none';
const itemClass =
  "flex cursor-default py-2 pr-8 pl-4 text-sm leading-4 outline-hidden select-none data-highlighted:relative data-highlighted:z-0 data-highlighted:text-white data-highlighted:before:absolute data-highlighted:before:inset-x-1 data-highlighted:before:inset-y-0 data-highlighted:before:z-[-1] data-highlighted:before:bg-neutral-950 data-highlighted:before:content-[''] data-disabled:text-neutral-500 dark:data-highlighted:text-neutral-950 dark:data-highlighted:before:bg-white dark:data-disabled:text-neutral-400";

const actions = ['Preview', 'Download', 'Copy link', 'Rename'];

function SharedMenuItems({ type = 'menu' }: { type?: 'menu' | 'context-menu' }) {
  const Item = type === 'context-menu' ? ContextMenu.Item : Menu.Item;
  const Separator = type === 'context-menu' ? ContextMenu.Separator : Menu.Separator;
  return (
    <React.Fragment>
      {actions.map((action) => (
        <Item key={action} className={itemClass}>
          {action}
        </Item>
      ))}
      <Separator className="mx-1 my-1 h-px bg-neutral-950 dark:bg-white" />
      <Item className={`${itemClass} text-red-700`}>Delete</Item>
    </React.Fragment>
  );
}

function MoreVertIcon(props: React.ComponentProps<'svg'>) {
  return (
    <svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor" {...props}>
      <path d="M9.5 13c0 .8284-.67157 1.5-1.5 1.5s-1.5-.6716-1.5-1.5.67157-1.5 1.5-1.5 1.5.6716 1.5 1.5m0-5c0 .82843-.67157 1.5-1.5 1.5S6.5 8.82843 6.5 8 7.17157 6.5 8 6.5s1.5.67157 1.5 1.5m0-5c0 .82843-.67157 1.5-1.5 1.5S6.5 3.82843 6.5 3 7.17157 1.5 8 1.5s1.5.67157 1.5 1.5" />
    </svg>
  );
}

CSS Modules

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

/* index.module.css */
.Card {
  box-sizing: border-box;
  position: relative;
  display: block;
  overflow: hidden;
  width: 100%;
  max-width: 16rem;
  outline: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  color: oklch(14.5% 0 0deg);
  text-align: left;
  -webkit-user-select: none;
  user-select: none;

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

.Image {
  display: block;
  width: 100%;
  height: 9rem;
  object-fit: cover;
}

.Content {
  padding: 0.5rem;
}

.Title {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.25rem;
}

.Metadata {
  margin: 0;
  font-size: 0.75rem;
  line-height: 1rem;
  color: oklch(55.6% 0 0deg);

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

.MenuTrigger {
  box-sizing: border-box;
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  margin: 0;
  outline: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  background-color: white;
  color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;
  opacity: 0;

  &[data-pressed],
  &:focus-visible,
  .Card:hover & {
    opacity: 1;
  }

  @media (any-pointer: coarse) {
    opacity: 1;
  }

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

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

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

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

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

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

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

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

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

.Positioner {
  outline: 0;
}

.Popup {
  box-sizing: border-box;
  outline: 0;
  padding-block: 0.25rem;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  background-color: white;
  color: oklch(14.5% 0 0deg);
  box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
  transform-origin: var(--transform-origin);
  transition:
    transform 100ms ease-out,
    opacity 100ms ease-out;

  @media (prefers-color-scheme: dark) {
    border-color: 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);
  }
}

.Item {
  position: relative;
  display: flex;
  padding-block: 0.5rem;
  padding-left: 1rem;
  padding-right: 2rem;
  outline: 0;
  color: inherit;
  font-size: 0.875rem;
  line-height: 1rem;
  cursor: default;
  -webkit-user-select: none;
  user-select: none;

  &[data-highlighted] {
    z-index: 0;
    color: white;

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

  &[data-highlighted]::before {
    content: '';
    z-index: -1;
    position: absolute;
    inset-block: 0;
    inset-inline: 0.25rem;
    background-color: oklch(14.5% 0 0deg);

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

.ItemDestructive {
  color: oklch(50.5% 0.213 27.518deg);
}

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

  @media (prefers-color-scheme: dark) {
    background-color: white;
  }
}
/* index.tsx */
'use client';
import * as React from 'react';
import { ContextMenu } from '@base-ui/react/context-menu';
import { Menu } from '@base-ui/react/menu';
import styles from './index.module.css';

export default function ContextMenuWithMenuDemo() {
  return (
    <div className={styles.Card}>
      <ContextMenu.Root>
        <ContextMenu.Trigger>
          <img
            width="512"
            height="288"
            className={styles.Image}
            src="https://images.unsplash.com/photo-1619615391095-dfa29e1672ef?q=80&w=512&h=288"
            alt=""
          />
          <div className={styles.Content}>
            <p className={styles.Title}>Station Hofplein</p>
            <p className={styles.Metadata}>JPG, 2.4 MB</p>
          </div>
        </ContextMenu.Trigger>

        <ContextMenu.Portal>
          <ContextMenu.Positioner className={styles.Positioner}>
            <ContextMenu.Popup className={styles.Popup}>
              <SharedMenuItems type="context-menu" />
            </ContextMenu.Popup>
          </ContextMenu.Positioner>
        </ContextMenu.Portal>
      </ContextMenu.Root>

      <Menu.Root>
        <Menu.Trigger aria-label="Image actions" className={styles.MenuTrigger}>
          <MoreVertIcon />
        </Menu.Trigger>
        <Menu.Portal>
          <Menu.Positioner align="end" sideOffset={8} className={styles.Positioner}>
            <Menu.Popup className={styles.Popup}>
              <SharedMenuItems />
            </Menu.Popup>
          </Menu.Positioner>
        </Menu.Portal>
      </Menu.Root>
    </div>
  );
}

const actions = ['Preview', 'Download', 'Copy link', 'Rename'];

function SharedMenuItems({ type = 'menu' }: { type?: 'menu' | 'context-menu' }) {
  const Item = type === 'context-menu' ? ContextMenu.Item : Menu.Item;
  const Separator = type === 'context-menu' ? ContextMenu.Separator : Menu.Separator;
  return (
    <React.Fragment>
      {actions.map((action) => (
        <Item key={action} className={styles.Item}>
          {action}
        </Item>
      ))}
      <Separator className={styles.Separator} />
      <Item className={`${styles.Item} ${styles.ItemDestructive}`}>Delete</Item>
    </React.Fragment>
  );
}

function MoreVertIcon(props: React.ComponentProps<'svg'>) {
  return (
    <svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor" {...props}>
      <path d="M9.5 13c0 .8284-.67157 1.5-1.5 1.5s-1.5-.6716-1.5-1.5.67157-1.5 1.5-1.5 1.5.6716 1.5 1.5m0-5c0 .82843-.67157 1.5-1.5 1.5S6.5 8.82843 6.5 8 7.17157 6.5 8 6.5s1.5.67157 1.5 1.5m0-5c0 .82843-.67157 1.5-1.5 1.5S6.5 3.82843 6.5 3 7.17157 1.5 8 1.5s1.5.67157 1.5 1.5" />
    </svg>
  );
}

중첩 메뉴 (Nested menu)

서브메뉴를 만들려면 부모 컨텍스트 메뉴 안에 <ContextMenu.SubmenuRoot>를 생성하세요. 중첩 메뉴를 여는 메뉴 항목에는 <ContextMenu.SubmenuTrigger> 파트를 사용해요.

데모

Tailwind

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

/* index.tsx */
import * as React from 'react';
import { ContextMenu } from '@base-ui/react/context-menu';

export default function ExampleContextMenu() {
  return (
    <ContextMenu.Root>
      <ContextMenu.Trigger className="flex aspect-5/3 w-full max-w-64 items-center justify-center rounded-none border border-neutral-950 bg-white text-neutral-950 select-none text-sm dark:border-white dark:bg-neutral-950 dark:text-white">
        Right click here
      </ContextMenu.Trigger>
      <ContextMenu.Portal>
        <ContextMenu.Positioner className="outline-hidden">
          <ContextMenu.Popup className={popupClass}>
            <ContextMenu.Item className={itemClass}>Add to Library</ContextMenu.Item>

            <ContextMenu.SubmenuRoot>
              <ContextMenu.SubmenuTrigger className={submenuTriggerClass}>
                Add to Playlist <CaretRightIcon />
              </ContextMenu.SubmenuTrigger>
              <ContextMenu.Portal>
                <ContextMenu.Positioner className="outline-hidden" alignOffset={-4} sideOffset={-4}>
                  <ContextMenu.Popup className={popupClass}>
                    <ContextMenu.Item className={itemClass}>Get Up!</ContextMenu.Item>
                    <ContextMenu.Item className={itemClass}>Inside Out</ContextMenu.Item>
                    <ContextMenu.Item className={itemClass}>Night Beats</ContextMenu.Item>
                    <ContextMenu.Separator className="mx-1 my-1 h-px bg-neutral-950 dark:bg-white" />
                    <ContextMenu.Item className={itemClass}>New playlist…</ContextMenu.Item>
                  </ContextMenu.Popup>
                </ContextMenu.Positioner>
              </ContextMenu.Portal>
            </ContextMenu.SubmenuRoot>

            <ContextMenu.Separator className="mx-1 my-1 h-px bg-neutral-950 dark:bg-white" />

            <ContextMenu.Item className={itemClass}>Play Next</ContextMenu.Item>
            <ContextMenu.Item className={itemClass}>Play Last</ContextMenu.Item>
            <ContextMenu.Separator className="mx-1 my-1 h-px bg-neutral-950 dark:bg-white" />
            <ContextMenu.Item className={itemClass}>Favorite</ContextMenu.Item>
            <ContextMenu.Item className={itemClass}>Share</ContextMenu.Item>
          </ContextMenu.Popup>
        </ContextMenu.Positioner>
      </ContextMenu.Portal>
    </ContextMenu.Root>
  );
}

const popupClass =
  'origin-[var(--transform-origin)] border border-neutral-950 bg-white py-1 text-neutral-950 shadow-[0.25rem_0.25rem_0] shadow-black/12 outline-hidden transition-[scale,opacity] duration-100 ease-out data-ending-style:scale-[0.98] data-ending-style:opacity-0 data-starting-style:scale-[0.98] data-starting-style:opacity-0 dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none';
const itemClass =
  "flex cursor-default py-2 pr-6 pl-4 text-sm leading-4 outline-hidden select-none data-highlighted:relative data-highlighted:z-0 data-highlighted:text-white data-highlighted:before:absolute data-highlighted:before:inset-x-1 data-highlighted:before:inset-y-0 data-highlighted:before:z-[-1] data-highlighted:before:bg-neutral-950 data-highlighted:before:content-[''] data-disabled:text-neutral-500 dark:data-highlighted:text-neutral-950 dark:data-highlighted:before:bg-white dark:data-disabled:text-neutral-400";
const submenuTriggerClass =
  "flex cursor-default items-center justify-between gap-4 py-2 pr-2 pl-4 text-sm leading-4 outline-hidden select-none data-popup-open:relative data-popup-open:z-0 data-popup-open:before:absolute data-popup-open:before:inset-x-1 data-popup-open:before:inset-y-0 data-popup-open:before:z-[-1] data-popup-open:before:bg-neutral-100 data-popup-open:before:content-[''] data-highlighted:relative data-highlighted:z-0 data-highlighted:text-white data-highlighted:before:absolute data-highlighted:before:inset-x-1 data-highlighted:before:inset-y-0 data-highlighted:before:z-[-1] data-highlighted:before:bg-neutral-950 data-highlighted:before:content-[''] data-highlighted:data-popup-open:before:bg-neutral-950 data-disabled:text-neutral-500 dark:data-popup-open:before:bg-neutral-800 dark:data-highlighted:text-neutral-950 dark:data-highlighted:before:bg-white dark:data-highlighted:data-popup-open:before:bg-white dark:data-disabled:text-neutral-400";

function CaretRightIcon(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="M6 12V4l4.5 4z" />
    </svg>
  );
}

CSS Modules

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

/* index.module.css */
.Trigger {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 16rem;
  aspect-ratio: 5 / 3;
  outline: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  background-color: white;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

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

.Positioner {
  outline: 0;
}

.Popup,
.SubmenuPopup {
  box-sizing: border-box;
  outline: 0;
  padding-block: 0.25rem;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  background-color: white;
  color: oklch(14.5% 0 0deg);
  box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
  transform-origin: var(--transform-origin);
  transition:
    transform 100ms ease-out,
    opacity 100ms ease-out;

  @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);
  }
}

.Arrow {
  display: flex;

  &[data-side='top'] {
    bottom: -8px;
    rotate: 180deg;
  }

  &[data-side='bottom'] {
    top: -8px;
    rotate: 0deg;
  }

  &[data-side='left'] {
    right: -13px;
    rotate: 90deg;
  }

  &[data-side='right'] {
    left: -13px;
    rotate: -90deg;
  }
}

.ArrowFill {
  fill: white;

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

.ArrowOuterStroke {
  fill: oklch(14.5% 0 0deg);

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

.ArrowInnerStroke {
  fill: white;

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

.Item,
.SubmenuTrigger {
  outline: 0;
  cursor: default;
  -webkit-user-select: none;
  user-select: none;
  padding-block: 0.5rem;
  padding-left: 1rem;
  padding-right: 1.5rem;
  display: flex;
  font-size: 0.875rem;
  line-height: 1rem;

  &[data-highlighted] {
    z-index: 0;
    position: relative;
    color: white;

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

  &[data-highlighted]::before {
    content: '';
    z-index: -1;
    position: absolute;
    inset-block: 0;
    inset-inline: 0.25rem;
    background-color: oklch(14.5% 0 0deg);

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

  &[data-disabled] {
    color: oklch(55.6% 0 0deg);

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

.SubmenuTrigger {
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-right: 0.5rem;

  &[data-popup-open] {
    z-index: 0;
    position: relative;
  }

  &[data-popup-open]::before {
    content: '';
    z-index: -1;
    position: absolute;
    inset-block: 0;
    inset-inline: 0.25rem;
    background-color: oklch(97% 0 0deg);

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

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

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

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

  @media (prefers-color-scheme: dark) {
    background-color: white;
  }
}
/* index.tsx */
import * as React from 'react';
import { ContextMenu } from '@base-ui/react/context-menu';
import { Menu } from '@base-ui/react/menu';
import styles from './index.module.css';

export default function ExampleContextMenu() {
  return (
    <ContextMenu.Root>
      <ContextMenu.Trigger className={styles.Trigger}>Right click here</ContextMenu.Trigger>
      <ContextMenu.Portal>
        <ContextMenu.Positioner className={styles.Positioner}>
          <ContextMenu.Popup className={styles.Popup}>
            <ContextMenu.Item className={styles.Item}>Add to Library</ContextMenu.Item>

            <ContextMenu.SubmenuRoot>
              <ContextMenu.SubmenuTrigger className={styles.SubmenuTrigger}>
                Add to Playlist
                <CaretRightIcon />
              </ContextMenu.SubmenuTrigger>
              <ContextMenu.Portal>
                <ContextMenu.Positioner
                  className={styles.Positioner}
                  alignOffset={-4}
                  sideOffset={-4}
                >
                  <ContextMenu.Popup className={styles.SubmenuPopup}>
                    <ContextMenu.Item className={styles.Item}>Get Up!</ContextMenu.Item>
                    <ContextMenu.Item className={styles.Item}>Inside Out</ContextMenu.Item>
                    <ContextMenu.Item className={styles.Item}>Night Beats</ContextMenu.Item>
                    <Menu.Separator className={styles.Separator} />
                    <ContextMenu.Item className={styles.Item}>New playlist…</ContextMenu.Item>
                  </ContextMenu.Popup>
                </ContextMenu.Positioner>
              </ContextMenu.Portal>
            </ContextMenu.SubmenuRoot>

            <ContextMenu.Separator className={styles.Separator} />
            <ContextMenu.Item className={styles.Item}>Play Next</ContextMenu.Item>
            <ContextMenu.Item className={styles.Item}>Play Last</ContextMenu.Item>
            <ContextMenu.Separator className={styles.Separator} />
            <ContextMenu.Item className={styles.Item}>Favorite</ContextMenu.Item>
            <ContextMenu.Item className={styles.Item}>Share</ContextMenu.Item>
          </ContextMenu.Popup>
        </ContextMenu.Positioner>
      </ContextMenu.Portal>
    </ContextMenu.Root>
  );
}

function CaretRightIcon(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="M6 12V4l4.5 4z" />
    </svg>
  );
}

API 레퍼런스

Root

오른쪽 클릭이나 길게 누르면 활성화되는 컨텍스트 메뉴를 만드는 컴포넌트예요. 자체 HTML 요소를 렌더링하지 않아요.

Root Props:

Prop Type Default Description
defaultOpen boolean false 메뉴가 처음에 열려 있는지 여부. 제어(controlled) 메뉴를 렌더링하려면 open prop을 사용하세요.
open boolean - 메뉴가 현재 열려 있는지 여부.
onOpenChange ((open: boolean, eventDetails: ContextMenu.Root.ChangeEventDetails) => void) - 메뉴가 열리거나 닫힐 때 호출되는 이벤트 핸들러.
highlightItemOnHover boolean true 포인터가 항목 위를 지나갈 때 항목을 하이라이트할지 여부. 이 prop을 비활성화하면 CSS :hover를 :focus(data-highlighted) 상태와 구분할 수 있어요.
actionsRef React.RefObject<MenuRoot.Actions | null> - 명령형 동작에 대한 ref. unmount: 메뉴를 수동으로 제거(unmount)해요. 외부에서 제어하는 닫기 애니메이션이 끝난 뒤 호출하세요.close: 지정하면 메뉴를 명령형으로 닫을 수 있어요.
loopFocus boolean true 화살표 키로 목록 끝에 도달했을 때 키보드 포커스를 첫 항목으로 순환시킬지 여부.
onOpenChangeComplete ((open: boolean) => void) - 메뉴가 열리거나 닫힐 때 애니메이션이 끝난 뒤 호출되는 이벤트 핸들러.
disabled boolean false 컴포넌트가 사용자 상호작용을 무시할지 여부.
orientation MenuRoot.Orientation 'vertical' 메뉴의 시각적 방향. 로빙 포커스(roving focus)가 위/아래 또는 왼쪽/오른쪽 화살표 키를 사용할지 제어해요.
children React.ReactNode - -

Root.Props

Root props의 재내보내기예요.

Root.State

type ContextMenuRootState = {};

Root.Actions

type ContextMenuRootActions = { unmount: () => void; close: () => void };

Root.ChangeEventReason

type ContextMenuRootChangeEventReason =
  | 'trigger-hover'
  | 'trigger-focus'
  | 'trigger-press'
  | 'outside-press'
  | 'focus-out'
  | 'list-navigation'
  | 'escape-key'
  | 'item-press'
  | 'close-press'
  | 'sibling-open'
  | 'cancel-open'
  | 'imperative-action'
  | 'none';

Root.ChangeEventDetails

type ContextMenuRootChangeEventDetails = (
  | { reason: 'trigger-hover'; event: MouseEvent }
  | { reason: 'trigger-focus'; event: FocusEvent }
  | { reason: 'trigger-press'; event: MouseEvent | PointerEvent | TouchEvent | KeyboardEvent }
  | { reason: 'outside-press'; event: MouseEvent | PointerEvent | TouchEvent }
  | { reason: 'focus-out'; event: FocusEvent | KeyboardEvent }
  | { reason: 'list-navigation'; event: KeyboardEvent }
  | { reason: 'escape-key'; event: KeyboardEvent }
  | { reason: 'item-press'; event: MouseEvent | PointerEvent | KeyboardEvent }
  | { reason: 'close-press'; event: MouseEvent | PointerEvent | KeyboardEvent }
  | { reason: 'sibling-open'; event: Event }
  | { reason: 'cancel-open'; event: MouseEvent }
  | { reason: 'imperative-action'; event: Event }
  | { reason: 'none'; 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;
};

Trigger

오른쪽 클릭이나 길게 누르면 메뉴를 여는 영역이에요. <div> 요소를 렌더링해요.

Trigger Props:

Prop Type Default Description
className string | ((state: ContextMenu.Trigger.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: ContextMenu.Trigger.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: ContextMenu.Trigger.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Trigger Data Attributes:

Attribute Type Description
data-popup-open - 해당 컨텍스트 메뉴가 열려 있을 때 존재해요.
data-pressed - 해당 컨텍스트 메뉴가 열려 있을 때 존재해요.

Trigger.Props

Trigger props의 재내보내기예요.

Trigger.State

type ContextMenuTriggerState = {
  /** Whether the context menu is currently open. */
  open: boolean;
};

Portal

팝업을 DOM의 다른 부분으로 옮기는 포털 요소예요. 기본적으로 포털 요소는 <body>에 추가돼요. <div> 요소를 렌더링해요.

Portal Props:

Prop Type Default Description
container HTMLElement | ShadowRoot | React.RefObject<HTMLElement | ShadowRoot | null> | null - 포털 요소를 렌더링할 부모 요소.
className string | ((state: ContextMenu.Portal.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: ContextMenu.Portal.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
keepMounted boolean false 팝업이 숨겨져 있는 동안 포털을 DOM에 유지할지 여부.
render ReactElement | ((props: HTMLProps, state: ContextMenu.Portal.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Portal.Props

Portal props의 재내보내기예요.

Portal.State

type ContextMenuPortalState = {};

Backdrop

메뉴 팝업 아래에 표시되는 오버레이예요. <div> 요소를 렌더링해요.

Backdrop Props:

Prop Type Default Description
className string | ((state: ContextMenu.Backdrop.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: ContextMenu.Backdrop.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: ContextMenu.Backdrop.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Backdrop Data Attributes:

Attribute Type Description
data-open - 메뉴가 열려 있을 때 존재해요.
data-closed - 메뉴가 닫혀 있을 때 존재해요.
data-starting-style - 메뉴가 애니메이션으로 나타나기 시작할 때 존재해요.
data-ending-style - 메뉴가 애니메이션으로 사라질 때 존재해요.

Backdrop.Props

Backdrop props의 재내보내기예요.

Backdrop.State

type ContextMenuBackdropState = {
  /** Whether the menu is currently open. */
  open: boolean;
  /** The transition status of the component. */
  transitionStatus: TransitionStatus;
};

Positioner

포인터 또는 커스텀 앵커에 대해 컨텍스트 메뉴 팝업을 배치해요. <div> 요소를 렌더링해요.

Positioner Props:

Prop Type Default Description
disableAnchorTracking boolean false 팝업이 위치 기준 앵커의 레이아웃 이동을 추적하지 않게 할지 여부.
align Align 'start' 지정된 side를 기준으로 팝업을 어떻게 정렬할지.
alignOffset number | OffsetFunction - 정렬 축을 따라 추가로 적용할 오프셋(픽셀)이에요. 앵커와 positioner 요소의 크기, 그리고 side·alignment를 읽기 위해 오프셋을 반환하는 함수도 허용해요. 함수는 data 객체 파라미터를 받는데, 속성은 다음과 같아요. data.anchor: width와 height 속성을 가진 앵커 요소의 크기.data.positioner: width와 height 속성을 가진 positioner 요소의 크기.data.side: positioner가 정렬되는 앵커 요소의 side.data.align: positioner가 지정된 side에 대해 정렬되는 방식. 루트 컨텍스트 메뉴에서 side가 지정되지 않고 align이 'center'가 아니면 기본값은 2예요. 그 외에는 기본값이 0이에요.
side Side 'bottom' 팝업을 정렬할 앵커 요소의 side. 충돌을 피하기 위해 자동으로 변경될 수 있어요. 서브메뉴는 기본적으로 'inline-end'를 사용해요.
sideOffset number | OffsetFunction - 앵커와 팝업 사이의 거리(픽셀)예요. 앵커와 positioner 요소의 크기, 그리고 side·alignment를 읽기 위해 거리를 반환하는 함수도 허용해요. 함수는 data 객체 파라미터를 받는데, 속성은 다음과 같아요. data.anchor: width와 height 속성을 가진 앵커 요소의 크기.data.positioner: width와 height 속성을 가진 positioner 요소의 크기.data.side: positioner가 정렬되는 앵커 요소의 side.data.align: positioner가 지정된 side에 대해 정렬되는 방식. 루트 컨텍스트 메뉴에서 side가 지정되지 않고 align이 'center'가 아니면 기본값은 -5예요. 그 외에는 기본값이 0이에요.
arrowPadding number - 화살표와 팝업 가장자리 사이에 유지할 최소 거리예요. 루트 컨텍스트 메뉴는 항상 0을 사용해요. 서브메뉴는 기본값이 5예요.
anchor Element | VirtualElement | React.RefObject<Element | null> | (() => Element | VirtualElement | null) | null - 팝업을 배치할 기준이 되는 요소예요. 기본적으로 루트 컨텍스트 메뉴는 포인터 위치에 배치되고, 서브메뉴는 트리거에 대해 배치돼요.
collisionAvoidance CollisionAvoidance - 팝업 배치 시 충돌을 처리하는 방법을 정해요. side는 선호하는 배치 축(top/bottom 또는 left/right)에서의 넘침을 제어해요. 'flip': 맞으면 요청한 side를 유지하고, 그렇지 않으면 반대쪽 side를 시도해요. (top과 bottom, 또는 left와 right).'shift': side를 절대 바꾸지 않고, 요청한 side를 유지한 채 팝업을 클리핑 경계 안에서 움직여 보이게 해요.'none': side 축 넘침을 보정하지 않아요. align은 정렬 축(start/center/end)에서의 넘침을 제어해요. 'flip': side는 유지하되, 요청한 정렬이 넘칠 때 start와 end를 바꿔요.'shift': side와 요청한 정렬을 유지한 채 팝업을 정렬 축을 따라 조금씩 밀어 맞춰요.'none': 정렬 축 넘침을 보정하지 않아요. fallbackAxisSide는 선호하는 축이 맞지 않을 때 수직 축에서의 폴백 동작을 제어해요. 'start': 수직 폴백을 허용하고 논리적 start쪽을 먼저 시도해요. (LTR에서 top을 bottom보다 먼저, 또는 left를 right보다 먼저).'end': 수직 폴백을 허용하고 논리적 end 쪽을 먼저 시도해요. (LTR에서 bottom을 top보다 먼저, 또는 right를 left보다 먼저).'none': 수직 축으로 폴백하지 않아요. side가 'shift'일 때 align을 명시적으로 설정하면 'shift' 또는 'none'만 지원해요. align을 생략하면 기본값은 'flip'이에요.
collisionBoundary Boundary 'clipping-ancestors' 팝업이 제한되는 영역을 구분하는 요소 또는 사각형이에요.
collisionPadding Padding 5 충돌 경계의 가장자리에서 유지할 추가 공간이에요.
sticky boolean false 앵커 요소가 뷰포트 밖으로 스크롤된 후에도 팝업을 뷰포트에 유지할지 여부.
className string | ((state: ContextMenu.Positioner.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: ContextMenu.Positioner.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: ContextMenu.Positioner.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

alignOffset Prop Example:

<ContextMenu.Positioner
  alignOffset={({ side, anchor }) => {
    return side === 'top' || side === 'bottom' ? anchor.width : anchor.height;
  }}
/>

sideOffset Prop Example:

<ContextMenu.Positioner
  sideOffset={({ side, anchor }) => {
    return side === 'top' || side === 'bottom' ? anchor.height : anchor.width;
  }}
/>

collisionAvoidance Prop Example:

<Positioner
  collisionAvoidance={{
    side: 'shift',
    align: 'shift',
    fallbackAxisSide: 'none',
  }}
/>

Positioner Data Attributes:

Attribute Type Description
data-open - 메뉴 팝업이 열려 있을 때 존재해요.
data-closed - 메뉴 팝업이 닫혀 있을 때 존재해요.
data-anchor-hidden - 앵커가 숨겨져 있을 때 존재해요.
data-align 'start' | 'center' | 'end' 팝업이 지정된 side에 대해 어떻게 정렬되는지 나타내요.
data-side 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start' 팝업이 앵커에 대해 어느 side에 배치되는지 나타내요.

Positioner CSS Variables:

Variable Type Description
--anchor-height number 앵커의 높이.
--anchor-width number 앵커의 너비.
--available-height number 앵커와 뷰포트 가장자리 사이의 사용 가능한 높이.
--available-width number 앵커와 뷰포트 가장자리 사이의 사용 가능한 너비.
--positioner-height number 메뉴 positioner의 높이. CSS로 크기 변화를 애니메이션할 때 height를 이 값으로 설정하는 것이 중요해요.
--positioner-width number 메뉴 positioner의 너비. CSS로 크기 변화를 애니메이션할 때 width를 이 값으로 설정하는 것이 중요해요.
--transform-origin string 이 요소가 기준으로 삼는 좌표예요. 애니메이션과 전환에 사용돼요.

Positioner.Props

Positioner props의 재내보내기예요.

Positioner.State

type ContextMenuPositionerState = {
  /** Whether the menu is currently open. */
  open: boolean;
  /** The side of the anchor the component is placed on. */
  side: Side;
  /** The alignment of the component relative to the anchor. */
  align: Align;
  /** Whether the anchor element is hidden. */
  anchorHidden: boolean;
  /** Whether the component is nested. */
  nested: boolean;
  /** Whether CSS transitions should be disabled. */
  instant: string | undefined;
};

메뉴 항목들의 컨테이너예요. <div> 요소를 렌더링해요.

Popup Props:

Prop Type Default Description
finalFocus boolean | React.RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | void | HTMLElement | null) - 메뉴가 닫힐 때 포커스할 요소를 정해요. false: 포커스를 옮기지 않아요.true: 기본 동작(트리거 또는 이전에 포커스된 요소)에 따라 포커스를 옮겨요.RefObject: ref 요소로 포커스를 옮겨요.function: 상호작용 유형(mouse, touch, pen, 또는 keyboard)으로 호출돼요. 포커스할 요소를 반환하거나, 기본 동작을 쓰려면 true, 아무것도 하지 않으려면 false/undefined를 반환해요.
children React.ReactNode - -
className string | ((state: ContextMenu.Popup.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: ContextMenu.Popup.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: ContextMenu.Popup.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Popup Data Attributes:

Attribute Type Description
data-open - 메뉴가 열려 있을 때 존재해요.
data-closed - 메뉴가 닫혀 있을 때 존재해요.
data-align 'start' | 'center' | 'end' 팝업이 지정된 side에 대해 어떻게 정렬되는지 나타내요.
data-instant 'click' | 'dismiss' | 'group' | 'trigger-change' 애니메이션이 즉시 이루어져야 할 때 존재해요.
data-side 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start' 팝업이 앵커에 대해 어느 side에 배치되는지 나타내요.
data-starting-style - 메뉴가 애니메이션으로 나타나기 시작할 때 존재해요.
data-ending-style - 메뉴가 애니메이션으로 사라질 때 존재해요.

Popup.Props

Popup props의 재내보내기예요.

Popup.State

type ContextMenuPopupState = {
  /** The transition status of the component. */
  transitionStatus: TransitionStatus;
  /** The side of the anchor the component is placed on. */
  side: Side;
  /** The alignment of the component relative to the anchor. */
  align: Align;
  /** Whether the menu is currently open. */
  open: boolean;
  /** Whether the component is nested. */
  nested: boolean;
  /** Whether transitions should be skipped. */
  instant: 'dismiss' | 'click' | 'group' | 'trigger-change' | undefined;
};

Arrow

메뉴 앵커에 대해 배치되는 요소를 표시해요. <div> 요소를 렌더링해요.

Arrow Props:

Prop Type Default Description
className string | ((state: ContextMenu.Arrow.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: ContextMenu.Arrow.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: ContextMenu.Arrow.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Arrow Data Attributes:

Attribute Type Description
data-open - 메뉴 팝업이 열려 있을 때 존재해요.
data-closed - 메뉴 팝업이 닫혀 있을 때 존재해요.
data-uncentered - 메뉴 화살표가 중앙에 있지 않을 때 존재해요.
data-align 'start' | 'center' | 'end' 팝업이 지정된 side에 대해 어떻게 정렬되는지 나타내요.
data-side 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start' 팝업이 앵커에 대해 어느 side에 배치되는지 나타내요.

Arrow.Props

Arrow props의 재내보내기예요.

Arrow.State

type ContextMenuArrowState = {
  /** Whether the menu is currently open. */
  open: boolean;
  /** The side of the anchor the component is placed on. */
  side: Side;
  /** The alignment of the component relative to the anchor. */
  align: Align;
  /** Whether the arrow cannot be centered on the anchor. */
  uncentered: boolean;
};

Item

메뉴의 개별 상호작용 항목이에요. <div> 요소를 렌더링해요.

Item Props:

Prop Type Default Description
label string - 키보드 텍스트 탐색 중 항목이 매칭될 때 사용할 텍스트 레이블을 덮어써요.
onClick ((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) - 메뉴 항목의 클릭 핸들러.
closeOnClick boolean true 항목을 클릭했을 때 메뉴를 닫을지 여부.
nativeButton boolean false render prop으로 요소를 대체할 때 네이티브 <button> 요소를 렌더링할지 여부. 렌더링되는 요소가 네이티브 버튼이면 true로 설정하세요.
disabled boolean false 컴포넌트가 사용자 상호작용을 무시할지 여부.
className string | ((state: ContextMenu.Item.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: ContextMenu.Item.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: ContextMenu.Item.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Item Data Attributes:

Attribute Type Description
data-highlighted - 메뉴 항목이 하이라이트될 때 존재해요.
data-disabled - 메뉴 항목이 비활성화될 때 존재해요.

Item.Props

Item props의 재내보내기예요.

Item.State

type ContextMenuItemState = {
  /** Whether the item should ignore user interaction. */
  disabled: boolean;
  /** Whether the item is highlighted. */
  highlighted: boolean;
};

Group

관련 메뉴 항목을 해당 레이블과 함께 묶어요. <div> 요소를 렌더링해요.

Group Props:

Prop Type Default Description
children React.ReactNode - 컴포넌트의 콘텐츠.
className string | ((state: ContextMenu.Group.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: ContextMenu.Group.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: ContextMenu.Group.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Group.Props

Group props의 재내보내기예요.

Group.State

type ContextMenuGroupState = {};

GroupLabel

부모 그룹과 자동으로 연결되는 접근 가능한 레이블이에요. <div> 요소를 렌더링해요.

GroupLabel Props:

Prop Type Default Description
className string | ((state: ContextMenu.GroupLabel.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: ContextMenu.GroupLabel.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: ContextMenu.GroupLabel.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

GroupLabel.Props

GroupLabel props의 재내보내기예요.

GroupLabel.State

type ContextMenuGroupLabelState = {};

Separator

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

Separator Props:

Prop Type Default Description
orientation Orientation 'horizontal' 구분선의 방향.
className string | ((state: SeparatorState) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: SeparatorState) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: SeparatorState) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Separator.Props

Separator props의 재내보내기예요.

Separator.State

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

서브메뉴의 모든 파트를 묶어요. 자체 HTML 요소를 렌더링하지 않아요.

SubmenuRoot Props:

Prop Type Default Description
defaultOpen boolean false 메뉴가 처음에 열려 있는지 여부. 제어(controlled) 메뉴를 렌더링하려면 open prop을 사용하세요.
open boolean - 메뉴가 현재 열려 있는지 여부.
onOpenChange ((open: boolean, eventDetails: ContextMenu.SubmenuRoot.ChangeEventDetails) => void) - 메뉴가 열리거나 닫힐 때 호출되는 이벤트 핸들러.
highlightItemOnHover boolean true 포인터가 항목 위를 지나갈 때 항목을 하이라이트할지 여부. 이 prop을 비활성화하면 CSS :hover를 :focus(data-highlighted) 상태와 구분할 수 있어요.
actionsRef React.RefObject<MenuRoot.Actions | null> - 명령형 동작에 대한 ref. unmount: 메뉴를 수동으로 제거(unmount)해요. 외부에서 제어하는 닫기 애니메이션이 끝난 뒤 호출하세요.close: 지정하면 메뉴를 명령형으로 닫을 수 있어요.
closeParentOnEsc boolean false 서브메뉴에 있을 때 Escape 키를 누르면 전체 메뉴를 닫을지, 현재 자식 메뉴만 닫을지 결정해요.
loopFocus boolean true 화살표 키로 목록 끝에 도달했을 때 키보드 포커스를 첫 항목으로 순환시킬지 여부.
onOpenChangeComplete ((open: boolean) => void) - 메뉴가 열리거나 닫힐 때 애니메이션이 끝난 뒤 호출되는 이벤트 핸들러.
disabled boolean false 컴포넌트가 사용자 상호작용을 무시할지 여부.
orientation MenuRoot.Orientation 'vertical' 메뉴의 시각적 방향. 로빙 포커스가 위/아래 또는 왼쪽/오른쪽 화살표 키를 사용할지 제어해요.
children React.ReactNode - 서브메뉴의 콘텐츠.

SubmenuRoot props의 재내보내기예요.

type ContextMenuSubmenuRootState = {};
type ContextMenuSubmenuRootChangeEventReason =
  | 'trigger-hover'
  | 'trigger-focus'
  | 'trigger-press'
  | 'outside-press'
  | 'focus-out'
  | 'list-navigation'
  | 'escape-key'
  | 'item-press'
  | 'close-press'
  | 'sibling-open'
  | 'cancel-open'
  | 'imperative-action'
  | 'none';
type ContextMenuSubmenuRootChangeEventDetails = (
  | { reason: 'trigger-hover'; event: MouseEvent }
  | { reason: 'trigger-focus'; event: FocusEvent }
  | { reason: 'trigger-press'; event: MouseEvent | PointerEvent | TouchEvent | KeyboardEvent }
  | { reason: 'outside-press'; event: MouseEvent | PointerEvent | TouchEvent }
  | { reason: 'focus-out'; event: FocusEvent | KeyboardEvent }
  | { reason: 'list-navigation'; event: KeyboardEvent }
  | { reason: 'escape-key'; event: KeyboardEvent }
  | { reason: 'item-press'; event: MouseEvent | PointerEvent | KeyboardEvent }
  | { reason: 'close-press'; event: MouseEvent | PointerEvent | KeyboardEvent }
  | { reason: 'sibling-open'; event: Event }
  | { reason: 'cancel-open'; event: MouseEvent }
  | { reason: 'imperative-action'; event: Event }
  | { reason: 'none'; 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;
  preventUnmountOnClose: preventUnmountOnClose;
};

서브메뉴를 여는 메뉴 항목이에요. <div> 요소를 렌더링해요.

SubmenuTrigger Props:

Prop Type Default Description
label string - 키보드 텍스트 탐색 중 항목이 매칭될 때 사용할 텍스트 레이블을 덮어써요.
onClick ((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) - -
nativeButton boolean false render prop으로 요소를 대체할 때 네이티브 <button> 요소를 렌더링할지 여부. 렌더링되는 요소가 네이티브 버튼이면 true로 설정하세요.
disabled boolean false 컴포넌트가 사용자 상호작용을 무시할지 여부.
openOnHover boolean true 트리거를 호버했을 때도 메뉴를 열지 여부.
delay number 100 호버 시 메뉴가 열릴 수 있을 때까지 기다릴 시간(밀리초)이에요. openOnHover prop이 필요해요.
closeDelay number 0 호버로 열린 메뉴를 닫기 전에 기다릴 시간(밀리초)이에요. openOnHover prop이 필요해요.
className string | ((state: ContextMenu.SubmenuTrigger.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: ContextMenu.SubmenuTrigger.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: ContextMenu.SubmenuTrigger.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

SubmenuTrigger Data Attributes:

Attribute Type Description
data-popup-open - 해당 서브메뉴가 열려 있을 때 존재해요.
data-highlighted - 서브메뉴 트리거가 하이라이트될 때 존재해요.
data-disabled - 서브메뉴 트리거가 비활성화될 때 존재해요.

SubmenuTrigger props의 재내보내기예요.

type ContextMenuSubmenuTriggerState = {
  /** Whether the component should ignore user interaction. */
  disabled: boolean;
  /** Whether the item is highlighted. */
  highlighted: boolean;
  /** Whether the menu is currently open. */
  open: boolean;
};

RadioGroup

관련 라디오 항목들을 묶어요. <div> 요소를 렌더링해요.

RadioGroup Props:

Prop Type Default Description
defaultValue any - 처음에 선택되어야 하는 라디오 항목의 비제어(controlled) 값. 제어 라디오 그룹을 렌더링하려면 value prop을 사용하세요.
value any - 현재 선택되어야 하는 라디오 항목의 제어 값. 비제어 라디오 그룹을 렌더링하려면 defaultValue prop을 사용하세요.
onValueChange ((value: any, eventDetails: ContextMenu.RadioGroup.ChangeEventDetails) => void) - 선택 값이 변경될 때 호출되는 함수.
disabled boolean false 컴포넌트가 사용자 상호작용을 무시할지 여부.
children React.ReactNode - 컴포넌트의 콘텐츠.
className string | ((state: ContextMenu.RadioGroup.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: ContextMenu.RadioGroup.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: ContextMenu.RadioGroup.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

RadioGroup.Props

RadioGroup props의 재내보내기예요.

RadioGroup.State

type ContextMenuRadioGroupState = {
  /** Whether the component is disabled. */
  disabled: boolean;
};

RadioGroup.ChangeEventReason

type ContextMenuRadioGroupChangeEventReason =
  | 'trigger-hover'
  | 'trigger-focus'
  | 'trigger-press'
  | 'outside-press'
  | 'focus-out'
  | 'list-navigation'
  | 'escape-key'
  | 'item-press'
  | 'close-press'
  | 'sibling-open'
  | 'cancel-open'
  | 'imperative-action'
  | 'none';

RadioGroup.ChangeEventDetails

type ContextMenuRadioGroupChangeEventDetails = (
  | { reason: 'trigger-hover'; event: MouseEvent }
  | { reason: 'trigger-focus'; event: FocusEvent }
  | { reason: 'trigger-press'; event: MouseEvent | PointerEvent | TouchEvent | KeyboardEvent }
  | { reason: 'outside-press'; event: MouseEvent | PointerEvent | TouchEvent }
  | { reason: 'focus-out'; event: FocusEvent | KeyboardEvent }
  | { reason: 'list-navigation'; event: KeyboardEvent }
  | { reason: 'escape-key'; event: KeyboardEvent }
  | { reason: 'item-press'; event: MouseEvent | PointerEvent | KeyboardEvent }
  | { reason: 'close-press'; event: MouseEvent | PointerEvent | KeyboardEvent }
  | { reason: 'sibling-open'; event: Event }
  | { reason: 'cancel-open'; event: MouseEvent }
  | { reason: 'imperative-action'; event: Event }
  | { reason: 'none'; 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;
  preventUnmountOnClose: preventUnmountOnClose;
};

RadioItem

주어진 그룹에서 라디오 버튼처럼 동작하는 메뉴 항목이에요. <div> 요소를 렌더링해요.

RadioItem Props:

Prop Type Default Description
label string - 키보드 텍스트 탐색 중 항목이 매칭될 때 사용할 텍스트 레이블을 덮어써요.
value* any - 라디오 항목의 값. 항목이 선택될 때 ContextMenu.RadioGroup에 설정될 값이에요.
onClick ((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) - 메뉴 항목의 클릭 핸들러.
closeOnClick boolean false 항목을 클릭했을 때 메뉴를 닫을지 여부.
nativeButton boolean false render prop으로 요소를 대체할 때 네이티브 <button> 요소를 렌더링할지 여부. 렌더링되는 요소가 네이티브 버튼이면 true로 설정하세요.
disabled boolean false 컴포넌트가 사용자 상호작용을 무시할지 여부.
className string | ((state: ContextMenu.RadioItem.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: ContextMenu.RadioItem.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: ContextMenu.RadioItem.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

RadioItem Data Attributes:

Attribute Type Description
data-checked - 메뉴 라디오 항목이 선택되었을 때 존재해요.
data-unchecked - 메뉴 라디오 항목이 선택되지 않았을 때 존재해요.
data-highlighted - 메뉴 라디오 항목이 하이라이트될 때 존재해요.
data-disabled - 메뉴 라디오 항목이 비활성화될 때 존재해요.

RadioItem.Props

RadioItem props의 재내보내기예요.

RadioItem.State

type ContextMenuRadioItemState = {
  /** Whether the radio item should ignore user interaction. */
  disabled: boolean;
  /** Whether the radio item is currently highlighted. */
  highlighted: boolean;
  /** Whether the radio item is currently selected. */
  checked: boolean;
};

RadioItemIndicator

라디오 항목이 선택되었는지 나타내요. <span> 요소를 렌더링해요.

RadioItemIndicator Props:

Prop Type Default Description
className string | ((state: ContextMenu.RadioItemIndicator.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: ContextMenu.RadioItemIndicator.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
keepMounted boolean false 라디오 항목이 비활성일 때 HTML 요소를 DOM에 유지할지 여부.
render ReactElement | ((props: HTMLProps, state: ContextMenu.RadioItemIndicator.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

RadioItemIndicator Data Attributes:

Attribute Type Description
data-checked - 메뉴 라디오 항목이 선택되었을 때 존재해요.
data-unchecked - 메뉴 라디오 항목이 선택되지 않았을 때 존재해요.
data-disabled - 메뉴 라디오 항목이 비활성화될 때 존재해요.
data-starting-style - 라디오 인디케이터가 애니메이션으로 나타나기 시작할 때 존재해요.
data-ending-style - 라디오 인디케이터가 애니메이션으로 사라질 때 존재해요.

RadioItemIndicator.Props

RadioItemIndicator props의 재내보내기예요.

RadioItemIndicator.State

type ContextMenuRadioItemIndicatorState = {
  /** Whether the radio item is currently selected. */
  checked: boolean;
  /** Whether the component should ignore user interaction. */
  disabled: boolean;
  /** Whether the item is highlighted. */
  highlighted: boolean;
  /** The transition status of the component. */
  transitionStatus: TransitionStatus;
};

CheckboxItem

설정을 켜고 끄는 메뉴 항목이에요. <div> 요소를 렌더링해요.

CheckboxItem Props:

Prop Type Default Description
label string - 키보드 텍스트 탐색 중 항목이 매칭될 때 사용할 텍스트 레이블을 덮어써요.
defaultChecked boolean false 체크박스 항목이 처음에 체크되어 있는지 여부. 제어 체크박스 항목을 렌더링하려면 checked prop을 사용하세요.
checked boolean - 체크박스 항목이 현재 체크되어 있는지 여부. 비제어 체크박스 항목을 렌더링하려면 defaultChecked prop을 사용하세요.
onCheckedChange ((checked: boolean, eventDetails: ContextMenu.CheckboxItem.ChangeEventDetails) => void) - 체크박스 항목이 체크되거나 해제될 때 호출되는 이벤트 핸들러.
onClick ((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) - 메뉴 항목의 클릭 핸들러.
closeOnClick boolean false 항목을 클릭했을 때 메뉴를 닫을지 여부.
nativeButton boolean false render prop으로 요소를 대체할 때 네이티브 <button> 요소를 렌더링할지 여부. 렌더링되는 요소가 네이티브 버튼이면 true로 설정하세요.
disabled boolean false 컴포넌트가 사용자 상호작용을 무시할지 여부.
className string | ((state: ContextMenu.CheckboxItem.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: ContextMenu.CheckboxItem.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: ContextMenu.CheckboxItem.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

CheckboxItem Data Attributes:

Attribute Type Description
data-checked - 메뉴 체크박스 항목이 체크되었을 때 존재해요.
data-unchecked - 메뉴 체크박스 항목이 체크되지 않았을 때 존재해요.
data-highlighted - 메뉴 체크박스 항목이 하이라이트될 때 존재해요.
data-disabled - 메뉴 체크박스 항목이 비활성화될 때 존재해요.

CheckboxItem.Props

CheckboxItem props의 재내보내기예요.

CheckboxItem.State

type ContextMenuCheckboxItemState = {
  /** Whether the checkbox item should ignore user interaction. */
  disabled: boolean;
  /** Whether the checkbox item is currently highlighted. */
  highlighted: boolean;
  /** Whether the checkbox item is currently ticked. */
  checked: boolean;
};

CheckboxItem.ChangeEventReason

type ContextMenuCheckboxItemChangeEventReason =
  | 'trigger-hover'
  | 'trigger-focus'
  | 'trigger-press'
  | 'outside-press'
  | 'focus-out'
  | 'list-navigation'
  | 'escape-key'
  | 'item-press'
  | 'close-press'
  | 'sibling-open'
  | 'cancel-open'
  | 'imperative-action'
  | 'none';

CheckboxItem.ChangeEventDetails

type ContextMenuCheckboxItemChangeEventDetails = (
  | { reason: 'trigger-hover'; event: MouseEvent }
  | { reason: 'trigger-focus'; event: FocusEvent }
  | { reason: 'trigger-press'; event: MouseEvent | PointerEvent | TouchEvent | KeyboardEvent }
  | { reason: 'outside-press'; event: MouseEvent | PointerEvent | TouchEvent }
  | { reason: 'focus-out'; event: FocusEvent | KeyboardEvent }
  | { reason: 'list-navigation'; event: KeyboardEvent }
  | { reason: 'escape-key'; event: KeyboardEvent }
  | { reason: 'item-press'; event: MouseEvent | PointerEvent | KeyboardEvent }
  | { reason: 'close-press'; event: MouseEvent | PointerEvent | KeyboardEvent }
  | { reason: 'sibling-open'; event: Event }
  | { reason: 'cancel-open'; event: MouseEvent }
  | { reason: 'imperative-action'; event: Event }
  | { reason: 'none'; 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;
  preventUnmountOnClose: preventUnmountOnClose;
};

CheckboxItemIndicator

체크박스 항목이 체크되었는지 나타내요. <span> 요소를 렌더링해요.

CheckboxItemIndicator Props:

Prop Type Default Description
className string | ((state: ContextMenu.CheckboxItemIndicator.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: ContextMenu.CheckboxItemIndicator.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
keepMounted boolean false 체크박스 항목이 체크되지 않았을 때 HTML 요소를 DOM에 유지할지 여부.
render ReactElement | ((props: HTMLProps, state: ContextMenu.CheckboxItemIndicator.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

CheckboxItemIndicator Data Attributes:

Attribute Type Description
data-checked - 메뉴 체크박스 항목이 체크되었을 때 존재해요.
data-unchecked - 메뉴 체크박스 항목이 체크되지 않았을 때 존재해요.
data-disabled - 메뉴 체크박스 항목이 비활성화될 때 존재해요.
data-starting-style - 인디케이터가 애니메이션으로 나타나기 시작할 때 존재해요.
data-ending-style - 인디케이터가 애니메이션으로 사라질 때 존재해요.

CheckboxItemIndicator.Props

CheckboxItemIndicator props의 재내보내기예요.

CheckboxItemIndicator.State

type ContextMenuCheckboxItemIndicatorState = {
  /** Whether the checkbox item is currently ticked. */
  checked: boolean;
  /** Whether the component should ignore user interaction. */
  disabled: boolean;
  /** Whether the item is highlighted. */
  highlighted: boolean;
  /** The transition status of the component. */
  transitionStatus: TransitionStatus;
};

LinkItem

다른 페이지나 섹션으로 이동할 수 있는 메뉴의 링크예요. <a> 요소를 렌더링해요.

LinkItem Props:

Prop Type Default Description
label string - 키보드 텍스트 탐색 중 항목이 매칭될 때 사용할 텍스트 레이블을 덮어써요.
closeOnClick boolean false 항목을 클릭했을 때 메뉴를 닫을지 여부.
className string | ((state: ContextMenu.LinkItem.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: ContextMenu.LinkItem.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>, state: ContextMenu.LinkItem.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

LinkItem Data Attributes:

Attribute Type Description
data-highlighted - 링크가 하이라이트될 때 존재해요.

LinkItem.Props

LinkItem props의 재내보내기예요.

LinkItem.State

type ContextMenuLinkItemState = {
  /** Whether the item is highlighted. */
  highlighted: boolean;
};

External Types

Orientation

type Orientation = 'horizontal' | 'vertical';

Side

type Side = 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start';

OffsetFunction

type OffsetFunction = (data: {
  side: 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start';
  align: 'start' | 'center' | 'end';
  anchor: { width: number; height: number };
  positioner: { width: number; height: number };
}) => number;

Align

type Align = 'start' | 'center' | 'end';

InteractionType

type InteractionType = 'mouse' | 'touch' | 'pen' | 'keyboard' | '';

preventUnmountOnClose

type preventUnmountOnClose = () => void;

내보내기 그룹 (Export Groups)

  • ContextMenu.Root: ContextMenu.Root, ContextMenu.Root.State, ContextMenu.Root.Props, ContextMenu.Root.Actions, ContextMenu.Root.ChangeEventReason, ContextMenu.Root.ChangeEventDetails
  • ContextMenu.Trigger: ContextMenu.Trigger, ContextMenu.Trigger.State, ContextMenu.Trigger.Props
  • ContextMenu.Backdrop: ContextMenu.Backdrop, ContextMenu.Backdrop.State, ContextMenu.Backdrop.Props
  • ContextMenu.Portal: ContextMenu.Portal, ContextMenu.Portal.State, ContextMenu.Portal.Props
  • ContextMenu.Positioner: ContextMenu.Positioner, ContextMenu.Positioner.Props, ContextMenu.Positioner.State
  • ContextMenu.Popup: ContextMenu.Popup, ContextMenu.Popup.Props, ContextMenu.Popup.State
  • ContextMenu.Arrow: ContextMenu.Arrow, ContextMenu.Arrow.State, ContextMenu.Arrow.Props
  • ContextMenu.Group: ContextMenu.Group, ContextMenu.Group.Props, ContextMenu.Group.State
  • ContextMenu.GroupLabel: ContextMenu.GroupLabel, ContextMenu.GroupLabel.Props, ContextMenu.GroupLabel.State
  • ContextMenu.Item: ContextMenu.Item, ContextMenu.Item.State, ContextMenu.Item.Props
  • ContextMenu.CheckboxItem: ContextMenu.CheckboxItem, ContextMenu.CheckboxItem.State, ContextMenu.CheckboxItem.Props, ContextMenu.CheckboxItem.ChangeEventReason, ContextMenu.CheckboxItem.ChangeEventDetails
  • ContextMenu.CheckboxItemIndicator: ContextMenu.CheckboxItemIndicator, ContextMenu.CheckboxItemIndicator.Props, ContextMenu.CheckboxItemIndicator.State
  • ContextMenu.LinkItem: ContextMenu.LinkItem, ContextMenu.LinkItem.State, ContextMenu.LinkItem.Props
  • ContextMenu.RadioGroup: ContextMenu.RadioGroup, ContextMenu.RadioGroup.Props, ContextMenu.RadioGroup.State, ContextMenu.RadioGroup.ChangeEventReason, ContextMenu.RadioGroup.ChangeEventDetails
  • ContextMenu.RadioItem: ContextMenu.RadioItem, ContextMenu.RadioItem.State, ContextMenu.RadioItem.Props
  • ContextMenu.RadioItemIndicator: ContextMenu.RadioItemIndicator, ContextMenu.RadioItemIndicator.Props, ContextMenu.RadioItemIndicator.State
  • ContextMenu.SubmenuRoot: ContextMenu.SubmenuRoot, ContextMenu.SubmenuRoot.Props, ContextMenu.SubmenuRoot.State, ContextMenu.SubmenuRoot.ChangeEventReason, ContextMenu.SubmenuRoot.ChangeEventDetails
  • ContextMenu.SubmenuTrigger: ContextMenu.SubmenuTrigger, ContextMenu.SubmenuTrigger.Props, ContextMenu.SubmenuTrigger.State
  • ContextMenu.Separator: ContextMenu.Separator, ContextMenu.Separator.Props, ContextMenu.Separator.State
  • Default: ContextMenuBackdropProps, ContextMenuBackdropState, ContextMenuPortalProps, ContextMenuPortalState, ContextMenuPopupProps, ContextMenuPopupState, ContextMenuArrowProps, ContextMenuArrowState, ContextMenuGroupProps, ContextMenuGroupState, ContextMenuGroupLabelProps, ContextMenuGroupLabelState, ContextMenuItemProps, ContextMenuItemState, ContextMenuLinkItemProps, ContextMenuLinkItemState, ContextMenuCheckboxItemProps, ContextMenuCheckboxItemState, ContextMenuCheckboxItemIndicatorProps, ContextMenuCheckboxItemIndicatorState, ContextMenuRadioGroupProps, ContextMenuRadioGroupState, ContextMenuRadioItemProps, ContextMenuRadioItemState, ContextMenuRadioItemIndicatorProps, ContextMenuRadioItemIndicatorState, ContextMenuSubmenuRootProps, ContextMenuSubmenuRootState, ContextMenuSubmenuTriggerProps, ContextMenuSubmenuTriggerState, ContextMenuRootState, ContextMenuRootProps, ContextMenuRootActions, ContextMenuRootChangeEventReason, ContextMenuRootChangeEventDetails, ContextMenuTriggerState, ContextMenuTriggerProps, ContextMenuPositionerState, ContextMenuPositionerProps

Canonical Types

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

  • ContextMenu.Root.State: ContextMenuRootState
  • ContextMenu.Root.Props: ContextMenuRootProps
  • ContextMenu.Root.Actions: ContextMenuRootActions
  • ContextMenu.Root.ChangeEventReason: ContextMenuRootChangeEventReason
  • ContextMenu.Root.ChangeEventDetails: ContextMenuRootChangeEventDetails
  • ContextMenu.Trigger.State: ContextMenuTriggerState
  • ContextMenu.Trigger.Props: ContextMenuTriggerProps
  • ContextMenu.Backdrop.State: ContextMenuBackdropState
  • ContextMenu.Backdrop.Props: ContextMenuBackdropProps
  • ContextMenu.Portal.State: ContextMenuPortalState
  • ContextMenu.Portal.Props: ContextMenuPortalProps
  • ContextMenu.Positioner.Props: ContextMenuPositionerProps
  • ContextMenu.Positioner.State: ContextMenuPositionerState
  • ContextMenu.Popup.Props: ContextMenuPopupProps
  • ContextMenu.Popup.State: ContextMenuPopupState
  • ContextMenu.Arrow.State: ContextMenuArrowState
  • ContextMenu.Arrow.Props: ContextMenuArrowProps
  • ContextMenu.Group.Props: ContextMenuGroupProps
  • ContextMenu.Group.State: ContextMenuGroupState
  • ContextMenu.GroupLabel.Props: ContextMenuGroupLabelProps
  • ContextMenu.GroupLabel.State: ContextMenuGroupLabelState
  • ContextMenu.Item.State: ContextMenuItemState
  • ContextMenu.Item.Props: ContextMenuItemProps
  • ContextMenu.CheckboxItem.State: ContextMenuCheckboxItemState
  • ContextMenu.CheckboxItem.Props: ContextMenuCheckboxItemProps
  • ContextMenu.CheckboxItemIndicator.Props: ContextMenuCheckboxItemIndicatorProps
  • ContextMenu.CheckboxItemIndicator.State: ContextMenuCheckboxItemIndicatorState
  • ContextMenu.LinkItem.State: ContextMenuLinkItemState
  • ContextMenu.LinkItem.Props: ContextMenuLinkItemProps
  • ContextMenu.RadioGroup.Props: ContextMenuRadioGroupProps
  • ContextMenu.RadioGroup.State: ContextMenuRadioGroupState
  • ContextMenu.RadioItem.State: ContextMenuRadioItemState
  • ContextMenu.RadioItem.Props: ContextMenuRadioItemProps
  • ContextMenu.RadioItemIndicator.Props: ContextMenuRadioItemIndicatorProps
  • ContextMenu.RadioItemIndicator.State: ContextMenuRadioItemIndicatorState
  • ContextMenu.SubmenuRoot.Props: ContextMenuSubmenuRootProps
  • ContextMenu.SubmenuRoot.State: ContextMenuSubmenuRootState
  • ContextMenu.SubmenuTrigger.Props: ContextMenuSubmenuTriggerProps
  • ContextMenu.SubmenuTrigger.State: ContextMenuSubmenuTriggerState

더 알아보기 (Learn more)