Navigation Menu (네비게이션 메뉴)
웹사이트를 탐색하기 위한 링크 모음 컴포넌트예요. 메뉴 트리거와 뷰포트(viewport)를 분리해, 열린 메뉴의 콘텐츠를 뷰포트 영역에 표시하는 구조예요. 서브메뉴, 라디오·체크박스 항목, 그룹, 분리선까지 풍부한 메뉴 구조와 애니메이션을 지원해요.
출처: 문서
본문
Import (불러오기)
import { NavigationMenu } from "@kobalte/core/navigation-menu";
// or
import { Root, Menu, ... } from "@kobalte/core/navigation-menu";
Features (기능)
- WAI-ARIA Menu and Menubar 디자인 패턴을 따릅니다.
- 모달(modal) 및 비모달(non-modal) 모드를 지원해요.
- 서브메뉴를 지원해요.
- 항목, 라벨, 항목 그룹을 지원해요.
- 선택적 비결정(indeterminate) 상태를 갖는 체크 가능한 항목(단일 또는 다중)을 지원해요.
- 비활성화된 항목을 지원해요.
- 복잡한 항목 라벨링을 통한 접근성을 지원해요.
- 키보드 열기 및 내비게이션을 지원해요.
- 키보드 내비게이션 중 자동 스크롤을 지원해요.
- 텍스트 입력으로 항목에 포커스할 수 있는 타입어헤드(typeahead)를 지원해요.
- 선택적으로 화살표(arrow)를 렌더링할 수 있어요.
- 포커스가 완전히 관리돼요.
Anatomy (구조)
네비게이션 메뉴는 다음의 부분들로 이루어져요:
- NavigationMenu: NavigationMenu의 루트 컨테이너예요.
- NavigationMenu.Viewport: 열린 메뉴가 렌더링하는 메뉴를 담는 컨테이너예요.
- NavigationMenu.Arrow: 뷰포트 옆에 렌더링되는 선택적 화살표 요소예요.
메뉴는 다음의 부분들로 이루어져요:
- NavigationMenu.Menu: 각 메뉴의 컨테이너예요.
- NavigationMenu.Trigger: 메뉴를 토글하는 버튼이에요.
- NavigationMenu.Icon: 메뉴 트리거 안에 표시되는 작은 아이콘이에요. 메뉴가 열릴 수 있다는 사실을 시각적으로 암시하는 역할을 해요.
- NavigationMenu.Portal: 메뉴가 열려 있을 때 children을
NavigationMenu.Viewport로 포털(portal)해요. - NavigationMenu.Content: 메뉴가 열려 있을 때 렌더링할 콘텐츠를 담아요.
- NavigationMenu.Separator: 메뉴에서 항목들을 시각적으로 분리하는 데 사용돼요.
- NavigationMenu.Group: 여러 항목을 그룹화하는 데 사용돼요. 자동 라벨링을 통한 접근성을 보장하려면
NavigationMenu.GroupLabel과 함께 사용하세요. - NavigationMenu.GroupLabel: 그룹의 라벨을 렌더링하는 데 사용돼요. 화살표 키로 포커스할 수 없어요.
- NavigationMenu.Sub: 서브메뉴의 모든 부분을 담아요.
- NavigationMenu.SubTrigger: 서브메뉴를 여는 항목이에요.
NavigationMenu.Sub안에 렌더링해야 해요. - NavigationMenu.SubContent: 서브메뉴가 열려 있을 때 튀어나오는 컴포넌트예요.
NavigationMenu.Sub안에 렌더링해야 해요.
메뉴 항목은 다음의 부분들로 이루어져요:
- NavigationMenu.Item: 선택 항목이에요.
- NavigationMenu.ItemLabel: 항목에 대해 알려줄 접근 가능한 라벨이에요.
- NavigationMenu.ItemDescription: 항목에 대해 알려줄 선택적 접근 가능한 설명이에요.
- NavigationMenu.ItemIndicator: 항목이 체크되었을 때 렌더링되는 시각적 표시예요.
체크 가능한 메뉴 항목은 다음의 부분들로 이루어져요:
- NavigationMenu.RadioGroup: 여러
NavigationMenu.RadioItem을 그룹화하고 선택을 관리하는 데 사용돼요. - NavigationMenu.RadioItem: 라디오처럼 제어되고 렌더링될 수 있는 항목이에요.
- NavigationMenu.CheckboxItem: 체크박스처럼 제어되고 렌더링될 수 있는 항목이에요.
<NavigationMenu>
<NavigationMenu.Menu>
<NavigationMenu.Trigger>
<NavigationMenu.Icon />
</NavigationMenu.Trigger>
<NavigationMenu.Portal>
<NavigationMenu.Content>
<NavigationMenu.Item>
<NavigationMenu.ItemLabel />
<NavigationMenu.ItemDescription />
</NavigationMenu.Item>
<NavigationMenu.Group>
<NavigationMenu.GroupLabel />
<NavigationMenu.Item />
</NavigationMenu.Group>
<NavigationMenu.CheckboxItem>
<NavigationMenu.ItemIndicator />
</NavigationMenu.CheckboxItem>
<NavigationMenu.RadioGroup>
<NavigationMenu.RadioItem>
<NavigationMenu.ItemIndicator />
</NavigationMenu.RadioItem>
</NavigationMenu.RadioGroup>
<NavigationMenu.Sub>
<NavigationMenu.SubTrigger />
<NavigationMenu.Portal>
<NavigationMenu.SubContent />
</NavigationMenu.Portal>
</NavigationMenu.Sub>
<NavigationMenu.Separator />
</NavigationMenu.Content>
</NavigationMenu.Portal>
</NavigationMenu.Menu>
<NavigationMenu.Viewport>
<NavigationMenu.Arrow />
</NavigationMenu.Viewport>
</NavigationMenu>
Example (예제)
기본 예제를 통해 네비게이션 메뉴의 구조와 스타일링 방식을 확인해 보세요. 인터랙티브한 미리보기는 출처 문서에서 직접 확인할 수 있어요.
Usage (사용법)
Viewport size (뷰포트 크기)
뷰포트 콘텐츠는 애니메이션을 위해 absolute 위치를 갖기 때문에, Kobalte는 CSS 커스텀 변수 --kb-navigation-menu-viewport-height와 --kb-navigation-menu-viewport-width를 내보내요. 높이와 너비는 활성화된 NavigationMenu.Content에서 복사되며, CSS로 설정하거나 콘텐츠에 따라 자동으로 계산될 수 있어요. transition CSS 규칙과 함께 결합하면 크기를 애니메이션할 수 있어요.
/* style.css */
.navigation-menu__viewport {
width: var(--kb-navigation-menu-viewport-width);
height: var(--kb-navigation-menu-viewport-height);
transition:
width,
height,
250ms ease;
}
Link trigger (링크 트리거)
네비게이션 메뉴 트리거 중 하나를 메뉴를 여는 대신 링크로 만들려면 NavigationMenu.Menu를 생략하고 NavigationMenu.Trigger에 as="a"를 설정하세요.
<NavigationMenu>
<NavigationMenu.Menu>
<NavigationMenu.Trigger>Opens a regular menu</NavigationMenu.Trigger>
<NavigationMenu.Portal>
<NavigationMenu.Content>...</NavigationMenu.Content>
</NavigationMenu.Portal>
</NavigationMenu.Menu>
<NavigationMenu.Trigger as="a" href="https://kobalte.dev">
Opens a link on click and enter
</NavigationMenu.Trigger>
<NavigationMenu.Viewport>
<NavigationMenu.Arrow />
</NavigationMenu.Viewport>
</NavigationMenu>
Origin-aware animations (원점 기준 애니메이션)
계산된 원점(origin)에서 뷰포트를 애니메이션 처리할 수 있도록, CSS 커스텀 프로퍼티 --kb-menu-content-transform-origin을 제공해요.
/* style.css */
.navigation-menu__viewport {
transform-origin: var(--kb-menu-content-transform-origin);
animation: viewportHide 250ms ease-in forwards;
}
.navigation-menu__viewport[data-expanded] {
animation: viewportShow 250ms ease-out;
}
@keyframes viewportShow {
from {
opacity: 0;
transform: rotateX(-20deg) scale(0.96);
}
to {
opacity: 1;
transform: rotateX(0deg) scale(1);
}
}
@keyframes viewportHide {
from {
opacity: 1;
transform: rotateX(0deg) scale(1);
}
to {
opacity: 0;
transform: rotateX(-10deg) scale(0.96);
}
}
Content animations (콘텐츠 애니메이션)
뷰포트의 콘텐츠를 애니메이션 처리하기 위해 NavigationMenu.Content에 "to-start" | "to-end" | "from-start" | "from-end" 타입의 data-motion 속성을 적용해요.
/* style.css */
.navigation-menu__content[data-motion="from-start"] {
animation-name: enterFromLeft;
}
.navigation-menu__content[data-motion="from-end"] {
animation-name: enterFromRight;
}
.navigation-menu__content[data-motion="to-start"] {
animation-name: exitToLeft;
}
.navigation-menu__content[data-motion="to-end"] {
animation-name: exitToRight;
}
@keyframes enterFromRight {
from {
opacity: 0;
transform: translateX(200px);
}
to {
opacity: 1;
transform: translateX(0);
}
}
@keyframes enterFromLeft {
from {
opacity: 0;
transform: translateX(-200px);
}
to {
opacity: 1;
transform: translateX(0);
}
}
@keyframes exitToRight {
from {
opacity: 1;
transform: translateX(0);
}
to {
opacity: 0;
transform: translateX(200px);
}
}
@keyframes exitToLeft {
from {
opacity: 1;
transform: translateX(0);
}
to {
opacity: 0;
transform: translateX(-200px);
}
}
다음은 애니메이션 예제의 완전한 코드예요. 인터랙티브한 미리보기는 출처 문서에서 확인할 수 있어요.
import { NavigationMenu } from "@kobalte/core/navigation-menu";
import "./style.css";
export function App() {
return (
<NavigationMenu class="navigation-menu__root" orientation={orientation()}>
<NavigationMenu.Menu>
<NavigationMenu.Trigger class="navigation-menu__trigger">
Learn{" "}
<NavigationMenu.Icon class="navigation-menu__trigger-indicator">
<ChevronDownIcon />
</NavigationMenu.Icon>
</NavigationMenu.Trigger>
<NavigationMenu.Portal>
<NavigationMenu.Content class="navigation-menu__content">
Learn Content
</NavigationMenu.Content>
</NavigationMenu.Portal>
</NavigationMenu.Menu>
<NavigationMenu.Menu>
<NavigationMenu.Trigger class="navigation-menu__trigger">
Overview{" "}
<NavigationMenu.Icon class="navigation-menu__trigger-indicator">
<ChevronDownIcon />
</NavigationMenu.Icon>
</NavigationMenu.Trigger>
<NavigationMenu.Portal>
<NavigationMenu.Content class="navigation-menu__content">
Overview Content
</NavigationMenu.Content>
</NavigationMenu.Portal>
</NavigationMenu.Menu>
<NavigationMenu.Trigger
class="navigation-menu__trigger"
as="a"
href="https://github.com/kobaltedev/kobalte"
target="_blank"
>
GitHub
</NavigationMenu.Trigger>
<NavigationMenu.Viewport class="navigation-menu__viewport">
<NavigationMenu.Arrow class="navigation-menu__arrow" />
</NavigationMenu.Viewport>
</NavigationMenu>
);
}
/* This snippet only includes the minimum to get the behavior working */
.navigation-menu__viewport {
display: flex;
justify-content: center;
align-items: center;
width: var(--kb-navigation-menu__viewport-width);
height: var(--kb-navigation-menu__viewport-height);
z-index: 1000;
opacity: 0;
overflow-x: clip;
overflow-y: visible;
transform-origin: var(--kb-menu-content-transform-origin);
transition:
width,
height,
250ms ease;
animation: viewportHide 250ms ease-in forwards;
pointer-events: none;
}
.navigation-menu__viewport[data-expanded] {
animation: viewportShow 250ms ease-out;
opacity: 1;
pointer-events: auto;
}
.navigation-menu__content {
position: absolute;
top: 0;
left: 0;
box-sizing: border-box;
animation-duration: 250ms;
animation-timing-function: ease;
animation-fill-mode: forwards;
pointer-events: none;
}
.navigation-menu__content[data-expanded] {
pointer-events: auto;
}
.navigation-menu__content[data-motion="from-start"] {
animation-name: enterFromLeft;
}
.navigation-menu__content[data-motion="from-end"] {
animation-name: enterFromRight;
}
.navigation-menu__content[data-motion="to-start"] {
animation-name: exitToLeft;
}
.navigation-menu__content[data-motion="to-end"] {
animation-name: exitToRight;
}
.navigation-menu__arrow {
transition: transform 250ms;
}
@keyframes viewportShow {
from {
opacity: 0;
transform: rotateX(-20deg) scale(0.96);
}
to {
opacity: 1;
transform: rotateX(0deg) scale(1);
}
}
@keyframes viewportHide {
from {
opacity: 1;
transform: rotateX(0deg) scale(1);
}
to {
opacity: 0;
transform: rotateX(-10deg) scale(0.96);
}
}
@keyframes enterFromRight {
from {
opacity: 0;
transform: translateX(200px);
}
to {
opacity: 1;
transform: translateX(0);
}
}
@keyframes enterFromLeft {
from {
opacity: 0;
transform: translateX(-200px);
}
to {
opacity: 1;
transform: translateX(0);
}
}
@keyframes exitToRight {
from {
opacity: 1;
transform: translateX(0);
}
to {
opacity: 0;
transform: translateX(200px);
}
}
@keyframes exitToLeft {
from {
opacity: 1;
transform: translateX(0);
}
to {
opacity: 0;
transform: translateX(-200px);
}
}
API Reference (API 참조)
NavigationMenu
NavigationMenu는 @kobalte/core/NavigationMenu의 Root 임포트와 동일해요.
| Prop | Description |
|---|---|
| defaultValue | string The value of the menu that should be open when initially rendered. Use when you do not need to control the value state. |
| value | string The controlled value of the menu to open. Should be used in conjunction with onValueChange. |
| onValueChange | (value: string | undefined | null) => void Event handler called when the value changes. |
| loop | boolean When true, keyboard navigation will loop from last item to first, and vice versa. |
| delayDuration | number Delay before the menu opens on hover (default 200). |
| skipDelayDuration | boolean Open immediately if hovered again within delay (default 300). |
| loop | boolean When true, keyboard navigation will loop from last item to first, and vice versa. |
| focusOnAlt | boolean When true, click on alt by itself will focus this NavigationMenu (some browsers interfere). |
| forceMount | boolean Used to force mounting the menu (portal and content) when more control is needed. Useful when controlling animation with SolidJS animation libraries. |
NavigationMenu.Viewport
| Prop | Description |
|---|---|
| onEscapeKeyDown | (event: KeyboardEvent) => void Event handler called when the escape key is down. It can be prevented by calling event.preventDefault. |
| onPointerDownOutside | (event: PointerDownOutsideEvent) => void Event handler called when a pointer event occurs outside the bounds of the component. It can be prevented by calling event.preventDefault. |
| onFocusOutside | (event: FocusOutsideEvent) => void Event handler called when the focus moves outside the bounds of the component. It can be prevented by calling event.preventDefault. |
| onInteractOutside | (event: InteractOutsideEvent) => void Event handler called when an interaction (pointer or focus event) happens outside the bounds of the component. It can be prevented by calling event.preventDefault. |
NavigationMenu.Arrow
| Prop | Description |
|---|---|
| size | number The size of the arrow. |
NavigationMenu.Menu
| Prop | Description |
|---|---|
| onOpenChange | (open: boolean) => void Event handler called when the open state of the menu changes. |
| id | string A unique identifier for the component. The id is used to generate id attributes for nested components. If no id prop is provided, a generated id will be used. |
| modal | boolean Whether the menu should be the only visible content for screen readers, when set to true: - interaction with outside elements will be disabled. - scroll will be locked. - focus will be locked inside the menu content. - elements outside the menu content will not be visible for screen readers. |
| preventScroll | boolean Whether the scroll should be locked even if the menu is not modal. |
| forceMount | boolean Used to force mounting the menu (portal and content) when more control is needed. Useful when controlling animation with SolidJS animation libraries. |
| value | string A unique value that associates the item with an active value when the navigation menu is controlled. This prop is managed automatically when uncontrolled. |
NavigationMenu.Menu는 NavigationMenu.Content의 배치(placement)를 커스텀하기 위해 다음의 prop들을 추가로 받아요.
| Prop | Description |
|---|---|
| placement | Placement The placement of the menu content. |
| gutter | number The distance between the menu content and the trigger element. By default, it's 0 plus half of the arrow offset, if it exists. |
| shift | number The skidding of the menu content along the trigger element. |
| flip | boolean | string Controls the behavior of the menu content when it overflows the viewport: - If a boolean, specifies whether the menu content should flip to the opposite side when it overflows.- If a string, indicates the preferred fallback placements when it overflows.The placements must be spaced-delimited, e.g. "top left". |
| slide | boolean Whether the menu content should slide when it overflows. |
| overlap | boolean Whether the menu content can overlap the trigger element when it overflows. |
| sameWidth | boolean Whether the menu content should have the same width as the trigger element. This will be exposed to CSS as --kb-popper-anchor-width. |
| fitViewport | boolean Whether the menu content should fit the viewport. If this is set to true, the menu content will have maxWidth and maxHeight set to the viewport size. This will be exposed to CSS as --kb-popper-available-width and --kb-popper-available-height. |
| hideWhenDetached | boolean Whether to hide the menu content when the trigger element becomes occluded. |
| detachedPadding | number The minimum padding in order to consider the trigger element occluded. |
| arrowPadding | number The minimum padding between the arrow and the menu content corner. |
| overflowPadding | number The minimum padding between the menu content and the viewport edge. This will be exposed to CSS as --kb-popper-overflow-padding. |
NavigationMenu.Trigger
| Prop | Description |
|---|---|
| disabled | boolean Whether the context menu trigger is disabled or not. |
| Data attribute | Description |
|---|---|
| data-expanded | Present when the menu is open. |
| data-closed | Present when the menu is close. |
| data-disabled | Present when the trigger is disabled. |
NavigationMenu.Icon, NavigationMenu.Content, NavigationMenu.SubTrigger과 NavigationMenu.SubContent는 동일한 data-expanded 속성을 공유해요.
NavigationMenu.Content
| Prop | Description |
|---|---|
| onOpenAutoFocus | (event: Event) => void Event handler called when focus moves into the component after opening. It can be prevented by calling event.preventDefault. |
| onCloseAutoFocus | (event: Event) => void Event handler called when focus moves to the trigger after closing. It can be prevented by calling event.preventDefault. |
| onEscapeKeyDown | (event: KeyboardEvent) => void Event handler called when the escape key is down. It can be prevented by calling event.preventDefault. |
| onPointerDownOutside | (event: PointerDownOutsideEvent) => void Event handler called when a pointer event occurs outside the bounds of the component. It can be prevented by calling event.preventDefault. |
| onFocusOutside | (event: FocusOutsideEvent) => void Event handler called when the focus moves outside the bounds of the component. It can be prevented by calling event.preventDefault. |
| onInteractOutside | (event: InteractOutsideEvent) => void Event handler called when an interaction (pointer or focus event) happens outside the bounds of the component. It can be prevented by calling event.preventDefault. |
NavigationMenu.Item
| Prop | Description |
|---|---|
| textValue | string Optional text used for typeahead purposes. By default, the typeahead behavior will use the .textContent of the NavigationMenu.ItemLabel part if provided, or fallback to the .textContent of the NavigationMenu.Item. Use this when the content is complex, or you have non-textual content inside. |
| disabled | boolean Whether the item is disabled or not. |
| closeOnSelect | boolean Whether the menu should close when the item is activated. |
| onSelect | () => void Event handler called when the user selects an item (via mouse or keyboard). |
| Data attribute | Description |
|---|---|
| data-disabled | Present when the item is disabled. |
| data-highlighted | Present when the item is highlighted. |
NavigationMenu.ItemLabel, NavigationMenu.ItemDescription과 NavigationMenu.ItemIndicator는 동일한 data-attribute를 공유해요.
NavigationMenu.ItemIndicator
| Prop | Description |
|---|---|
| forceMount | boolean Used to force mounting when more control is needed. Useful when controlling animation with SolidJS animation libraries. |
NavigationMenu.RadioGroup
| Prop | Description |
|---|---|
| value | string The controlled value of the menu radio item to check. |
| defaultValue | string The value of the menu radio item that should be checked when initially rendered. Useful when you do not need to control the state of the radio group. |
| onChange | (value: string) => void Event handler called when the value changes. |
| disabled | boolean Whether the radio group is disabled or not. |
NavigationMenu.RadioItem
| Prop | Description |
|---|---|
| value | string The value of the menu item radio. |
| textValue | string Optional text used for typeahead purposes. By default, the typeahead behavior will use the .textContent of the NavigationMenu.ItemLabel part if provided, or fallback to the .textContent of the NavigationMenu.Item. Use this when the content is complex, or you have non-textual content inside. |
| disabled | boolean Whether the item is disabled or not. |
| closeOnSelect | boolean Whether the menu should close when the item is checked. |
| onSelect | () => void Event handler called when the user selects an item (via mouse or keyboard). |
| Data attribute | Description |
|---|---|
| data-disabled | Present when the item is disabled. |
| data-checked | Present when the item is checked. |
| data-highlighted | Present when the item is highlighted. |
NavigationMenu.CheckboxItem
| Prop | Description |
|---|---|
| checked | boolean The controlled checked state of the item. |
| defaultChecked | boolean The default checked state when initially rendered. Useful when you do not need to control the checked state. |
| onChange | (checked: boolean) => void Event handler called when the checked state of the item changes. |
| textValue | string Optional text used for typeahead purposes. By default, the typeahead behavior will use the .textContent of the NavigationMenu.ItemLabel part if provided, or fallback to the .textContent of the NavigationMenu.Item. Use this when the content is complex, or you have non-textual content inside. |
| indeterminate | boolean Whether the item is in an indeterminate state. |
| disabled | boolean Whether the item is disabled or not. |
| closeOnSelect | boolean Whether the menu should close when the item is checked/unchecked. |
| onSelect | () => void Event handler called when the user selects an item (via mouse or keyboard). |
| Data attribute | Description |
|---|---|
| data-disabled | Present when the item is disabled. |
| data-indeterminate | Present when the item is in an indeterminate state. |
| data-checked | Present when the item is checked. |
| data-highlighted | Present when the item is highlighted. |
NavigationMenu.Sub
| Prop | Description |
|---|---|
| open | boolean The controlled open state of the sub menu. |
| defaultOpen | boolean The default open state when initially rendered. Useful when you do not need to control the open state. |
| onOpenChange | (open: boolean) => void Event handler called when the open state of the sub menu changes. |
NavigationMenu.Sub는 NavigationMenu.SubContent의 배치(placement)를 커스텀하기 위해 다음의 prop들을 추가로 받아요.
| Prop | Description |
|---|---|
| getAnchorRect | (anchor?: HTMLElement) => AnchorRect | undefined Function that returns the trigger element's DOMRect. |
| gutter | number The distance between the sub menu content and the trigger element. By default, it's 0 plus half of the arrow offset, if it exists. |
| shift | number The skidding of the sub menu content along the trigger element. |
| slide | boolean Whether the sub menu content should slide when it overflows. |
| overlap | boolean Whether the sub menu content can overlap the trigger element when it overflows. |
| fitViewport | boolean Whether the sub menu content should fit the viewport. If this is set to true, the sub menu content will have maxWidth and maxHeight set to the viewport size. This will be exposed to CSS as --kb-popper-available-width and --kb-popper-available-height. |
| hideWhenDetached | boolean Whether to hide the sub menu content when the trigger element becomes occluded. |
| detachedPadding | number The minimum padding in order to consider the trigger element occluded. |
| arrowPadding | number The minimum padding between the arrow and the sub menu content corner. |
| overflowPadding | number The minimum padding between the sub menu content and the viewport edge. This will be exposed to CSS as --kb-popper-overflow-padding. |
NavigationMenu.SubTrigger
| Prop | Description |
|---|---|
| textValue | string Optional text used for typeahead purposes. By default, the typeahead behavior will use the .textContent of the NavigationMenu.SubTrigger. Use this when the content is complex, or you have non-textual content inside. |
| disabled | boolean Whether the sub menu trigger is disabled or not. |
| Data attribute | Description |
|---|---|
| data-disabled | Present when the item is disabled. |
| data-highlighted | Present when the item is highlighted. |
NavigationMenu.SubContent
| Prop | Description |
|---|---|
| onEscapeKeyDown | (event: KeyboardEvent) => void Event handler called when the escape key is down. It can be prevented by calling event.preventDefault. |
| onPointerDownOutside | (event: PointerDownOutsideEvent) => void Event handler called when a pointer event occurs outside the bounds of the component. It can be prevented by calling event.preventDefault. |
| onFocusOutside | (event: FocusOutsideEvent) => void Event handler called when the focus moves outside the bounds of the component. It can be prevented by calling event.preventDefault. |
| onInteractOutside | (event: InteractOutsideEvent) => void Event handler called when an interaction (pointer or focus event) happens outside the bounds of the component. It can be prevented by calling event.preventDefault. |
Rendered elements (렌더링되는 요소)
| Component | Default rendered element |
|---|---|
NavigationMenu |
ul |
NavigationMenu.Viewport |
li |
NavigationMenu.Arrow |
div |
NavigationMenu.Menu |
none |
NavigationMenu.Trigger |
div |
NavigationMenu.Icon |
div |
NavigationMenu.Portal |
Portal |
NavigationMenu.Content |
ul |
NavigationMenu.Separator |
hr |
NavigationMenu.Group |
div |
NavigationMenu.GroupLabel |
span |
NavigationMenu.Sub |
none |
NavigationMenu.SubTrigger |
div |
NavigationMenu.SubContent |
div |
NavigationMenu.Item |
a |
NavigationMenu.ItemLabel |
div |
NavigationMenu.ItemDescription |
div |
NavigationMenu.ItemIndicator |
div |
NavigationMenu.RadioGroup |
div |
NavigationMenu.RadioItem |
div |
NavigationMenu.CheckboxItem |
div |
Accessibility (접근성)
Keyboard Interactions (키보드 상호작용)
| Key | Description |
|---|---|
| Space | When focus is on an item, activates the item. |
| Enter | When focus is on an item, activates the item. |
| ArrowDown | When focus is on an item, moves focus to the next item. |
| ArrowUp | When focus is on an item, moves focus to the previous item. |
| ArrowRight | When focus is on an item (not sub menu trigger), moves focus to the next menu. |
| ArrowLeft | When focus is on an item (not sub menu item), moves focus to the previous menu. |
| ArrowRight / ArrowLeft | When focus is on a sub menu trigger, opens or closes the submenu depending on reading direction. |
| Home | When focus is on an item, moves focus to first item. |
| End | When focus is on an item, moves focus to last item. |
| Esc | Closes the menu. |
더 알아보기 (Learn more)
- Navigation Menu 컴포넌트 소스 — GitHub 저장소
- WAI ARIA Menubar 패턴 — 접근성 가이드라인
- Kobalte 시작하기 — 프로젝트 설정