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

내비게이션 메뉴

원문 보기 위키 갱신

내비게이션 메뉴 (Navigation Menu)

웹사이트 내비게이션을 위한 링크와 메뉴 모음을 표시하는 고품질의 비스타일 React 내비게이션 메뉴 컴포넌트예요. 다단계 서브메뉴, 커스텀 링크, 스크롤 가능한 큰 메뉴까지 지원해요.

출처: Base UI 내비게이션 메뉴

본문

웹사이트 내비게이션을 위한 링크와 메뉴 모음을 표시하는 고품질의 비스타일 React 내비게이션 메뉴 컴포넌트예요.

데모

Tailwind

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

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

export default function ExampleNavigationMenu() {
  return (
    <NavigationMenu.Root className="min-w-max text-neutral-950 dark:text-white">
      <NavigationMenu.List className="relative flex gap-px">
        <NavigationMenu.Item>
          <NavigationMenu.Trigger className={triggerClassName}>
            Overview
            <NavigationMenu.Icon className="transition-transform duration-200 ease-[ease] data-popup-open:rotate-180">
              <CaretDownIcon />
            </NavigationMenu.Icon>
          </NavigationMenu.Trigger>

          <NavigationMenu.Content className={contentClassName}>
            <ul className="m-0 grid list-none grid-cols-2 p-0 max-[500px]:grid-cols-1">
              {overviewLinks.map((item) => (
                <li key={item.href}>
                  <Link href={item.href} className={linkCardClassName}>
                    <h3 className="m-0 mb-1 text-sm leading-4 font-normal">{item.title}</h3>
                    <p className="m-0 text-sm text-neutral-500 dark:text-neutral-400">
                      {item.description}
                    </p>
                  </Link>
                </li>
              ))}
            </ul>
          </NavigationMenu.Content>
        </NavigationMenu.Item>

        <NavigationMenu.Item>
          <NavigationMenu.Trigger className={triggerClassName}>
            Handbook
            <NavigationMenu.Icon className="transition-transform duration-200 ease-[ease] data-popup-open:rotate-180">
              <CaretDownIcon />
            </NavigationMenu.Icon>
          </NavigationMenu.Trigger>

          <NavigationMenu.Content className={contentClassName}>
            <ul className="m-0 flex max-w-[400px] list-none flex-col justify-center p-0">
              {handbookLinks.map((item) => (
                <li key={item.href}>
                  <Link href={item.href} className={linkCardClassName}>
                    <h3 className="m-0 mb-1 text-sm leading-4 font-normal">{item.title}</h3>
                    <p className="m-0 text-sm text-neutral-500 dark:text-neutral-400">
                      {item.description}
                    </p>
                  </Link>
                </li>
              ))}
            </ul>
          </NavigationMenu.Content>
        </NavigationMenu.Item>

        <NavigationMenu.Item>
          <Link className={triggerClassName} href="https://github.com/mui/base-ui">
            GitHub
          </Link>
        </NavigationMenu.Item>
      </NavigationMenu.List>

      <NavigationMenu.Portal>
        <NavigationMenu.Positioner
          sideOffset={10}
          collisionPadding={{ top: 5, bottom: 5, left: 20, right: 20 }}
          collisionAvoidance={{ side: 'none' }}
          className="h-[var(--positioner-height)] w-[var(--positioner-width)] max-w-[var(--available-width)] transition-[top,left,right,bottom] duration-[var(--duration)] ease-[var(--easing)] before:absolute before:content-[''] data-instant:transition-none data-[side=bottom]:before:top-[-10px] data-[side=bottom]:before:right-0 data-[side=bottom]:before:left-0 data-[side=bottom]:before:h-2.5 data-[side=left]:before:top-0 data-[side=left]:before:right-[-10px] data-[side=left]:before:bottom-0 data-[side=left]:before:w-2.5 data-[side=right]:before:top-0 data-[side=right]:before:bottom-0 data-[side=right]:before:left-[-10px] data-[side=right]:before:w-2.5 data-[side=top]:before:right-0 data-[side=top]:before:bottom-[-10px] data-[side=top]:before:left-0 data-[side=top]:before:h-2.5"
          style={{
            ['--duration' as string]: '0.35s',
            ['--easing' as string]: 'cubic-bezier(0.22, 1, 0.36, 1)',
          }}
        >
          <NavigationMenu.Popup className="relative h-[var(--popup-height)] w-[var(--popup-width)] origin-[var(--transform-origin)] border border-neutral-950 bg-white text-neutral-950 shadow-[0.25rem_0.25rem_0] shadow-black/12 outline-none transition-[opacity,transform,width,height,scale] duration-[var(--duration)] ease-[var(--easing)] data-ending-style:scale-90 data-ending-style:opacity-0 data-ending-style:duration-150 data-ending-style:ease-[ease] data-starting-style:scale-90 data-starting-style:opacity-0 dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none">
            <NavigationMenu.Arrow className="relative block h-1.5 w-3 overflow-clip transition-[left,right] duration-[var(--duration)] ease-[var(--easing)] before:absolute before:bottom-0 before:left-1/2 before:block before:h-[calc(6px*sqrt(2))] before:w-[calc(6px*sqrt(2))] before:-translate-x-1/2 before:translate-y-1/2 before:rotate-45 before:border before:border-neutral-950 before:bg-white before:content-[''] data-[side=bottom]:top-[-6px] data-[side=left]:right-[-9px] data-[side=left]:rotate-90 data-[side=right]:left-[-9px] data-[side=right]:-rotate-90 data-[side=top]:bottom-[-6px] data-[side=top]:rotate-180 dark:before:border-white dark:before:bg-neutral-950" />
            <NavigationMenu.Viewport className="relative h-full w-full overflow-hidden" />
          </NavigationMenu.Popup>
        </NavigationMenu.Positioner>
      </NavigationMenu.Portal>
    </NavigationMenu.Root>
  );
}

function Link(props: NavigationMenu.Link.Props) {
  return (
    <NavigationMenu.Link
      render={
        // Use the `render` prop to render your framework's Link component
        // for client-side routing.
        // e.g. `<NextLink href={props.href} />` instead of `<a />`.
        <a />
      }
      {...props}
    />
  );
}

function CaretDownIcon(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="M12 6H4l4 4.5z" />
    </svg>
  );
}

const triggerClassName =
  'flex h-8 items-center justify-center gap-1.5 bg-transparent px-2 text-sm font-normal text-neutral-950 no-underline select-none min-[501px]:px-3 hover:bg-neutral-100 data-pressed:bg-neutral-100 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white dark:text-white dark:hover:bg-neutral-800 dark:data-pressed:bg-neutral-800';

const contentClassName =
  'h-full w-[calc(100vw-40px)] p-2 min-[500px]:w-max min-[500px]:max-w-[400px] ' +
  'transition-[opacity,transform,translate] duration-[var(--duration)] ease-[var(--easing)] ' +
  'data-starting-style:opacity-0 data-ending-style:opacity-0 ' +
  'data-starting-style:data-[activation-direction=left]:translate-x-[-50%] ' +
  'data-starting-style:data-[activation-direction=right]:translate-x-[50%] ' +
  'data-ending-style:data-[activation-direction=left]:translate-x-[50%] ' +
  'data-ending-style:data-[activation-direction=right]:translate-x-[-50%]';

const linkCardClassName =
  'relative block h-full w-full border-0 bg-transparent p-2 text-left text-inherit no-underline hover:bg-neutral-100 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white dark:hover:bg-neutral-800';

const overviewLinks = [
  {
    href: '/react/overview/quick-start',
    title: 'Quick Start',
    description: 'Install and assemble your first component.',
  },
  {
    href: '/react/overview/accessibility',
    title: 'Accessibility',
    description: 'Learn how we build accessible components.',
  },
  {
    href: '/react/overview/releases',
    title: 'Releases',
    description: 'See what’s new in the latest Base UI versions.',
  },
  {
    href: '/react/overview/about',
    title: 'About',
    description: 'Learn more about Base UI and our mission.',
  },
] as const;

const handbookLinks = [
  {
    href: '/react/handbook/styling',
    title: 'Styling',
    description:
      'Base UI components can be styled with plain CSS, Tailwind CSS, CSS-in-JS, or CSS Modules.',
  },
  {
    href: '/react/handbook/animation',
    title: 'Animation',
    description:
      'Base UI components can be animated with CSS transitions, CSS animations, or JavaScript libraries.',
  },
  {
    href: '/react/handbook/composition',
    title: 'Composition',
    description:
      'Base UI components can be replaced and composed with your own existing components.',
  },
] as const;

CSS Modules

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

