BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/trovecn/menu

Menu

trovecn/menu
FreeComponent

Base UI menu with submenus, checkbox/radio items, and a spring-driven popup.

Install it

npx shadcn@latest add https://trovecn.dev/r/menu.json

Source

src/components/ui/menu.tsxtrovecn.dev/r/menu.json · first 6 KB
1"use client";
2
3import {
4 Children,
5 cloneElement,
6 createContext,
7 isValidElement,
8 useContext,
9 useEffect,
10 useMemo,
11 useRef,
12 type ComponentProps,
13 type ReactElement,
14 type ReactNode,
15} from "react";
16import { Menu as MenuPrimitive } from "@base-ui/react/menu";
17import { motion, AnimatePresence, useReducedMotion } from "motion/react";
18import { CheckIcon, ChevronRightIcon } from "lucide-react";
19
20import { cn } from "@/lib/utils";
21import { spring } from "@/lib/springs";
22import { useProximityHover, proximityHoverWashClassName } from "@/hooks/use-proximity-hover";
23
24// ─── Proximity hover ─────────────────────────────────────────────────────────
25// Every MenuContent/MenuSubContent popup owns one useProximityHover instance
26// — the same measured-rect hover wash Accordion/Tabs use, scoped to that
27// popup's own items so a submenu's pill never reaches into its parent's.
28// Base UI's own `data-highlighted` (keyboard nav and pointer hover both set
29// it) still drives each row's text color, same split Accordion uses between
30// its pill-owns-background and item-owns-text-color.
31
32interface MenuProximityContextValue {
33 registerItem: (index: number, element: HTMLElement | null) => void;
34}
35
36const MenuProximityContext = createContext<MenuProximityContextValue | null>(null);
37
38/** Position for proximity hover — auto-assigned by MenuContent's child walk; only present on items it recognized as interactive rows. */
39type MenuIndexProp = { _index?: number };
40
41function useMenuItemRegistration(ref: React.RefObject<HTMLElement | null>, index?: number) {
42 const ctx = useContext(MenuProximityContext);
43 useEffect(() => {
44 if (index === undefined || !ctx) return;
45 ctx.registerItem(index, ref.current);
46 return () => ctx.registerItem(index, null);
47 // eslint-disable-next-line react-hooks/exhaustive-deps
48 }, [index, ctx]);
49}
50
51/**
52 * Auto-indexes MenuContent's children so callers never hand-thread an index
53 * just for proximity hover — mirrors Accordion's indexedChildren, but as a
54 * recursive walk (not a flat Children.map) since indexable rows can sit one
55 * level down inside a MenuGroup/MenuRadioGroup. MenuSub's trigger is indexed
56 * as a row in *this* popup, but Base UI requires it nested one level inside
57 * MenuSub (alongside the portaled SubContent), so that level is unwrapped
58// … truncated

What it pulls in

npm packages

  • @base-ui/react
  • motion
  • lucide-react

Other registry items

  • utils
  • springs
  • use-proximity-hover

Files it writes

  • src/components/ui/menu.tsx

Facts

Registry
trovecn
Type
registry:ui
Access
Free
Files written
1
Licence
MIT
In the index
at or before 2026-08-14
Last confirmed
today

Go to the source

trovecn.dev PPRAMANIK62/trovecn on GitHub Raw registry item This item as JSON

More from trovecn

All 26 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
AccordionaccordiontrovecnComponentsFree3 deps
Agent Activityagent-activitytrovecnComponentsFree2 deps
Approval Requestapproval-requesttrovecnComponentsFree2 deps
ButtonbuttontrovecnComponentsFree2 deps
CheckboxcheckboxtrovecnComponentsFree2 deps
Checkbox Groupcheckbox-grouptrovecnComponentsFree2 deps
ComboboxcomboboxtrovecnComponentsFree3 deps
Comparison Slidercomparison-slidertrovecnComponentsFree1 dep

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind StoreReady, ToolDrift and BreachProbe

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product.

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind StoreReady, ToolDrift and BreachProbe

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product.

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind StoreReady, ToolDrift and BreachProbe

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product.

BlockDex