# Menu URL: /lynx/components/menu Source: https://github.com/daangn/seed-design/blob/dev/docs/content/lynx/components/menu.mdx A component that provides a list of choices or actions that users can take. Lynx Engine 최소 버전: 3.9 사용 XElement: ## Preview ```tsx import "./styles"; import IconPencilLine from "@karrotmarket/lynx-monochrome-icon/IconPencilLine"; import IconPlusLine from "@karrotmarket/lynx-monochrome-icon/IconPlusLine"; import IconTrashcanLine from "@karrotmarket/lynx-monochrome-icon/IconTrashcanLine"; import { ActionButton, VStack, useSeedClassName } from "@seed-design/lynx-react"; import { MenuContent, MenuGroup, MenuGroupLabel, MenuItem, MenuRoot, MenuTrigger, } from "@/components/ui/menu"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 열기 작업 } /> } /> } /> ); } ``` ## Installation - npm: npx @seed-design/cli@latest add ui:menu - pnpm: pnpm dlx @seed-design/cli@latest add ui:menu - yarn: yarn dlx @seed-design/cli@latest add ui:menu - bun: bun x @seed-design/cli@latest add ui:menu ## Usage Menu consists of Root, Trigger, Content, and Group. `MenuContent` handles native overlay, position calculation, display lifetime, and vertical scrolling of long lists together. ```tsx import { ActionButton } from "@seed-design/lynx-react"; import { MenuContent, MenuGroup, MenuGroupLabel, MenuItem, MenuRoot, MenuTrigger, } from "@/components/ui/menu"; export function App() { return ( Open Actions ); } ``` - `MenuRoot` manages the open state and position. - `MenuTrigger` opens a closed Menu by tapping. - `MenuAnchor` provides only the position reference point. Control the open state with `open` and `onOpenChange`. - `MenuContent` renders the overlay and scrollable menu list. Do not add a separate `Positioner` or `ScrollArea` to children. - `MenuGroup` and `MenuGroupLabel` group related items and display the title. - `MenuItem` assembles `label`, optional `description`, `prefixIcon`, `suffixIcon` into one item. ## Props ### `MenuRoot` ### `MenuTrigger` ### `MenuAnchor` ### `MenuContent` ### `MenuGroup` ### `MenuGroupLabel` ### `MenuItem` ## Examples ### Trigger Tapping `MenuTrigger` opens a closed Menu. Tapping `MenuItem` or the outer area closes it. ## Preview ```tsx import "./styles"; import IconPencilLine from "@karrotmarket/lynx-monochrome-icon/IconPencilLine"; import IconPlusLine from "@karrotmarket/lynx-monochrome-icon/IconPlusLine"; import IconTrashcanLine from "@karrotmarket/lynx-monochrome-icon/IconTrashcanLine"; import { ActionButton, VStack, useSeedClassName } from "@seed-design/lynx-react"; import { MenuContent, MenuGroup, MenuGroupLabel, MenuItem, MenuRoot, MenuTrigger, } from "@/components/ui/menu"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 열기 작업 } /> } /> } /> ); } ``` ### Size Set the Menu size with `size`. The default is `"medium"`. `"responsive"` changes to `"small"` or `"medium"` based on the current screen width. ```tsx import "./styles"; import IconPencilLine from "@karrotmarket/lynx-monochrome-icon/IconPencilLine"; import IconPlusLine from "@karrotmarket/lynx-monochrome-icon/IconPlusLine"; import { ActionButton, HStack, useSeedClassName } from "@seed-design/lynx-react"; import { MenuContent, MenuGroup, MenuGroupLabel, MenuItem, MenuRoot, MenuTrigger, type MenuRootProps, } from "@/components/ui/menu"; function SizeMenu({ size, label }: { size: MenuRootProps["size"]; label: string }) { return ( {label} 작업 } /> } /> ); } export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( ); } ``` ### With Description Pass additional description of the item in `MenuItem`'s `description`. ```tsx import "./styles"; import IconArrowUpBracketDownLine from "@karrotmarket/lynx-monochrome-icon/IconArrowUpBracketDownLine"; import IconPencilLine from "@karrotmarket/lynx-monochrome-icon/IconPencilLine"; import IconPlusLine from "@karrotmarket/lynx-monochrome-icon/IconPlusLine"; import { ActionButton, VStack, useSeedClassName } from "@seed-design/lynx-react"; import { MenuContent, MenuGroup, MenuItem, MenuRoot, MenuTrigger } from "@/components/ui/menu"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 열기 } /> } /> } /> ); } ``` ### Tone Mark actions requiring caution, such as deletion, with `MenuItem`'s `tone="critical"`. ```tsx import "./styles"; import IconPencilLine from "@karrotmarket/lynx-monochrome-icon/IconPencilLine"; import IconPlusLine from "@karrotmarket/lynx-monochrome-icon/IconPlusLine"; import IconTrashcanLine from "@karrotmarket/lynx-monochrome-icon/IconTrashcanLine"; import { ActionButton, VStack, useSeedClassName } from "@seed-design/lynx-react"; import { MenuContent, MenuGroup, MenuItem, MenuRoot, MenuTrigger } from "@/components/ui/menu"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 열기 } /> } /> } /> ); } ``` ### Disabled Items `disabled` items do not execute `bindtap` when tapped and do not close the Menu. ```tsx import "./styles"; import IconArrowUpBracketDownLine from "@karrotmarket/lynx-monochrome-icon/IconArrowUpBracketDownLine"; import IconPencilLine from "@karrotmarket/lynx-monochrome-icon/IconPencilLine"; import IconPlusLine from "@karrotmarket/lynx-monochrome-icon/IconPlusLine"; import { ActionButton, VStack, useSeedClassName } from "@seed-design/lynx-react"; import { MenuContent, MenuGroup, MenuItem, MenuRoot, MenuTrigger } from "@/components/ui/menu"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 열기 } /> } disabled /> } /> ); } ``` ### Placement Position the Menu at 12 directions around the reference element using `MenuRoot`'s `placement`. The default is `"bottom"`. If there's insufficient space at the screen edge, the native runtime flips it or moves it within the boundary. ```tsx import "./styles"; import IconPencilLine from "@karrotmarket/lynx-monochrome-icon/IconPencilLine"; import IconPlusLine from "@karrotmarket/lynx-monochrome-icon/IconPlusLine"; import { ActionButton, Box, HStack, VStack, useSeedClassName } from "@seed-design/lynx-react"; import { MenuContent, MenuGroup, MenuItem, MenuRoot, MenuTrigger, type MenuRootProps, } from "@/components/ui/menu"; function PlacementMenu({ placement }: { placement: NonNullable }) { return ( {placement} } /> } /> ); } export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( ); } ``` ### Anchor `MenuAnchor` only sets the Menu position and does not open or close it by tapping. You can control the state with `open` and `onOpenChange` as in this example. ```tsx import "./styles"; import IconPencilLine from "@karrotmarket/lynx-monochrome-icon/IconPencilLine"; import IconPlusLine from "@karrotmarket/lynx-monochrome-icon/IconPlusLine"; import { useState } from "@lynx-js/react"; import { Box, HStack, useSeedClassName } from "@seed-design/lynx-react"; import { MenuAnchor, MenuContent, MenuGroup, MenuItem, MenuRoot } from "@/components/ui/menu"; import { Switch } from "@/components/ui/switch"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [open, setOpen] = useState(false); function handleOpenChange(nextOpen: boolean, details?: { reason?: string }) { "background only"; if (!nextOpen && details?.reason === "interactOutside") return; setOpen(nextOpen); } return ( } /> } /> ); } ``` While the native overlay is open, you cannot tap the Switch outside the Anchor. This example shows the flow of opening with the Switch when the Menu is closed and closing by selecting an item. Control to ignore taps outside the overlay is implemented by filtering `details.reason === "interactOutside"` in `onOpenChange`. ### Match Width Using `matchReferenceWidth` makes the Menu width equal to the Trigger or Anchor width. ```tsx import "./styles"; import { ActionButton, Box, VStack, useSeedClassName } from "@seed-design/lynx-react"; import { MenuContent, MenuGroup, MenuItem, MenuRoot, MenuTrigger } from "@/components/ui/menu"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 열기 ); } ``` ### `onOpenChange` details The `details` parameter, the second argument of `onOpenChange`, contains the reason for the state change and the native event. - Open: `"trigger"` - Close: `"trigger"`, `"interactOutside"`, `"itemClick"` - When native overlay requests closing: `"dismiss"` ```tsx import "./styles"; import IconPencilLine from "@karrotmarket/lynx-monochrome-icon/IconPencilLine"; import IconPlusLine from "@karrotmarket/lynx-monochrome-icon/IconPlusLine"; import { useState } from "@lynx-js/react"; import { ActionButton, HStack, VStack, useSeedClassName } from "@seed-design/lynx-react"; import { MenuContent, MenuGroup, MenuItem, MenuRoot, MenuTrigger } from "@/components/ui/menu"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [open, setOpen] = useState(false); const [openReason, setOpenReason] = useState(null); const [closeReason, setCloseReason] = useState(null); function handleOpenChange(nextOpen: boolean, details?: { reason?: string }) { "background only"; setOpen(nextOpen); (nextOpen ? setOpenReason : setCloseReason)(details?.reason ?? null); } return ( 열기 } /> } /> 마지막 열림 이유: {openReason ?? "-"} 마지막 닫힘 이유: {closeReason ?? "-"} ); } ``` ## Differences from Web Version Lynx Menu renders on top of native `overlay`. It does not support HTML DOM, `asChild`, keyboard focus, typeahead, or ESC key closing. Therefore, it does not provide `escapeKeyDown` and `cascadeDismiss` reasons. For keyboard accessibility needed at the screen and app level, check with the host's native accessibility flow. | Item | Web | Lynx | | ---------------------------- | ------------------------------------- | ------------------------------------------------------------------- | | Trigger composition | Supports `asChild` | Uses native Trigger wrapping children | | Position and list | DOM positioner and scroll area | `MenuContent` handles native overlay, position, and scroll together | | External interaction | DOM pointer and keyboard | Outer tap is `interactOutside`, native dismissal is `dismiss` | | Keyboard | Supports ESC, focus, typeahead | Not supported | | Control while Anchor is open | Can continue composing outer controls | Fullscreen overlay blocks taps outside Anchor |