navigation-menu
shadcn-solidjs/navigation-menuFreeComponent
shadcn-solidjs publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by shadcn-solidjs on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://shadcn-solidjs.com/r/navigation-menu.jsonSource
1import type { PolymorphicProps } from "@kobalte/core";2import * as NavigationMenuPrimitive from "@kobalte/core/navigation-menu";34import { cn } from "~/lib/utils.ts";5import IconChevronDown from "~icons/lucide/chevron-down";6import { cva } from "class-variance-authority";78import type { JSX, ValidComponent } from "solid-js";9import {10 createContext,11 createEffect,12 createSignal,13 onCleanup,14 Show,15 splitProps,16 useContext,17} from "solid-js";1819// Kobalte folds Radix's `Root` and `List` into a single primitive: the root20// renders the `<nav>` wrapper and the `<ul>` itself, so there is no separate21// `NavigationMenuList`. It also has no `Item` element — `NavigationMenu.Menu`22// only provides context, and the `<li>` wrappers come from `Trigger`/`Link`.23const NavigationMenuItem = NavigationMenuPrimitive.Menu;2425// Kobalte's `Portal` mounts a content into the viewport, so with26// `viewport={false}` the content has to render in place instead. The root27// publishes the flag for `NavigationMenuContent` to read.28const NavigationMenuViewportContext = createContext<() => boolean>(() => true);2930type NavigationMenuProps<T extends ValidComponent = "ul"> =31 & NavigationMenuPrimitive.NavigationMenuRootProps<T>32 & {33 class?: string | undefined;34 children?: JSX.Element;35 viewport?: boolean;36 };3738// Kobalte's popper centres the viewport on the menu bar; upstream's wrapper is39// `left-0`, so the placement is pinned to the start edge — on the axis Kobalte40// itself would pick for the orientation, so a vertical menu still opens sideways41// the way its `data-[orientation=vertical]:flex-col` bar expects.42//43// `viewport={false}` also has to be given its own dismissal. Kobalte wires44// `onEscapeKeyDown` only into the viewport's `DismissableLayer` and into the45// `Popper.Positioner` branch of `MenuContentBase`; with no viewport neither of46// them renders, so nothing but an outside click can close the menu. The root47// therefore takes over the open menu's value and closes it from a document-level48// `keydown` listener — the same place Kobalte's own dismissable layer listens —49// attached only while such a menu is open.50const NavigationMenu = <T extends ValidComponent = "ul">(51 props: PolymorphicProps<T, NavigationMenuProps<T>>,52) => {53 const [local, others] = splitProps(props as NavigationMenuProps, [54 "class",55 "children",56 "viewport",57 "value",58 "onValueChange",59 ]);60 const viewport = () => local.viewport ?? true;61// … truncated
What it pulls in
npm packages
More from shadcn-solidjs
All 85 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| accordionaccordion | shadcn-solidjs | Components | Free | 1 dep | |
| alertalert | shadcn-solidjs | Components | Free | 2 deps | |
| alert-dialogalert-dialog | shadcn-solidjs | Components | Free | 2 deps | |
| aspect-ratioaspect-ratio | shadcn-solidjs | Components | Free | no deps | |
| attachmentattachment | shadcn-solidjs | Components | Free | 2 deps | |
| avataravatar | shadcn-solidjs | Components | Free | 1 dep | |
| badgebadge | shadcn-solidjs | Components | Free | 2 deps | |
| breadcrumbbreadcrumb | shadcn-solidjs | Components | Free | 1 dep |