/* index.module.css */
.Root {
  box-sizing: border-box;
  color: oklch(14.5% 0 0deg);
  min-width: max-content;

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

.List {
  display: flex;
  position: relative;
  gap: 1px;
  list-style: none;
  padding: 0;
  margin: 0;
}

.Trigger {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  height: 2rem;
  padding: 0 0.75rem;
  margin: 0;
  outline: 0;
  border: 0;
  background-color: transparent;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1.25rem;
  color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;
  text-decoration: none;

  @media (max-width: 500px) {
    padding: 0 0.5rem;
  }

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

  @media (hover: hover) {
    &:hover {
      background-color: oklch(97% 0 0deg);

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

.Icon {
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;

  &[data-popup-open] {
    transform: rotate(180deg);
  }
}

.Positioner {
  --easing: cubic-bezier(0.22, 1, 0.36, 1);
  --duration: 0.35s;
  box-sizing: border-box;
  transition-property: top, left, right, bottom;
  transition-duration: var(--duration);
  transition-timing-function: var(--easing);
  width: var(--positioner-width);
  height: var(--positioner-height);
  max-width: var(--available-width);

  &::before {
    content: '';
    position: absolute;
  }

  &[data-side='top']::before {
    left: 0;
    right: 0;
    bottom: -10px;
    height: 10px;
  }

  &[data-side='bottom']::before {
    left: 0;
    right: 0;
    top: -10px;
    height: 10px;
  }

  &[data-side='left']::before {
    top: 0;
    bottom: 0;
    right: -10px;
    width: 10px;
  }

  &[data-side='right']::before {
    top: 0;
    bottom: 0;
    left: -10px;
    width: 10px;
  }

  &[data-instant] {
    transition: none;
  }
}

.Popup {
  position: relative;
  overflow: visible;
  box-sizing: border-box;
  outline: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  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-property: opacity, transform, width, height;
  transition-duration: var(--duration);
  transition-timing-function: var(--easing);
  width: var(--popup-width);
  height: var(--popup-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.9);
  }

  &[data-ending-style] {
    transition-timing-function: ease;
    transition-duration: 0.15s;
  }
}

.Content {
  box-sizing: border-box;
  transition:
    opacity calc(var(--duration) * 0.5) ease,
    transform var(--duration) var(--easing);
  padding: 0.5rem;
  width: calc(100vw - 40px);
  height: 100%;

  @media (min-width: 500px) {
    width: max-content;
    max-width: 400px;
  }

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

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

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

.Viewport {
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 100%;
}

.GridLinkList {
  box-sizing: border-box;
  display: grid;
  grid-template-columns: 1fr 1fr;
  list-style: none;
  padding: 0;
  margin: 0;

  @media (max-width: 500px) {
    grid-template-columns: 1fr;
  }
}

.FlexLinkList {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: 400px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.LinkCard {
  box-sizing: border-box;
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  padding: 0.5rem;
  text-decoration: none;
  color: inherit;
  text-align: left;
  border: 0;
  background-color: transparent;

  @media (hover: hover) {
    &:hover {
      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;
    }
  }
}

.LinkTitle {
  margin: 0 0 4px;
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1rem;
}

.LinkDescription {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: oklch(55.6% 0 0deg);

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

.Arrow {
  display: block;
  position: relative;
  width: 12px;
  height: 6px;
  overflow: clip;
  transition:
    left var(--duration) var(--easing),
    right var(--duration) var(--easing);

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

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

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

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

  &::before {
    content: '';
    display: block;
    position: absolute;
    bottom: 0;
    left: 50%;
    box-sizing: border-box;
    width: calc(6px * sqrt(2));
    height: calc(6px * sqrt(2));
    border: 1px solid oklch(14.5% 0 0deg);
    background-color: white;
    transform: translate(-50%, 50%) rotate(45deg);

    @media (prefers-color-scheme: dark) {
      border: 1px solid white;
      background-color: oklch(14.5% 0 0deg);
    }
  }
}
/* index.tsx */
import * as React from 'react';
import { NavigationMenu } from '@base-ui/react/navigation-menu';
import styles from './index.module.css';

export default function ExampleNavigationMenu() {
  return (
    <NavigationMenu.Root className={styles.Root}>
      <NavigationMenu.List className={styles.List}>
        <NavigationMenu.Item>
          <NavigationMenu.Trigger className={styles.Trigger}>
            Overview
            <NavigationMenu.Icon className={styles.Icon}>
              <CaretDownIcon />
            </NavigationMenu.Icon>
          </NavigationMenu.Trigger>
          <NavigationMenu.Content className={styles.Content}>
            <ul className={styles.GridLinkList}>
              {overviewLinks.map((item) => (
                <li key={item.href}>
                  <Link className={styles.LinkCard} href={item.href}>
                    <h3 className={styles.LinkTitle}>{item.title}</h3>
                    <p className={styles.LinkDescription}>{item.description}</p>
                  </Link>
                </li>
              ))}
            </ul>
          </NavigationMenu.Content>
        </NavigationMenu.Item>

        <NavigationMenu.Item>
          <NavigationMenu.Trigger className={styles.Trigger}>
            Handbook
            <NavigationMenu.Icon className={styles.Icon}>
              <CaretDownIcon />
            </NavigationMenu.Icon>
          </NavigationMenu.Trigger>
          <NavigationMenu.Content className={styles.Content}>
            <ul className={styles.FlexLinkList}>
              {handbookLinks.map((item) => (
                <li key={item.href}>
                  <Link className={styles.LinkCard} href={item.href}>
                    <h3 className={styles.LinkTitle}>{item.title}</h3>
                    <p className={styles.LinkDescription}>{item.description}</p>
                  </Link>
                </li>
              ))}
            </ul>
          </NavigationMenu.Content>
        </NavigationMenu.Item>

        <NavigationMenu.Item>
          <Link className={styles.Trigger} href="https://github.com/mui/base-ui">
            GitHub
          </Link>
        </NavigationMenu.Item>
      </NavigationMenu.List>

      <NavigationMenu.Portal>
        <NavigationMenu.Positioner
          className={styles.Positioner}
          sideOffset={10}
          collisionPadding={{ top: 5, bottom: 5, left: 20, right: 20 }}
          collisionAvoidance={{ side: 'none' }}
        >
          <NavigationMenu.Popup className={styles.Popup}>
            <NavigationMenu.Arrow className={styles.Arrow} />
            <NavigationMenu.Viewport className={styles.Viewport} />
          </NavigationMenu.Popup>
        </NavigationMenu.Positioner>
      </NavigationMenu.Portal>
    </NavigationMenu.Root>
  );
}

function Link(props: NavigationMenu.Link.Props) {
  return (
    <NavigationMenu.Link
      render={
        // Use the `render` prop to render your framework's Link component
        // for client-side routing.
        // e.g. `<NextLink href={props.href} />` instead of `<a />`.
        <a />
      }
      {...props}
    />
  );
}

function CaretDownIcon(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="M12 6H4l4 4.5z" />
    </svg>
  );
}

const overviewLinks = [
  {
    href: '/react/overview/quick-start',
    title: 'Quick Start',
    description: 'Install and assemble your first component.',
  },
  {
    href: '/react/overview/accessibility',
    title: 'Accessibility',
    description: 'Learn how we build accessible components.',
  },
  {
    href: '/react/overview/releases',
    title: 'Releases',
    description: 'See what’s new in the latest Base UI versions.',
  },
  {
    href: '/react/overview/about',
    title: 'About',
    description: 'Learn more about Base UI and our mission.',
  },
] as const;

const handbookLinks = [
  {
    href: '/react/handbook/styling',
    title: 'Styling',
    description:
      'Base UI components can be styled with plain CSS, Tailwind CSS, CSS-in-JS, or CSS Modules.',
  },
  {
    href: '/react/handbook/animation',
    title: 'Animation',
    description:
      'Base UI components can be animated with CSS transitions, CSS animations, or JavaScript libraries.',
  },
  {
    href: '/react/handbook/composition',
    title: 'Composition',
    description:
      'Base UI components can be replaced and composed with your own existing components.',
  },
] as const;

구조 (Anatomy)

컴포넌트를 임포트하고 파트를 조립해요.

import { NavigationMenu } from '@base-ui/react/navigation-menu';

<NavigationMenu.Root>
  <NavigationMenu.List>
    <NavigationMenu.Item>
      <NavigationMenu.Trigger>
        <NavigationMenu.Icon />
      </NavigationMenu.Trigger>
      <NavigationMenu.Content>
        <NavigationMenu.Link />
      </NavigationMenu.Content>
    </NavigationMenu.Item>
  </NavigationMenu.List>

  <NavigationMenu.Portal>
    <NavigationMenu.Backdrop />
    <NavigationMenu.Positioner>
      <NavigationMenu.Popup>
        <NavigationMenu.Arrow />
        <NavigationMenu.Viewport />
      </NavigationMenu.Popup>
    </NavigationMenu.Positioner>
  </NavigationMenu.Portal>
</NavigationMenu.Root>;

예시

중첩 서브메뉴

<NavigationMenu.Root> 컴포넌트는 더 높은 수준의 <NavigationMenu.Content> 파트 안에 중첩해 다단계 내비게이션 메뉴를 만들 수 있어요.

데모

Tailwind

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

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

export default function ExampleNavigationMenu() {
  return (
    <NavigationMenu.Root className="min-w-max text-neutral-950 dark:text-white">
      <NavigationMenu.List className="relative flex gap-px">
        <NavigationMenu.Item>
          <NavigationMenu.Trigger className={triggerClassName}>
            Overview
            <NavigationMenu.Icon className="transition-transform duration-200 ease-[ease] data-popup-open:rotate-180">
              <CaretDownIcon />
            </NavigationMenu.Icon>
          </NavigationMenu.Trigger>

          <NavigationMenu.Content className={contentClassName}>
            <ul className="m-0 grid list-none grid-cols-2 p-0 min-[640px]:grid-cols-[12rem_12rem]">
              {overviewLinks.map((item) => (
                <li key={item.href}>
                  <Link href={item.href} className={linkCardClassName}>
                    <h3 className="m-0 mb-1 text-sm leading-4 font-normal">{item.title}</h3>
                    <p className="m-0 text-sm text-neutral-500 dark:text-neutral-400">
                      {item.description}
                    </p>
                  </Link>
                </li>
              ))}
              <li>
                <NavigationMenu.Root orientation="vertical">
                  <NavigationMenu.List>
                    <NavigationMenu.Item>
                      <NavigationMenu.Trigger className={linkCardClassName}>
                        <span className="m-0 mb-1 text-sm leading-4 font-normal">Handbook</span>
                        <p className="m-0 text-sm text-neutral-500 dark:text-neutral-400">
                          How to use Base UI effectively.
                        </p>
                        <NavigationMenu.Icon className="absolute top-1/2 right-2.5 flex -translate-y-1/2 items-center justify-center transition-transform duration-200 ease-[ease] data-popup-open:rotate-180">
                          <CaretRightIcon />
                        </NavigationMenu.Icon>
                      </NavigationMenu.Trigger>
                      <NavigationMenu.Content className={contentClassName}>
                        <ul className="m-0 flex max-w-[400px] list-none flex-col justify-center p-0">
                          {handbookLinks.map((item) => (
                            <li key={item.href}>
                              <Link href={item.href} className={linkCardClassName}>
                                <h3 className="m-0 mb-1 text-sm leading-4 font-normal">
                                  {item.title}
                                </h3>
                                <p className="m-0 text-sm text-neutral-500 dark:text-neutral-400">
                                  {item.description}
                                </p>
                              </Link>
                            </li>
                          ))}
                        </ul>
                      </NavigationMenu.Content>
                    </NavigationMenu.Item>
                  </NavigationMenu.List>

                  <NavigationMenu.Portal>
                    <NavigationMenu.Positioner
                      sideOffset={8}
                      alignOffset={-8}
                      align="end"
                      side="right"
                      className="h-[var(--positioner-height)] w-[var(--positioner-width)] max-w-[var(--available-width)] transition-[top,left,right,bottom] duration-[var(--duration)] ease-[var(--easing)] before:absolute before:content-[''] data-instant:transition-none data-[side=bottom]:before:top-[-10px] data-[side=bottom]:before:right-0 data-[side=bottom]:before:left-0 data-[side=bottom]:before:h-2.5 data-[side=left]:before:top-0 data-[side=left]:before:right-[-10px] data-[side=left]:before:bottom-0 data-[side=left]:before:w-2.5 data-[side=right]:before:top-0 data-[side=right]:before:bottom-0 data-[side=right]:before:left-[-10px] data-[side=right]:before:w-2.5 data-[side=top]:before:right-0 data-[side=top]:before:bottom-[-10px] data-[side=top]:before:left-0 data-[side=top]:before:h-2.5"
                      style={{
                        ['--duration' as string]: '0.35s',
                        ['--easing' as string]: 'cubic-bezier(0.22, 1, 0.36, 1)',
                      }}
                    >
                      <NavigationMenu.Popup className="relative h-[var(--popup-height)] w-[var(--popup-width)] origin-[var(--transform-origin)] border border-neutral-950 bg-white text-neutral-950 shadow-[0.25rem_0.25rem_0] shadow-black/12 outline-none transition-[opacity,transform,width,height,scale] duration-[var(--duration)] ease-[var(--easing)] data-ending-style:scale-90 data-ending-style:opacity-0 data-ending-style:duration-150 data-ending-style:ease-[ease] data-starting-style:scale-90 data-starting-style:opacity-0 dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none">
                        <NavigationMenu.Viewport className="relative h-full w-full overflow-hidden" />
                      </NavigationMenu.Popup>
                    </NavigationMenu.Positioner>
                  </NavigationMenu.Portal>
                </NavigationMenu.Root>
              </li>
            </ul>
          </NavigationMenu.Content>
        </NavigationMenu.Item>
      </NavigationMenu.List>

      <NavigationMenu.Portal>
        <NavigationMenu.Positioner
          sideOffset={10}
          collisionPadding={{ top: 5, bottom: 5, left: 20, right: 20 }}
          className="h-[var(--positioner-height)] w-[var(--positioner-width)] max-w-[var(--available-width)] transition-[top,left,right,bottom] duration-[var(--duration)] ease-[var(--easing)] before:absolute before:content-[''] data-instant:transition-none data-[side=bottom]:before:top-[-10px] data-[side=bottom]:before:right-0 data-[side=bottom]:before:left-0 data-[side=bottom]:before:h-2.5 data-[side=left]:before:top-0 data-[side=left]:before:right-[-10px] data-[side=left]:before:bottom-0 data-[side=left]:before:w-2.5 data-[side=right]:before:top-0 data-[side=right]:before:bottom-0 data-[side=right]:before:left-[-10px] data-[side=right]:before:w-2.5 data-[side=top]:before:right-0 data-[side=top]:before:bottom-[-10px] data-[side=top]:before:left-0 data-[side=top]:before:h-2.5"
          style={{
            ['--duration' as string]: '0.35s',
            ['--easing' as string]: 'cubic-bezier(0.22, 1, 0.36, 1)',
          }}
        >
          <NavigationMenu.Popup className="relative h-[var(--popup-height)] w-[var(--popup-width)] origin-[var(--transform-origin)] border border-neutral-950 bg-white text-neutral-950 shadow-[0.25rem_0.25rem_0] shadow-black/12 outline-none transition-[opacity,transform,width,height,scale] duration-[var(--duration)] ease-[var(--easing)] data-ending-style:scale-90 data-ending-style:opacity-0 data-ending-style:duration-150 data-ending-style:ease-[ease] data-starting-style:scale-90 data-starting-style:opacity-0 dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none">
            <NavigationMenu.Arrow className="relative block h-1.5 w-3 overflow-clip transition-[left,right] duration-[var(--duration)] ease-[var(--easing)] before:absolute before:bottom-0 before:left-1/2 before:block before:h-[calc(6px*sqrt(2))] before:w-[calc(6px*sqrt(2))] before:-translate-x-1/2 before:translate-y-1/2 before:rotate-45 before:border before:border-neutral-950 before:bg-white before:content-[''] data-[side=bottom]:top-[-6px] data-[side=left]:right-[-9px] data-[side=left]:rotate-90 data-[side=right]:left-[-9px] data-[side=right]:-rotate-90 data-[side=top]:bottom-[-6px] data-[side=top]:rotate-180 dark:before:border-white dark:before:bg-neutral-950" />
            <NavigationMenu.Viewport className="relative h-full w-full overflow-hidden" />
          </NavigationMenu.Popup>
        </NavigationMenu.Positioner>
      </NavigationMenu.Portal>
    </NavigationMenu.Root>
  );
}

function Link(props: NavigationMenu.Link.Props) {
  return (
    <NavigationMenu.Link
      render={
        // Use the `render` prop to render your framework's Link component
        // for client-side routing.
        // e.g. `<NextLink href={props.href} />` instead of `<a />`.
        <a />
      }
      {...props}
    />
  );
}

function CaretDownIcon(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="M12 6H4l4 4.5z" />
    </svg>
  );
}

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

const triggerClassName =
  'flex h-8 items-center justify-center gap-1.5 bg-transparent px-2 text-sm font-normal text-neutral-950 no-underline select-none min-[501px]:px-3 hover:bg-neutral-100 data-pressed:bg-neutral-100 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white dark:text-white dark:hover:bg-neutral-800 dark:data-pressed:bg-neutral-800';

const contentTransitionClassName =
  'transition-[opacity,transform,translate] duration-[var(--duration)] ease-[var(--easing)] ' +
  'data-starting-style:opacity-0 data-ending-style:opacity-0 ' +
  'data-starting-style:data-[activation-direction=left]:translate-x-[-50%] ' +
  'data-starting-style:data-[activation-direction=right]:translate-x-[50%] ' +
  'data-ending-style:data-[activation-direction=left]:translate-x-[50%] ' +
  'data-ending-style:data-[activation-direction=right]:translate-x-[-50%]';

const contentClassName = `h-full w-[calc(100vw_-_40px)] p-2 min-[500px]:w-max min-[500px]:min-w-[400px] ${contentTransitionClassName}`;

const linkCardClassName =
  'relative block h-full w-full border-0 bg-transparent p-2 text-left text-inherit no-underline hover:bg-neutral-100 data-pressed:bg-neutral-100 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white dark:hover:bg-neutral-800 dark:data-pressed:bg-neutral-800';

const overviewLinks = [
  {
    href: '/react/overview/quick-start',
    title: 'Quick Start',
    description: 'Install and assemble your first component.',
  },
  {
    href: '/react/overview/accessibility',
    title: 'Accessibility',
    description: 'Learn how we build accessible components.',
  },
  {
    href: '/react/overview/releases',
    title: 'Releases',
    description: 'See what’s new in the latest Base UI versions.',
  },
] as const;

const handbookLinks = [
  {
    href: '/react/handbook/styling',
    title: 'Styling',
    description:
      'Base UI components can be styled with plain CSS, Tailwind CSS, CSS-in-JS, or CSS Modules.',
  },
  {
    href: '/react/handbook/animation',
    title: 'Animation',
    description:
      'Base UI components can be animated with CSS transitions, CSS animations, or JavaScript libraries.',
  },
  {
    href: '/react/handbook/composition',
    title: 'Composition',
    description:
      'Base UI components can be replaced and composed with your own existing components.',
  },
] as const;

CSS Modules

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

/* index.module.css */
.Root {
  box-sizing: border-box;
  color: oklch(14.5% 0 0deg);
  min-width: max-content;

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

.List {
  display: flex;
  position: relative;
  gap: 1px;
  list-style: none;
  padding: 0;
  margin: 0;
}

.Trigger {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  height: 2rem;
  padding: 0 0.75rem;
  margin: 0;
  outline: 0;
  border: 0;
  background-color: transparent;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1.25rem;
  color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;
  text-decoration: none;

  @media (max-width: 500px) {
    padding: 0 0.5rem;
  }

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

  @media (hover: hover) {
    &:hover {
      background-color: oklch(97% 0 0deg);

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

.Icon {
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;

  &[data-popup-open] {
    transform: rotate(180deg);
  }
}

.Positioner {
  --easing: cubic-bezier(0.22, 1, 0.36, 1);
  --duration: 0.35s;
  box-sizing: border-box;
  transition-property: top, left, right, bottom;
  transition-duration: var(--duration);
  transition-timing-function: var(--easing);
  width: var(--positioner-width);
  height: var(--positioner-height);
  max-width: var(--available-width);

  &::before {
    content: '';
    position: absolute;
  }

  &[data-side='top']::before {
    left: 0;
    right: 0;
    bottom: -10px;
    height: 10px;
  }

  &[data-side='bottom']::before {
    left: 0;
    right: 0;
    top: -10px;
    height: 10px;
  }

  &[data-side='left']::before {
    top: 0;
    bottom: 0;
    right: -10px;
    width: 10px;
  }

  &[data-side='right']::before {
    top: 0;
    bottom: 0;
    left: -10px;
    width: 10px;
  }

  &[data-instant] {
    transition: none;
  }
}

.Popup {
  position: relative;
  overflow: visible;
  box-sizing: border-box;
  outline: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  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-property: opacity, transform, width, height;
  transition-duration: var(--duration);
  transition-timing-function: var(--easing);
  width: var(--popup-width);
  height: var(--popup-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.9);
  }

  &[data-ending-style] {
    transition-timing-function: ease;
    transition-duration: 0.15s;
  }
}

.Content {
  box-sizing: border-box;
  transition:
    opacity calc(var(--duration) * 0.5) ease,
    transform var(--duration) var(--easing);
  padding: 0.5rem;
  width: calc(100vw - 40px);
  height: 100%;

  @media (min-width: 500px) {
    width: max-content;
    min-width: 400px;
  }

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

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

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

.Viewport {
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 100%;
}

.GridLinkList {
  box-sizing: border-box;
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 0;
  margin: 0;
  list-style: none;

  @media (min-width: 640px) {
    grid-template-columns: 12rem 12rem;
  }
}

.FlexLinkList {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: 400px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.LinkCard {
  box-sizing: border-box;
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  padding: 0.5rem;
  text-decoration: none;
  color: inherit;
  text-align: left;
  border: 0;
  background-color: transparent;

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

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

  @media (hover: hover) {
    &:hover {
      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;
    }
  }
}

.LinkTitle {
  margin: 0 0 4px;
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1rem;
}

.LinkDescription {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: oklch(55.6% 0 0deg);

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

.Arrow {
  display: block;
  position: relative;
  width: 12px;
  height: 6px;
  overflow: clip;
  transition:
    left var(--duration) var(--easing),
    right var(--duration) var(--easing);

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

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

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

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

  &::before {
    content: '';
    display: block;
    position: absolute;
    bottom: 0;
    left: 50%;
    box-sizing: border-box;
    width: calc(6px * sqrt(2));
    height: calc(6px * sqrt(2));
    border: 1px solid oklch(14.5% 0 0deg);
    background-color: white;
    transform: translate(-50%, 50%) rotate(45deg);

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

.NestedIcon {
  position: absolute;
  top: 50%;
  right: 0.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: -0.3rem;
  transition: transform 0.2s ease;

  &[data-popup-open] {
    transform: rotate(180deg);
  }
}
/* index.tsx */
import * as React from 'react';
import { NavigationMenu } from '@base-ui/react/navigation-menu';
import styles from './index.module.css';

export default function ExampleNavigationMenu() {
  return (
    <NavigationMenu.Root className={styles.Root}>
      <NavigationMenu.List className={styles.List}>
        <NavigationMenu.Item>
          <NavigationMenu.Trigger className={styles.Trigger}>
            Overview
            <NavigationMenu.Icon className={styles.Icon}>
              <CaretDownIcon />
            </NavigationMenu.Icon>
          </NavigationMenu.Trigger>
          <NavigationMenu.Content className={styles.Content}>
            <ul className={styles.GridLinkList}>
              {overviewLinks.map((item) => (
                <li key={item.href}>
                  <Link className={styles.LinkCard} href={item.href}>
                    <h3 className={styles.LinkTitle}>{item.title}</h3>
                    <p className={styles.LinkDescription}>{item.description}</p>
                  </Link>
                </li>
              ))}
              <li>
                <NavigationMenu.Root orientation="vertical">
                  <NavigationMenu.List>
                    <NavigationMenu.Item>
                      <NavigationMenu.Trigger className={styles.LinkCard}>
                        <span className={styles.LinkTitle}>Handbook</span>
                        <p className={styles.LinkDescription}>How to use Base UI effectively.</p>
                        <NavigationMenu.Icon className={styles.NestedIcon}>
                          <CaretRightIcon />
                        </NavigationMenu.Icon>
                      </NavigationMenu.Trigger>
                      <NavigationMenu.Content className={styles.Content}>
                        <ul className={styles.FlexLinkList}>
                          {handbookLinks.map((item) => (
                            <li key={item.href}>
                              <Link className={styles.LinkCard} href={item.href}>
                                <h3 className={styles.LinkTitle}>{item.title}</h3>
                                <p className={styles.LinkDescription}>{item.description}</p>
                              </Link>
                            </li>
                          ))}
                        </ul>
                      </NavigationMenu.Content>
                    </NavigationMenu.Item>
                  </NavigationMenu.List>

                  <NavigationMenu.Portal>
                    <NavigationMenu.Positioner
                      className={styles.Positioner}
                      sideOffset={8}
                      alignOffset={-8}
                      align="end"
                      side="right"
                    >
                      <NavigationMenu.Popup className={styles.Popup}>
                        <NavigationMenu.Viewport className={styles.Viewport} />
                      </NavigationMenu.Popup>
                    </NavigationMenu.Positioner>
                  </NavigationMenu.Portal>
                </NavigationMenu.Root>
              </li>
            </ul>
          </NavigationMenu.Content>
        </NavigationMenu.Item>
      </NavigationMenu.List>

      <NavigationMenu.Portal>
        <NavigationMenu.Positioner
          className={styles.Positioner}
          sideOffset={10}
          collisionPadding={{ top: 5, bottom: 5, left: 20, right: 20 }}
        >
          <NavigationMenu.Popup className={styles.Popup}>
            <NavigationMenu.Arrow className={styles.Arrow} />
            <NavigationMenu.Viewport className={styles.Viewport} />
          </NavigationMenu.Popup>
        </NavigationMenu.Positioner>
      </NavigationMenu.Portal>
    </NavigationMenu.Root>
  );
}

function Link(props: NavigationMenu.Link.Props) {
  return (
    <NavigationMenu.Link
      render={
        // Use the `render` prop to render your framework's Link component
        // for client-side routing.
        // e.g. `<NextLink href={props.href} />` instead of `<a />`.
        <a />
      }
      {...props}
    />
  );
}

function CaretDownIcon(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="M12 6H4l4 4.5z" />
    </svg>
  );
}

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

const overviewLinks = [
  {
    href: '/react/overview/quick-start',
    title: 'Quick Start',
    description: 'Install and assemble your first component.',
  },
  {
    href: '/react/overview/accessibility',
    title: 'Accessibility',
    description: 'Learn how we build accessible components.',
  },
  {
    href: '/react/overview/releases',
    title: 'Releases',
    description: 'See what’s new in the latest Base UI versions.',
  },
] as const;

const handbookLinks = [
  {
    href: '/react/handbook/styling',
    title: 'Styling',
    description:
      'Base UI components can be styled with plain CSS, Tailwind CSS, CSS-in-JS, or CSS Modules.',
  },
  {
    href: '/react/handbook/animation',
    title: 'Animation',
    description:
      'Base UI components can be animated with CSS transitions, CSS animations, or JavaScript libraries.',
  },
  {
    href: '/react/handbook/composition',
    title: 'Composition',
    description:
      'Base UI components can be replaced and composed with your own existing components.',
  },
] as const;

중첩 인라인 서브메뉴

같은 패널에 유지되어야 하는 2단계 내비게이션은 중첩된 <NavigationMenu.Portal>을 생략하고 defaultValue와 함께 List + Viewport만 렌더링해요.

데모

Tailwind

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

/* index.tsx */
'use client';
import * as React from 'react';
import { NavigationMenu } from '@base-ui/react/navigation-menu';
import { useMediaQuery } from '@base-ui/react/unstable-use-media-query';
import { audienceMenus, guideLinks, guidesPanel } from './data';

export default function ExampleNavigationMenu() {
  const isDesktop = useMediaQuery('(min-width: 700px)', { defaultMatches: true });

  return (
    <NavigationMenu.Root className="min-w-max text-neutral-950 dark:text-white">
      <NavigationMenu.List className="relative flex gap-px">
        <NavigationMenu.Item>
          <NavigationMenu.Trigger className={triggerClassName}>
            Product
            <NavigationMenu.Icon className="transition-transform duration-200 ease-[ease] data-popup-open:rotate-180">
              <CaretDownIcon />
            </NavigationMenu.Icon>
          </NavigationMenu.Trigger>

          <NavigationMenu.Content className={productContentClassName}>
            <NavigationMenu.Root
              className="overflow-hidden overflow-clip text-neutral-950 dark:text-white"
              orientation={isDesktop ? 'vertical' : 'horizontal'}
              defaultValue="developers"
            >
              <div className="grid grid-cols-1 overflow-hidden overflow-clip min-[700px]:grid-cols-[13rem_minmax(0,1fr)]">
                <NavigationMenu.List className="m-0 flex list-none flex-row gap-1 overflow-x-auto p-2 min-[700px]:h-[var(--popup-height)] min-[700px]:flex-col min-[700px]:gap-px min-[700px]:overflow-x-visible min-[700px]:overflow-y-clip min-[700px]:border-r min-[700px]:border-r-neutral-950 min-[700px]:transition-[height] min-[700px]:duration-[var(--duration)] min-[700px]:ease-[var(--easing)] dark:min-[700px]:border-r-white">
                  {audienceMenus.map((menu) => (
                    <NavigationMenu.Item key={menu.value} value={menu.value}>
                      <NavigationMenu.Trigger className={submenuTriggerClassName}>
                        <span className="text-sm leading-4 font-normal text-neutral-950 dark:text-white">
                          {menu.label}
                        </span>
                        <span className="text-sm text-neutral-500 dark:text-neutral-400">
                          {menu.hint}
                        </span>
                      </NavigationMenu.Trigger>
                      <NavigationMenu.Content className={submenuContentClassName}>
                        <div>
                          <h4 className="m-0 text-base leading-5 font-normal">{menu.title}</h4>
                          <p className="m-0 mt-1 text-sm text-neutral-500 dark:text-neutral-400">
                            {menu.description}
                          </p>
                        </div>
                        <ul className="-mx-2 m-0 flex list-none flex-col gap-0 p-0">
                          {menu.links.map((link) => (
                            <li key={link.href}>
                              <Link className={linkCardClassName} href={link.href}>
                                <h5 className="m-0 text-sm leading-4 font-normal">{link.title}</h5>
                                <p className="m-0 text-sm text-neutral-500 dark:text-neutral-400">
                                  {link.description}
                                </p>
                              </Link>
                            </li>
                          ))}
                        </ul>
                      </NavigationMenu.Content>
                    </NavigationMenu.Item>
                  ))}
                </NavigationMenu.List>
                <NavigationMenu.Viewport className="relative min-h-[16.5rem] overflow-hidden border-t border-neutral-950 min-[700px]:border-t-0 dark:border-white" />
              </div>
            </NavigationMenu.Root>
          </NavigationMenu.Content>
        </NavigationMenu.Item>

        <NavigationMenu.Item>
          <NavigationMenu.Trigger className={triggerClassName}>
            Learn
            <NavigationMenu.Icon className="transition-transform duration-200 ease-[ease] data-popup-open:rotate-180">
              <CaretDownIcon />
            </NavigationMenu.Icon>
          </NavigationMenu.Trigger>

          <NavigationMenu.Content className={guidesContentClassName}>
            <div className="flex flex-col gap-4 p-4 text-neutral-950 dark:text-white">
              <div>
                <h4 className="m-0 text-base leading-5 font-normal">{guidesPanel.title}</h4>
                <p className="m-0 mt-1 text-sm text-neutral-500 dark:text-neutral-400">
                  {guidesPanel.description}
                </p>
              </div>
              <ul className="-mx-2 m-0 flex list-none flex-col gap-0 p-0">
                {guideLinks.map((link) => (
                  <li key={link.href}>
                    <Link className={linkCardClassName} href={link.href}>
                      <h5 className="m-0 text-sm leading-4 font-normal">{link.title}</h5>
                      <p className="m-0 text-sm text-neutral-500 dark:text-neutral-400">
                        {link.description}
                      </p>
                    </Link>
                  </li>
                ))}
              </ul>
            </div>
          </NavigationMenu.Content>
        </NavigationMenu.Item>

        <NavigationMenu.Item>
          <Link className={triggerClassName} href="/react/overview/releases">
            Releases
          </Link>
        </NavigationMenu.Item>

        <NavigationMenu.Item>
          <Link className={triggerClassName} href="https://github.com/mui/base-ui">
            GitHub
          </Link>
        </NavigationMenu.Item>
      </NavigationMenu.List>

      <NavigationMenu.Portal>
        <NavigationMenu.Positioner
          sideOffset={10}
          collisionPadding={{ top: 5, bottom: 5, left: 20, right: 20 }}
          collisionAvoidance={{ side: 'none' }}
          className="h-[var(--positioner-height)] w-[var(--positioner-width)] max-w-[var(--available-width)] transition-[top,left,right,bottom] duration-[var(--duration)] ease-[var(--easing)] before:absolute before:content-[''] data-instant:transition-none data-[side=bottom]:before:top-[-10px] data-[side=bottom]:before:right-0 data-[side=bottom]:before:left-0 data-[side=bottom]:before:h-2.5 data-[side=left]:before:top-0 data-[side=left]:before:right-[-10px] data-[side=left]:before:bottom-0 data-[side=left]:before:w-2.5 data-[side=right]:before:top-0 data-[side=right]:before:bottom-0 data-[side=right]:before:left-[-10px] data-[side=right]:before:w-2.5 data-[side=top]:before:right-0 data-[side=top]:before:bottom-[-10px] data-[side=top]:before:left-0 data-[side=top]:before:h-2.5"
          style={{
            ['--duration' as string]: '0.35s',
            ['--easing' as string]: 'cubic-bezier(0.22, 1, 0.36, 1)',
          }}
        >
          <NavigationMenu.Popup className="relative h-[var(--popup-height)] w-[var(--popup-width)] origin-[var(--transform-origin)] border border-neutral-950 bg-white text-neutral-950 shadow-[0.25rem_0.25rem_0] shadow-black/12 outline-none transition-[opacity,transform,width,height,scale] duration-[var(--duration)] ease-[var(--easing)] data-ending-style:scale-90 data-ending-style:opacity-0 data-ending-style:duration-150 data-ending-style:ease-[ease] data-ending-style:transition-[opacity,scale] data-starting-style:scale-90 data-starting-style:opacity-0 dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none">
            <NavigationMenu.Arrow className="relative block h-1.5 w-3 overflow-clip transition-[left,right] duration-[var(--duration)] ease-[var(--easing)] before:absolute before:bottom-0 before:left-1/2 before:block before:h-[calc(6px*sqrt(2))] before:w-[calc(6px*sqrt(2))] before:-translate-x-1/2 before:translate-y-1/2 before:rotate-45 before:border before:border-neutral-950 before:bg-white before:content-[''] data-[side=bottom]:top-[-6px] data-[side=left]:right-[-9px] data-[side=left]:rotate-90 data-[side=right]:left-[-9px] data-[side=right]:-rotate-90 data-[side=top]:bottom-[-6px] data-[side=top]:rotate-180 dark:before:border-white dark:before:bg-neutral-950" />
            <NavigationMenu.Viewport className="relative h-full w-full overflow-hidden" />
          </NavigationMenu.Popup>
        </NavigationMenu.Positioner>
      </NavigationMenu.Portal>
    </NavigationMenu.Root>
  );
}

function Link(props: NavigationMenu.Link.Props) {
  return (
    <NavigationMenu.Link
      render={
        // Use the `render` prop to render your framework's Link component
        // for client-side routing.
        // e.g. `<NextLink href={props.href} />` instead of `<a />`.
        <a />
      }
      {...props}
    />
  );
}

function CaretDownIcon(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="M12 6H4l4 4.5z" />
    </svg>
  );
}

const triggerClassName =
  'flex h-8 items-center justify-center gap-1.5 bg-transparent px-2 text-sm font-normal text-neutral-950 no-underline select-none min-[501px]:px-3 hover:bg-neutral-100 data-pressed:bg-neutral-100 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white dark:text-white dark:hover:bg-neutral-800 dark:data-pressed:bg-neutral-800';

const sharedContentClassName =
  'h-full w-[calc(100vw_-_40px)] ' +
  'transition-[opacity,translate] duration-[calc(var(--duration)*0.5),var(--duration)] ease-[ease,cubic-bezier(0.4,0,0.2,1)] ' +
  'data-starting-style:data-[activation-direction=left]:opacity-0 data-starting-style:data-[activation-direction=right]:opacity-0 data-ending-style:opacity-0 ' +
  'data-ending-style:duration-[calc(var(--duration)*0.5)] data-ending-style:ease-[ease] ' +
  'data-starting-style:data-[activation-direction=left]:translate-x-[-2rem] ' +
  'data-starting-style:data-[activation-direction=right]:translate-x-[2rem] ' +
  'data-ending-style:data-[activation-direction=left]:translate-x-[2rem] ' +
  'data-ending-style:data-[activation-direction=right]:translate-x-[-2rem]';

const productContentClassName = `${sharedContentClassName} p-0 min-[700px]:[width:min(675px,calc(100vw-40px))]`;

const guidesContentClassName = `${sharedContentClassName} p-0 min-[700px]:[width:min(500px,calc(100vw-40px))]`;

const submenuTriggerClassName =
  'm-0 flex w-full min-w-[10rem] flex-col items-start gap-1 border-0 bg-transparent p-2 text-left text-inherit hover:bg-neutral-100 data-pressed:bg-neutral-100 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white dark:hover:bg-neutral-800 dark:data-pressed:bg-neutral-800';

const submenuContentClassName =
  'flex h-full translate-x-0 flex-col gap-4 p-4 min-[700px]:blur-0 transition-[opacity,translate,filter] duration-[var(--duration)] ease-[var(--easing)] min-[700px]:duration-[calc(var(--duration)*1.35)] min-[700px]:ease-[cubic-bezier(0.16,1,0.3,1)] ' +
  'data-starting-style:data-[activation-direction=left]:opacity-0 data-starting-style:data-[activation-direction=right]:opacity-0 data-starting-style:data-[activation-direction=left]:translate-x-[-50%] data-starting-style:data-[activation-direction=right]:translate-x-[50%] ' +
  'data-ending-style:opacity-0 data-ending-style:data-[activation-direction=left]:translate-x-[50%] data-ending-style:data-[activation-direction=right]:translate-x-[-50%] ' +
  'min-[700px]:data-starting-style:data-[activation-direction=up]:opacity-0 min-[700px]:data-starting-style:data-[activation-direction=down]:opacity-0 min-[700px]:data-starting-style:data-[activation-direction=up]:translate-y-[-72px] min-[700px]:data-starting-style:data-[activation-direction=down]:translate-y-[72px] min-[700px]:data-starting-style:blur-[2px] ' +
  'min-[700px]:data-ending-style:data-[activation-direction=up]:translate-y-[72px] min-[700px]:data-ending-style:data-[activation-direction=down]:translate-y-[-72px] min-[700px]:data-ending-style:blur-[2px]';

const linkCardClassName =
  'relative block h-full w-full border-0 bg-transparent p-2 text-left text-inherit no-underline hover:bg-neutral-100 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white dark:hover:bg-neutral-800';
/* data.ts */
export const audienceMenus = [
  {
    value: 'developers',
    label: 'Developers',
    hint: 'Go from idea to UI faster.',
    title: 'Build product UI without giving up control',
    description:
      'Start with accessible parts and shape them to your app instead of working around a preset design system.',
    links: [
      {
        href: '/react/overview/quick-start',
        title: 'Quick start',
        description: 'Install Base UI and get your first interactive primitive on screen fast.',
      },
      {
        href: '/react/handbook/composition',
        title: 'Composition',
        description: 'Wrap and combine parts to match your product structure without hacks.',
      },
    ],
  },
  {
    value: 'systems',
    label: 'Design Systems',
    hint: 'Keep patterns aligned across teams.',
    title: 'Turn shared standards into working components',
    description:
      'Connect tokens, states, and accessibility rules once, then give every product team the same solid starting point.',
    links: [
      {
        href: '/react/handbook/styling',
        title: 'Styling',
        description: 'Map tokens and component states to your own CSS or utility setup.',
      },
      {
        href: '/react/overview/accessibility',
        title: 'Accessibility',
        description: 'Review keyboard support and semantic defaults before anything ships.',
      },
      {
        href: '/react/components/tooltip',
        title: 'Tooltip',
        description: 'Set one clear pattern for lightweight help, hints, and field guidance.',
      },
      {
        href: '/react/components/popover',
        title: 'Popover',
        description: 'Handle richer anchored panels like menus, inspectors, and onboarding.',
      },
    ],
  },
  {
    value: 'managers',
    label: 'Engineering Leads',
    hint: 'Roll out shared UI without drag.',
    title: 'Give squads clear defaults and room to move',
    description:
      'Use the docs to align on quality bars, upgrades, and extension points while still leaving teams space to customize.',
    links: [
      {
        href: '/react/overview/releases',
        title: 'Releases',
        description: 'Track version changes and migration notes before upgrades surprise teams.',
      },
      {
        href: '/react/handbook/typescript',
        title: 'TypeScript',
        description: 'See how the primitives type custom wrappers and shared abstractions.',
      },
      {
        href: '/react/handbook/forms',
        title: 'Forms',
        description: 'Standardize validation and field patterns teams reach for constantly.',
      },
    ],
  },
  {
    value: 'startups',
    label: 'Startups',
    hint: 'Ship polished basics while things change.',
    title: 'Get sturdy UI foundations in place early',
    description:
      'Cover the hard interaction details now so your team can spend more time on the product ideas that actually differentiate you.',
    links: [
      {
        href: '/react/overview/quick-start',
        title: 'Quick start',
        description: 'Get the package installed and your first component working in minutes.',
      },
      {
        href: '/react/components/menu',
        title: 'Menu',
        description: 'Add action menus with keyboard support and focus handling already done.',
      },
      {
        href: '/react/components/dialog',
        title: 'Dialog',
        description: 'Launch settings or upgrade flows without rebuilding focus management.',
      },
    ],
  },
] as const;

export const guidesPanel = {
  title: 'Where teams usually start',
  description:
    'These are the docs people reach for first when they are turning a prototype into shared UI.',
} as const;

export const guideLinks = [
  {
    href: '/react/overview/accessibility',
    title: 'Accessibility handbook',
    description: 'Take a practical pass over focus order, semantics, and keyboard support.',
  },
  {
    href: '/react/handbook/composition',
    title: 'Composition handbook',
    description: 'Learn when to wrap parts, share behavior, and expose flexible APIs.',
  },
  {
    href: '/react/handbook/styling',
    title: 'Styling handbook',
    description: 'Apply tokens and state styles without fighting the underlying markup.',
  },
] as const;

CSS Modules

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

/* index.module.css */
.Root {
  box-sizing: border-box;
  color: oklch(14.5% 0 0deg);
  min-width: max-content;

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

.List {
  display: flex;
  position: relative;
  gap: 1px;
  list-style: none;
  padding: 0;
  margin: 0;
}

.Trigger {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  height: 2rem;
  padding: 0 0.75rem;
  margin: 0;
  outline: 0;
  border: 0;
  background-color: transparent;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1.25rem;
  color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;
  text-decoration: none;

  @media (max-width: 500px) {
    padding: 0 0.5rem;
  }

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

  @media (hover: hover) {
    &:hover {
      background-color: oklch(97% 0 0deg);

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

.Icon {
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;

  &[data-popup-open] {
    transform: rotate(180deg);
  }
}

.Positioner {
  --easing: cubic-bezier(0.22, 1, 0.36, 1);
  --duration: 0.35s;
  box-sizing: border-box;
  transition-property: top, left, right, bottom;
  transition-duration: var(--duration);
  transition-timing-function: var(--easing);
  width: var(--positioner-width);
  height: var(--positioner-height);
  max-width: var(--available-width);

  &::before {
    content: '';
    position: absolute;
  }

  &[data-side='top']::before {
    left: 0;
    right: 0;
    bottom: -10px;
    height: 10px;
  }

  &[data-side='bottom']::before {
    left: 0;
    right: 0;
    top: -10px;
    height: 10px;
  }

  &[data-side='left']::before {
    top: 0;
    bottom: 0;
    right: -10px;
    width: 10px;
  }

  &[data-side='right']::before {
    top: 0;
    bottom: 0;
    left: -10px;
    width: 10px;
  }

  &[data-instant] {
    transition: none;
  }
}

.Popup {
  position: relative;
  overflow: visible;
  box-sizing: border-box;
  outline: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  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-property: opacity, transform, width, height;
  transition-duration: var(--duration);
  transition-timing-function: var(--easing);
  width: var(--popup-width);
  height: var(--popup-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.9);
  }

  &[data-ending-style] {
    transition-property: opacity, transform;
    transition-timing-function: ease;
    transition-duration: 0.15s;
  }
}

.Content {
  box-sizing: border-box;
  transition:
    opacity calc(var(--duration) * 0.5) ease,
    transform var(--duration) cubic-bezier(0.4, 0, 0.2, 1);
  padding: 0.5rem;
  width: calc(100vw - 40px);
  height: 100%;

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

  &[data-starting-style] {
    &[data-activation-direction='left'] {
      transform: translateX(-2rem);
    }
    &[data-activation-direction='right'] {
      transform: translateX(2rem);
    }
  }

  &[data-ending-style] {
    transition-duration: calc(var(--duration) * 0.5);
    transition-timing-function: ease;

    &[data-activation-direction='left'] {
      transform: translateX(2rem);
    }
    &[data-activation-direction='right'] {
      transform: translateX(-2rem);
    }
  }
}

.ProductContent {
  padding: 0;

  @media (min-width: 700px) {
    width: min(675px, calc(100vw - 40px));
  }
}

.GuidesContent {
  padding: 0;

  @media (min-width: 700px) {
    width: min(500px, calc(100vw - 40px));
  }
}

.Viewport {
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 100%;
}

.SubmenuRoot {
  color: oklch(14.5% 0 0deg);
  overflow: hidden;
  overflow: clip;

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

.SubmenuLayout {
  display: grid;
  grid-template-columns: 1fr;
  overflow: hidden;
  overflow: clip;
}

@media (min-width: 700px) {
  .SubmenuLayout {
    grid-template-columns: 13rem minmax(0, 1fr);
  }
}

.SubmenuList {
  box-sizing: border-box;
  list-style: none;
  margin: 0;
  padding: 0.5rem;
  display: flex;
  flex-direction: row;
  gap: 0.25rem;
  overflow-x: auto;
}

@media (min-width: 700px) {
  .SubmenuList {
    flex-direction: column;
    gap: 1px;
    overflow-x: visible;
    overflow-y: clip;
    border-right: 1px solid oklch(14.5% 0 0deg);
    height: var(--popup-height);
    transition: height var(--duration) var(--easing);

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

.SubmenuTrigger {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
  width: 100%;
  min-width: 10rem;
  margin: 0;
  padding: 0.5rem;
  border: 0;
  background-color: transparent;
  color: inherit;
  font-family: inherit;
  text-align: left;

  @media (hover: hover) {
    &:hover {
      background-color: oklch(97% 0 0deg);

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

.SubmenuLabel {
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1rem;
  color: oklch(14.5% 0 0deg);

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

.SubmenuHint {
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: oklch(55.6% 0 0deg);

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

.SubmenuViewport {
  position: relative;
  overflow: hidden;
  min-height: 16.5rem;
  border-top: 1px solid oklch(14.5% 0 0deg);

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

@media (min-width: 700px) {
  .SubmenuViewport {
    border-top: 0;
  }
}

.SubmenuContent {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  height: 100%;
  padding: 1rem;
  transform: translateX(0);
  transition:
    opacity var(--duration) var(--easing),
    transform var(--duration) var(--easing),
    filter var(--duration) var(--easing);

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

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

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

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

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

  @media (min-width: 700px) {
    transform: translateY(0);
    filter: blur(0);
    transition-duration: calc(var(--duration) * 1.35);
    transition-timing-function: cubic-bezier(0.16, 1, 0.3, 1);

    &[data-starting-style] {
      &[data-activation-direction='up'] {
        transform: translateY(-72px);
      }

      &[data-activation-direction='down'] {
        transform: translateY(72px);
      }
    }

    &[data-ending-style] {
      &[data-activation-direction='up'] {
        transform: translateY(72px);
      }

      &[data-activation-direction='down'] {
        transform: translateY(-72px);
      }
    }

    &[data-starting-style],
    &[data-ending-style] {
      filter: blur(2px);
    }
  }
}

.SubmenuTitle {
  margin: 0;
  font-size: 1rem;
  line-height: 1.25rem;
  font-weight: 400;
}

.SubmenuDescription {
  margin: 0.25rem 0 0;
  color: oklch(55.6% 0 0deg);
  font-size: 0.875rem;
  line-height: 1.25rem;

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

.LinkList {
  list-style: none;
  margin: 0 -0.5rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.LinkCard {
  box-sizing: border-box;
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  padding: 0.5rem;
  text-decoration: none;
  color: inherit;
  text-align: left;
  border: 0;
  background-color: transparent;

  @media (hover: hover) {
    &:hover {
      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;
    }
  }
}

.LinkTitle {
  margin: 0 0 4px;
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1rem;
}

.LinkDescription {
  margin: 0;
  color: oklch(55.6% 0 0deg);
  font-size: 0.875rem;
  line-height: 1.25rem;

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

.GuidesPanel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
}

.Arrow {
  display: block;
  position: relative;
  width: 12px;
  height: 6px;
  overflow: clip;
  transition:
    left var(--duration) var(--easing),
    right var(--duration) var(--easing);

  @media (max-width: 699px) {
    display: none;
  }

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

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

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

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

  &::before {
    content: '';
    display: block;
    position: absolute;
    bottom: 0;
    left: 50%;
    box-sizing: border-box;
    width: calc(6px * sqrt(2));
    height: calc(6px * sqrt(2));
    border: 1px solid oklch(14.5% 0 0deg);
    background-color: white;
    transform: translate(-50%, 50%) rotate(45deg);

    @media (prefers-color-scheme: dark) {
      border: 1px solid white;
      background-color: oklch(14.5% 0 0deg);
    }
  }
}
/* index.tsx */
'use client';
import * as React from 'react';
import { NavigationMenu } from '@base-ui/react/navigation-menu';
import { useMediaQuery } from '@base-ui/react/unstable-use-media-query';
import { audienceMenus, guideLinks, guidesPanel } from './data';
import styles from './index.module.css';

export default function ExampleNavigationMenu() {
  const isDesktop = useMediaQuery('(min-width: 700px)', { defaultMatches: true });

  return (
    <NavigationMenu.Root className={styles.Root}>
      <NavigationMenu.List className={styles.List}>
        <NavigationMenu.Item>
          <NavigationMenu.Trigger className={styles.Trigger}>
            Product
            <NavigationMenu.Icon className={styles.Icon}>
              <CaretDownIcon />
            </NavigationMenu.Icon>
          </NavigationMenu.Trigger>
          <NavigationMenu.Content className={`${styles.Content} ${styles.ProductContent}`}>
            <NavigationMenu.Root
              className={styles.SubmenuRoot}
              orientation={isDesktop ? 'vertical' : 'horizontal'}
              defaultValue="developers"
            >
              <div className={styles.SubmenuLayout}>
                <NavigationMenu.List className={styles.SubmenuList}>
                  {audienceMenus.map((menu) => (
                    <NavigationMenu.Item key={menu.value} value={menu.value}>
                      <NavigationMenu.Trigger className={styles.SubmenuTrigger}>
                        <span className={styles.SubmenuLabel}>{menu.label}</span>
                        <span className={styles.SubmenuHint}>{menu.hint}</span>
                      </NavigationMenu.Trigger>
                      <NavigationMenu.Content className={styles.SubmenuContent}>
                        <div>
                          <h4 className={styles.SubmenuTitle}>{menu.title}</h4>
                          <p className={styles.SubmenuDescription}>{menu.description}</p>
                        </div>
                        <ul className={styles.LinkList}>
                          {menu.links.map((link) => (
                            <li key={link.href}>
                              <Link className={styles.LinkCard} href={link.href}>
                                <h5 className={styles.LinkTitle}>{link.title}</h5>
                                <p className={styles.LinkDescription}>{link.description}</p>
                              </Link>
                            </li>
                          ))}
                        </ul>
                      </NavigationMenu.Content>
                    </NavigationMenu.Item>
                  ))}
                </NavigationMenu.List>

                <NavigationMenu.Viewport className={styles.SubmenuViewport} />
              </div>
            </NavigationMenu.Root>
          </NavigationMenu.Content>
        </NavigationMenu.Item>

        <NavigationMenu.Item>
          <NavigationMenu.Trigger className={styles.Trigger}>
            Learn
            <NavigationMenu.Icon className={styles.Icon}>
              <CaretDownIcon />
            </NavigationMenu.Icon>
          </NavigationMenu.Trigger>
          <NavigationMenu.Content className={`${styles.Content} ${styles.GuidesContent}`}>
            <div className={styles.GuidesPanel}>
              <div>
                <h4 className={styles.SubmenuTitle}>{guidesPanel.title}</h4>
                <p className={styles.SubmenuDescription}>{guidesPanel.description}</p>
              </div>
              <ul className={styles.LinkList}>
                {guideLinks.map((link) => (
                  <li key={link.href}>
                    <Link className={styles.LinkCard} href={link.href}>
                      <h5 className={styles.LinkTitle}>{link.title}</h5>
                      <p className={styles.LinkDescription}>{link.description}</p>
                    </Link>
                  </li>
                ))}
              </ul>
            </div>
          </NavigationMenu.Content>
        </NavigationMenu.Item>

        <NavigationMenu.Item>
          <Link className={styles.Trigger} href="/react/overview/releases">
            Releases
          </Link>
        </NavigationMenu.Item>

        <NavigationMenu.Item>
          <Link className={styles.Trigger} href="https://github.com/mui/base-ui">
            GitHub
          </Link>
        </NavigationMenu.Item>
      </NavigationMenu.List>

      <NavigationMenu.Portal>
        <NavigationMenu.Positioner
          className={styles.Positioner}
          sideOffset={10}
          collisionPadding={{ top: 5, bottom: 5, left: 20, right: 20 }}
          collisionAvoidance={{ side: 'none' }}
        >
          <NavigationMenu.Popup className={styles.Popup}>
            <NavigationMenu.Arrow className={styles.Arrow} />
            <NavigationMenu.Viewport className={styles.Viewport} />
          </NavigationMenu.Popup>
        </NavigationMenu.Positioner>
      </NavigationMenu.Portal>
    </NavigationMenu.Root>
  );
}

function Link(props: NavigationMenu.Link.Props) {
  return (
    <NavigationMenu.Link
      render={
        // Use the `render` prop to render your framework's Link component
        // for client-side routing.
        // e.g. `<NextLink href={props.href} />` instead of `<a />`.
        <a />
      }
      {...props}
    />
  );
}

function CaretDownIcon(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="M12 6H4l4 4.5z" />
    </svg>
  );
}
/* data.ts */
export const audienceMenus = [
  {
    value: 'developers',
    label: 'Developers',
    hint: 'Go from idea to UI faster.',
    title: 'Build product UI without giving up control',
    description:
      'Start with accessible parts and shape them to your app instead of working around a preset design system.',
    links: [
      {
        href: '/react/overview/quick-start',
        title: 'Quick start',
        description: 'Install Base UI and get your first interactive primitive on screen fast.',
      },
      {
        href: '/react/handbook/composition',
        title: 'Composition',
        description: 'Wrap and combine parts to match your product structure without hacks.',
      },
    ],
  },
  {
    value: 'systems',
    label: 'Design Systems',
    hint: 'Keep patterns aligned across teams.',
    title: 'Turn shared standards into working components',
    description:
      'Connect tokens, states, and accessibility rules once, then give every product team the same solid starting point.',
    links: [
      {
        href: '/react/handbook/styling',
        title: 'Styling',
        description: 'Map tokens and component states to your own CSS or utility setup.',
      },
      {
        href: '/react/overview/accessibility',
        title: 'Accessibility',
        description: 'Review keyboard support and semantic defaults before anything ships.',
      },
      {
        href: '/react/components/tooltip',
        title: 'Tooltip',
        description: 'Set one clear pattern for lightweight help, hints, and field guidance.',
      },
      {
        href: '/react/components/popover',
        title: 'Popover',
        description: 'Handle richer anchored panels like menus, inspectors, and onboarding.',
      },
    ],
  },
  {
    value: 'managers',
    label: 'Engineering Leads',
    hint: 'Roll out shared UI without drag.',
    title: 'Give squads clear defaults and room to move',
    description:
      'Use the docs to align on quality bars, upgrades, and extension points while still leaving teams space to customize.',
    links: [
      {
        href: '/react/overview/releases',
        title: 'Releases',
        description: 'Track version changes and migration notes before upgrades surprise teams.',
      },
      {
        href: '/react/handbook/typescript',
        title: 'TypeScript',
        description: 'See how the primitives type custom wrappers and shared abstractions.',
      },
      {
        href: '/react/handbook/forms',
        title: 'Forms',
        description: 'Standardize validation and field patterns teams reach for constantly.',
      },
    ],
  },
  {
    value: 'startups',
    label: 'Startups',
    hint: 'Ship polished basics while things change.',
    title: 'Get sturdy UI foundations in place early',
    description:
      'Cover the hard interaction details now so your team can spend more time on the product ideas that actually differentiate you.',
    links: [
      {
        href: '/react/overview/quick-start',
        title: 'Quick start',
        description: 'Get the package installed and your first component working in minutes.',
      },
      {
        href: '/react/components/menu',
        title: 'Menu',
        description: 'Add action menus with keyboard support and focus handling already done.',
      },
      {
        href: '/react/components/dialog',
        title: 'Dialog',
        description: 'Launch settings or upgrade flows without rebuilding focus management.',
      },
    ],
  },
] as const;

export const guidesPanel = {
  title: 'Where teams usually start',
  description:
    'These are the docs people reach for first when they are turning a prototype into shared UI.',
} as const;

export const guideLinks = [
  {
    href: '/react/overview/accessibility',
    title: 'Accessibility handbook',
    description: 'Take a practical pass over focus order, semantics, and keyboard support.',
  },
  {
    href: '/react/handbook/composition',
    title: 'Composition handbook',
    description: 'Learn when to wrap parts, share behavior, and expose flexible APIs.',
  },
  {
    href: '/react/handbook/styling',
    title: 'Styling handbook',
    description: 'Apply tokens and state styles without fighting the underlying markup.',
  },
] as const;

커스텀 링크

<NavigationMenu.Link> 파트는 render prop을 사용해 프레임워크의 링크를 렌더링하도록 커스터마이즈해 클라이언트 사이드 라우팅을 활성화할 수 있어요.

// @highlight
import NextLink from 'next/link';
import { NavigationMenu } from '@base-ui/react/navigation-menu';

function Link(props: NavigationMenu.Link.Props) {
  return (
    <NavigationMenu.Link
      // @highlight
      render={<NextLink href={props.href} />}
      {...props}
    />
  );
}

큰 메뉴

어떤 경우에는 뷰포트에 맞지 않는 큰 메뉴 콘텐츠가 있을 때 보통 두 가지 선택지가 있어요:

  1. 내비게이션 메뉴 콘텐츠 압축하기

레이아웃을 변경해 내비게이션 메뉴가 차지하는 공간을 줄여 적은 콘텐츠를 렌더링하거나 더 컴팩트하게 만들 수 있어요. 콘텐츠가 유연하다면 .Popup의 max-height 속성을 사용해 내비게이션 메뉴의 높이를 제한해서 넘침을 막고 스스로 압축하게 할 수 있어요.

.Content,
.Popup {
  max-height: var(--available-height);
}
  1. 내비게이션 메뉴를 스크롤 가능하게 만들기
.Content,
.Popup {
  max-height: var(--available-height);
}

.Content {
  overflow-y: auto;
}

콘텐츠를 전환하는 동안 네이티브 스크롤바가 보이기 때문에, 네이티브 스크롤바 대신 Scroll Area 컴포넌트를 사용해 스크롤바를 숨기는 것을 권장해요. 그러면 Arrow도 올바르게 중앙 정렬할 수 있어요.

API 레퍼런스

Root

내비게이션 메뉴의 모든 파트를 묶어요. 루트에서는 <nav> 요소를, 중첩되면 <div> 요소를 렌더링해요.

Root Props:

Prop Type Default Description
defaultValue Value | null null 처음에 선택되어야 하는 항목의 비제어 값. 제어 내비게이션 메뉴를 렌더링하려면 value prop을 사용하세요.
value Value | null null 현재 열려 있어야 하는 내비게이션 메뉴 항목의 제어 값. null이 아니면 메뉴가 열려요. null이면 메뉴가 닫혀요. 비제어 내비게이션 메뉴를 렌더링하려면 defaultValue prop을 사용하세요.
onValueChange ((value: Value | null, eventDetails: NavigationMenu.Root.ChangeEventDetails) => void) - 값이 변경될 때 호출되는 콜백.
actionsRef React.RefObject<NavigationMenu.Root.Actions | null> - 명령형 동작에 대한 ref.
onOpenChangeComplete ((open: boolean) => void) - 내비게이션 메뉴가 닫힐 때 애니메이션이 끝난 뒤 호출되는 이벤트 핸들러.
delay number 50 내비게이션 팝업을 열기 전에 기다릴 시간(밀리초).
closeDelay number 50 내비게이션 팝업을 닫기 전에 기다릴 시간(밀리초).
orientation 'horizontal' | 'vertical' 'horizontal' 내비게이션 메뉴의 방향.
className string | ((state: NavigationMenu.Root.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: NavigationMenu.Root.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: NavigationMenu.Root.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Root.Props

Root props의 재내보내기예요.

Root.State

type NavigationMenuRootState = {
  /** If `true`, the popup is open. */
  open: boolean;
  /** Whether the navigation menu is nested. */
  nested: boolean;
};

Root.Actions

type NavigationMenuRootActions = { unmount: () => void };

Root.ChangeEventReason

type NavigationMenuRootChangeEventReason =
  | 'trigger-press'
  | 'trigger-hover'
  | 'outside-press'
  | 'list-navigation'
  | 'focus-out'
  | 'escape-key'
  | 'link-press'
  | 'none';

Root.ChangeEventDetails

type NavigationMenuRootChangeEventDetails = (
  | { reason: 'trigger-press'; event: MouseEvent | PointerEvent | TouchEvent | KeyboardEvent }
  | { reason: 'trigger-hover'; event: MouseEvent }
  | { reason: 'outside-press'; event: MouseEvent | PointerEvent | TouchEvent }
  | { reason: 'list-navigation'; event: KeyboardEvent }
  | { reason: 'focus-out'; event: KeyboardEvent | FocusEvent }
  | { reason: 'escape-key'; event: KeyboardEvent }
  | { reason: 'link-press'; event: MouseEvent | PointerEvent }
  | { 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;
};

Root.Value

type NavigationMenuRootValue<TValue = any> = TValue | null;

Trigger

호버되거나 클릭되면 내비게이션 메뉴 팝업을 열어 관련 콘텐츠를 드러내요. <button> 요소를 렌더링해요.

Trigger Props:

Prop Type Default Description
nativeButton boolean true render prop으로 요소를 대체할 때 네이티브 <button> 요소를 렌더링할지 여부. 렌더링되는 요소가 <div>처럼 버튼이 아니면 false로 설정하세요.
disabled boolean false 컴포넌트가 사용자 상호작용을 무시할지 여부.
className string | ((state: NavigationMenu.Trigger.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: NavigationMenu.Trigger.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: NavigationMenu.Trigger.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Trigger Data Attributes:

Attribute Type Description
data-popup-open - 해당 내비게이션 메뉴가 열려 있을 때 존재해요.
data-pressed - 트리거가 눌렸을 때 존재해요.
data-disabled - 트리거가 비활성화되었을 때 존재해요.

Trigger.Props

Trigger props의 재내보내기예요.

Trigger.State

type NavigationMenuTriggerState = {
  /** If `true`, the popup is open and the item is active. */
  open: boolean;
  /** Whether the component should ignore user interaction. */
  disabled: boolean;
};

Icon

트리거 버튼이 메뉴를 연다는 것을 나타내는 아이콘이에요.

Icon Props:

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

Icon Data Attributes:

Attribute Type Description
data-popup-open - 내비게이션 메뉴가 열려 있고 항목이 활성화되어 있을 때 존재해요.

Icon.Props

Icon props의 재내보내기예요.

Icon.State

type NavigationMenuIconState = {
  /** Whether the navigation menu is open and the item is active. */
  open: boolean;
};

List

내비게이션 메뉴 항목들의 목록을 담아요. <ul> 요소를 렌더링해요.

List Props:

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

List.Props

List props의 재내보내기예요.

List.State

type NavigationMenuListState = {
  /** If `true`, the popup is 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: NavigationMenu.Portal.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: NavigationMenu.Portal.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
keepMounted boolean false 팝업이 숨겨져 있는 동안 포털을 DOM에 유지할지 여부.
render ReactElement | ((props: HTMLProps, state: NavigationMenu.Portal.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Portal.Props

Portal props의 재내보내기예요.

Portal.State

type NavigationMenuPortalState = {};

Backdrop

내비게이션 메뉴 팝업을 위한 백드롭이에요. <div> 요소를 렌더링해요.

Backdrop Props:

Prop Type Default Description
className string | ((state: NavigationMenu.Backdrop.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: NavigationMenu.Backdrop.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: NavigationMenu.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 NavigationMenuBackdropState = {
  /** If `true`, the popup is open. */
  open: boolean;
  /** The transition status of the popup. */
  transitionStatus: TransitionStatus;
};

Positioner

현재 활성화된 트리거에 대해 내비게이션 메뉴를 배치해요. <div> 요소를 렌더링해요.

Positioner Props:

Prop Type Default Description
disableAnchorTracking boolean false 팝업이 위치 기준 앵커의 레이아웃 이동을 추적하지 않게 할지 여부.
align Align 'center' 지정된 side를 기준으로 팝업을 어떻게 정렬할지.
alignOffset number | OffsetFunction 0 정렬 축을 따라 추가로 적용할 오프셋(픽셀)이에요. 앵커와 positioner 요소의 크기, 그리고 side·alignment를 읽기 위해 오프셋을 반환하는 함수도 허용해요. 함수는 data 객체 파라미터를 받는데, 속성은 다음과 같아요. data.anchor: width와 height 속성을 가진 앵커 요소의 크기.data.positioner: width와 height 속성을 가진 positioner 요소의 크기.data.side: positioner가 정렬되는 앵커 요소의 side.data.align: positioner가 지정된 side에 대해 정렬되는 방식.
side Side 'bottom' 팝업을 정렬할 앵커 요소의 side. 충돌을 피하기 위해 자동으로 변경될 수 있어요.
sideOffset number | OffsetFunction 0 앵커와 팝업 사이의 거리(픽셀)예요. 앵커와 positioner 요소의 크기, 그리고 side·alignment를 읽기 위해 거리를 반환하는 함수도 허용해요. 함수는 data 객체 파라미터를 받는데, 속성은 다음과 같아요. data.anchor: width와 height 속성을 가진 앵커 요소의 크기.data.positioner: width와 height 속성을 가진 positioner 요소의 크기.data.side: positioner가 정렬되는 앵커 요소의 side.data.align: positioner가 지정된 side에 대해 정렬되는 방식.
arrowPadding number 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 앵커 요소가 뷰포트 밖으로 스크롤된 후에도 팝업을 뷰포트에 유지할지 여부.
positionMethod 'absolute' | 'fixed' 'absolute' 사용할 CSS position 속성을 결정해요.
className string | ((state: NavigationMenu.Positioner.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: NavigationMenu.Positioner.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: NavigationMenu.Positioner.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

alignOffset Prop Example:

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

sideOffset Prop Example:

<Positioner
  sideOffset={({ side, align, anchor, positioner }) => {
    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-instant - 애니메이션이 즉시 이루어져야 할 때 존재해요.
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 요소의 고정 높이.
--positioner-width number positioner 요소의 고정 너비.
--transform-origin string 이 요소가 기준으로 삼는 좌표예요. 애니메이션과 전환에 사용돼요.

Positioner.Props

Positioner props의 재내보내기예요.

Positioner.State

type NavigationMenuPositionerState = {
  /** Whether the navigation 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 CSS transitions should be disabled. */
  instant: boolean;
};

내비게이션 메뉴 콘텐츠의 컨테이너예요. <nav> 요소를 렌더링해요.

Popup Props:

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

Popup 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에 배치되는지 나타내요.
data-starting-style - 팝업이 애니메이션으로 나타나기 시작할 때 존재해요.
data-ending-style - 팝업이 애니메이션으로 사라질 때 존재해요.

Popup CSS Variables:

Variable Type Description
--popup-height number 팝업 요소의 고정 높이.
--popup-width number 팝업 요소의 고정 너비.

Popup.Props

Popup props의 재내보내기예요.

Popup.State

type NavigationMenuPopupState = {
  /** If `true`, the popup is open. */
  open: boolean;
  /** The transition status of the popup. */
  transitionStatus: TransitionStatus;
  /** The side of the anchor the popup is positioned on. */
  side: Side;
  /** The alignment of the popup relative to the anchor. */
  align: Align;
  /** Whether the anchor element is hidden. */
  anchorHidden: boolean;
};

Arrow

내비게이션 메뉴의 현재 앵커를 가리키는 요소를 표시해요. <div> 요소를 렌더링해요.

Arrow Props:

Prop Type Default Description
className string | ((state: NavigationMenu.Arrow.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: NavigationMenu.Arrow.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: NavigationMenu.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 NavigationMenuArrowState = {
  /** Whether the popup 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

개별 내비게이션 메뉴 항목이에요. <li> 요소를 렌더링해요.

Item Props:

Prop Type Default Description
value any - 이 내비게이션 메뉴 항목을 식별하는 고유 값. 값이 제공되지 않으면 고유 ID가 자동으로 생성돼요. 내비게이션 메뉴를 프로그래밍 방식으로 제어할 때 사용하세요.
className string | ((state: NavigationMenu.Item.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: NavigationMenu.Item.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: NavigationMenu.Item.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Item.Props

Item props의 재내보내기예요.

Item.State

type NavigationMenuItemState = {};

Content

항목이 활성화되면 팝업으로 이동되는 내비게이션 메뉴 항목 콘텐츠의 컨테이너예요. <div> 요소를 렌더링해요.

Content Props:

Prop Type Default Description
className string | ((state: NavigationMenu.Content.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: NavigationMenu.Content.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
keepMounted boolean false 팝업이 닫혀 있는 동안 콘텐츠를 DOM에 유지할지 여부. 웹 크롤러를 위한 서버 사이드 렌더링 동안 콘텐츠가 존재하도록 보장해요.
render ReactElement | ((props: HTMLProps, state: NavigationMenu.Content.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Content Data Attributes:

Attribute Type Description
data-open - 팝업이 열려 있을 때 존재해요.
data-closed - 팝업이 닫혀 있을 때 존재해요.
data-activation-direction 'left' | 'right' | 'up' | 'down' 다른 트리거가 어느 방향에서 활성화되었는지.
data-starting-style - 콘텐츠가 애니메이션으로 나타나기 시작할 때 존재해요.
data-ending-style - 콘텐츠가 애니메이션으로 사라질 때 존재해요.

Content.Props

Content props의 재내보내기예요.

Content.State

type NavigationMenuContentState = {
  /** If `true`, the component is open. */
  open: boolean;
  /** The transition status of the component. */
  transitionStatus: TransitionStatus;
  /** The direction of the activation. */
  activationDirection: 'left' | 'right' | 'up' | 'down' | null;
};

Viewport

내비게이션 메뉴의 현재 콘텐츠를 클리핑하는 뷰포트예요. <div> 요소를 렌더링해요.

Viewport Props:

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

Viewport.Props

Viewport props의 재내보내기예요.

Viewport.State

type NavigationMenuViewportState = {};

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

Link Props:

Prop Type Default Description
closeOnClick boolean false 링크를 클릭했을 때 내비게이션 메뉴를 닫을지 여부.
active boolean false 링크가 현재 활성 페이지인지 여부.
className string | ((state: NavigationMenu.Link.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: NavigationMenu.Link.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>, state: NavigationMenu.Link.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Link Data Attributes:

Attribute Type Description
data-active - 링크가 현재 활성 페이지일 때 존재해요.

Link.Props

Link props의 재내보내기예요.

Link.State

type NavigationMenuLinkState = {
  /** Whether the link is the currently active page. */
  active: boolean;
};

External Types

Side

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

Align

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

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;

내보내기 그룹 (Export Groups)

  • NavigationMenu.Root: NavigationMenu.Root, NavigationMenu.Root.State, NavigationMenu.Root.Props, NavigationMenu.Root.Value, NavigationMenu.Root.Actions, NavigationMenu.Root.ChangeEventReason, NavigationMenu.Root.ChangeEventDetails
  • NavigationMenu.List: NavigationMenu.List, NavigationMenu.List.State, NavigationMenu.List.Props
  • NavigationMenu.Item: NavigationMenu.Item, NavigationMenu.Item.State, NavigationMenu.Item.Props
  • NavigationMenu.Content: NavigationMenu.Content, NavigationMenu.Content.State, NavigationMenu.Content.Props
  • NavigationMenu.Trigger: NavigationMenu.Trigger, NavigationMenu.Trigger.State, NavigationMenu.Trigger.Props
  • NavigationMenu.Portal: NavigationMenu.Portal, NavigationMenu.Portal.State, NavigationMenu.Portal.Props
  • NavigationMenu.Positioner: NavigationMenu.Positioner, NavigationMenu.Positioner.State, NavigationMenu.Positioner.Props
  • NavigationMenu.Viewport: NavigationMenu.Viewport, NavigationMenu.Viewport.State, NavigationMenu.Viewport.Props
  • NavigationMenu.Backdrop: NavigationMenu.Backdrop, NavigationMenu.Backdrop.State, NavigationMenu.Backdrop.Props
  • NavigationMenu.Popup: NavigationMenu.Popup, NavigationMenu.Popup.State, NavigationMenu.Popup.Props
  • NavigationMenu.Arrow: NavigationMenu.Arrow, NavigationMenu.Arrow.State, NavigationMenu.Arrow.Props
  • NavigationMenu.Link: NavigationMenu.Link, NavigationMenu.Link.State, NavigationMenu.Link.Props
  • NavigationMenu.Icon: NavigationMenu.Icon, NavigationMenu.Icon.State, NavigationMenu.Icon.Props
  • Default: NavigationMenuRootState, NavigationMenuRootProps, NavigationMenuRootActions, NavigationMenuRootChangeEventReason, NavigationMenuRootChangeEventDetails, NavigationMenuTriggerState, NavigationMenuTriggerProps, NavigationMenuPortalState, NavigationMenuPortalProps, NavigationMenuPositionerState, NavigationMenuPositionerProps, NavigationMenuViewportState, NavigationMenuViewportProps, NavigationMenuListState, NavigationMenuListProps, NavigationMenuItemState, NavigationMenuItemProps, NavigationMenuContentState, NavigationMenuContentProps, NavigationMenuPopupState, NavigationMenuPopupProps, NavigationMenuBackdropState, NavigationMenuBackdropProps, NavigationMenuArrowState, NavigationMenuArrowProps, NavigationMenuLinkState, NavigationMenuLinkProps, NavigationMenuIconState, NavigationMenuIconProps

Canonical Types

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

  • NavigationMenu.Root.State: NavigationMenuRootState
  • NavigationMenu.Root.Props: NavigationMenuRootProps
  • NavigationMenu.Root.Actions: NavigationMenuRootActions
  • NavigationMenu.Root.ChangeEventReason: NavigationMenuRootChangeEventReason
  • NavigationMenu.Root.ChangeEventDetails: NavigationMenuRootChangeEventDetails
  • NavigationMenu.List.State: NavigationMenuListState
  • NavigationMenu.List.Props: NavigationMenuListProps
  • NavigationMenu.Item.State: NavigationMenuItemState
  • NavigationMenu.Item.Props: NavigationMenuItemProps
  • NavigationMenu.Content.State: NavigationMenuContentState
  • NavigationMenu.Content.Props: NavigationMenuContentProps
  • NavigationMenu.Trigger.State: NavigationMenuTriggerState
  • NavigationMenu.Trigger.Props: NavigationMenuTriggerProps
  • NavigationMenu.Portal.State: NavigationMenuPortalState
  • NavigationMenu.Portal.Props: NavigationMenuPortalProps
  • NavigationMenu.Positioner.State: NavigationMenuPositionerState
  • NavigationMenu.Positioner.Props: NavigationMenuPositionerProps
  • NavigationMenu.Viewport.State: NavigationMenuViewportState
  • NavigationMenu.Viewport.Props: NavigationMenuViewportProps
  • NavigationMenu.Backdrop.State: NavigationMenuBackdropState
  • NavigationMenu.Backdrop.Props: NavigationMenuBackdropProps
  • NavigationMenu.Popup.State: NavigationMenuPopupState
  • NavigationMenu.Popup.Props: NavigationMenuPopupProps
  • NavigationMenu.Arrow.State: NavigationMenuArrowState
  • NavigationMenu.Arrow.Props: NavigationMenuArrowProps
  • NavigationMenu.Link.State: NavigationMenuLinkState
  • NavigationMenu.Link.Props: NavigationMenuLinkProps
  • NavigationMenu.Icon.State: NavigationMenuIconState
  • NavigationMenu.Icon.Props: NavigationMenuIconProps

더 알아보기 (Learn more)