mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-07-07 14:08:47 +00:00
92 lines
2.2 KiB
Plaintext
92 lines
2.2 KiB
Plaintext
---
|
|
title: Navigation Menu
|
|
description: A collection of links for navigating websites.
|
|
component: true
|
|
radix:
|
|
link: https://www.radix-ui.com/docs/primitives/components/navigation-menu
|
|
api: https://www.radix-ui.com/docs/primitives/components/navigation-menu#api-reference
|
|
---
|
|
|
|
<ComponentExample src="/components/examples/navigation-menu/demo.tsx">
|
|
<NavigationMenuDemo />
|
|
</ComponentExample>
|
|
|
|
## Installation
|
|
|
|
```bash
|
|
npx shadcn-ui add navigation-menu
|
|
```
|
|
|
|
<Accordion type="single" collapsible>
|
|
<AccordionItem value="manual-installation">
|
|
<AccordionTrigger>Manual Installation</AccordionTrigger>
|
|
<AccordionContent>
|
|
|
|
1. Install the `@radix-ui/react-navigation-menu` component from radix-ui:
|
|
|
|
```bash
|
|
npm install @radix-ui/react-navigation-menu
|
|
```
|
|
|
|
2. Copy and paste the following code into your project.
|
|
|
|
<ComponentSource src="/components/ui/navigation-menu.tsx" />
|
|
|
|
<Callout>
|
|
This is the `<NavigationMenu />` primitive. You can place it in a file at
|
|
`components/ui/navigation-menu.tsx`.
|
|
</Callout>
|
|
|
|
</AccordionContent>
|
|
|
|
</AccordionItem>
|
|
</Accordion>
|
|
|
|
## Usage
|
|
|
|
```tsx
|
|
import {
|
|
NavigationMenu,
|
|
NavigationMenuContent,
|
|
NavigationMenuIndicator,
|
|
NavigationMenuItem,
|
|
NavigationMenuLink,
|
|
NavigationMenuList,
|
|
NavigationMenuTrigger,
|
|
NavigationMenuViewport,
|
|
} from "@/components/ui/navigation-menu"
|
|
```
|
|
|
|
```tsx
|
|
<NavigationMenu>
|
|
<NavigationMenuList>
|
|
<NavigationMenuItem>
|
|
<NavigationMenuTrigger>Item One</NavigationMenuTrigger>
|
|
<NavigationMenuContent>
|
|
<NavigationMenuLink>Link</NavigationMenuLink>
|
|
</NavigationMenuContent>
|
|
</NavigationMenuItem>
|
|
</NavigationMenuList>
|
|
</NavigationMenu>
|
|
```
|
|
|
|
### Link Component
|
|
|
|
When using the Next.js `<Link />` component, you can use `navigationMenuTriggerStyle()` to apply the correct styles to the trigger.
|
|
|
|
```tsx
|
|
import { navigationMenuTriggerStyle } from "@/components/ui/navigation-menu"
|
|
```
|
|
|
|
```tsx {3-5}
|
|
<NavigationMenuItem>
|
|
<Link href="/docs" legacyBehavior passHref>
|
|
<NavigationMenuLink className={navigationMenuTriggerStyle()}>
|
|
Documentation
|
|
</NavigationMenuLink>
|
|
</Link>
|
|
</NavigationMenuItem>
|
|
```
|
|
|
|
See also the [Radix UI documentation](https://www.radix-ui.com/docs/primitives/components/navigation-menu#with-client-side-routing) for handling client side routing.
|