Typing @ or / opens a menu at the cursor, with rows cascading in and a gliding highlight.
Part of Keyframery, the open-source animated components for UI SDK
The demo plays by itself. Point at it or press Tab to take over.
Installation
npx shadcn@latest add @keyframery/trigger-menuThis adds components/keyframery/trigger-menu.tsx and its primitive, components/keyframery/primitives/trigger-menu.tsx, to your project, and installs @ui-sdk/react. The motion tokens are added to your global CSS the first time you install a component.
Usage
import {
TriggerMenu,
TriggerMenuContent,
TriggerMenuEmpty,
TriggerMenuGroup,
TriggerMenuGroupLabel,
TriggerMenuHint,
TriggerMenuInput,
TriggerMenuItem,
TriggerMenuItemIcon,
TriggerMenuItems,
TriggerMenuList,
TriggerMenuSeparator,
TriggerMenuStatus,
} from "@/components/keyframery/trigger-menu"The parts and props are the same as UI SDK's Trigger Menu. For every prop, see the UI SDK trigger menu reference.
What moves
| Move | What you see |
|---|---|
| Unfold | Typing @ or / opens a menu at the cursor. |
| Cascade | Rows arrive one after another. |
| Glide | One highlight glides between items. |
Timing and springiness follow the motion style you set, so this component moves like the rest of your app.
Swap the import
Already using UI SDK's trigger menu with your own styles? Keep your markup and change one line. The primitive adds motion and nothing else.
// Before
import { … } from "@ui-sdk/react/trigger-menu"
// After: same parts, same props, now animated
import { … } from "@/components/keyframery/primitives/trigger-menu"Parts
The finished component exports 13 parts:
TriggerMenu, TriggerMenuContent, TriggerMenuEmpty, TriggerMenuGroup, TriggerMenuGroupLabel, TriggerMenuHint, TriggerMenuInput, TriggerMenuItem, TriggerMenuItemIcon, TriggerMenuItems, TriggerMenuList, TriggerMenuSeparator, TriggerMenuStatus
Accessibility
Keyboard, focus and screen-reader behaviour come from UI SDK and are not changed. With reduced motion turned on, nothing in the trigger menu moves: changes happen at once or with a short fade. More in Accessibility.
Source
The code that lands in your project. It is yours to change.
"use client"
/* Styled trigger menu: the animated primitive plus the Keyframery look. */
import {
createTriggerMenuController,
textFieldAdapter,
TriggerMenu as TriggerMenuRoot,
TriggerMenuContent as TriggerMenuContentPart,
type TriggerMenuData,
TriggerMenuEmpty as TriggerMenuEmptyPart,
TriggerMenuGroup as TriggerMenuGroupPart,
TriggerMenuGroupLabel as TriggerMenuGroupLabelPart,
TriggerMenuHint as TriggerMenuHintPart,
TriggerMenuInput as TriggerMenuInputPart,
TriggerMenuItem as TriggerMenuItemPart,
TriggerMenuItemIcon as TriggerMenuItemIconPart,
TriggerMenuList as TriggerMenuListPart,
type TriggerMenuProps,
TriggerMenuSeparator as TriggerMenuSeparatorPart,
TriggerMenuStatus as TriggerMenuStatusPart,
} from "@/components/keyframery/primitives/trigger-menu"
import * as React from "react"
import { cn } from "@/lib/utils"
/* The sheet. Its motion comes from the primitive. */
const sheet = cn(
"group/content m-0 flex w-64 flex-col border-0 p-0 outline-none",
"[--list-height:var(--available-height)]",
"rounded-[14px] bg-popover text-popover-foreground",
"shadow-[0_0_0_1px_rgb(0_0_0/0.06),0_2px_6px_-2px_rgb(0_0_0/0.08),0_12px_32px_-8px_rgb(0_0_0/0.18)]",
"dark:shadow-[0_0_0_1px_rgb(255_255_255/0.08),0_12px_32px_-8px_rgb(0_0_0/0.7)]",
)
/* One row per suggestion. Focus stays in the field; the list's gliding highlight is the cursor. */
const row = cn(
"group/item relative flex min-h-8 cursor-default items-center gap-2 rounded-[8px] px-2 py-1.5 text-[13px] leading-4 outline-none select-none",
"data-highlighted:text-accent-foreground",
"data-disabled:text-muted-foreground/60 data-disabled:data-highlighted:text-muted-foreground/60",
/* Rows without an icon keep the icon column when another row in the list has one. */
"[[data-has-icons]_&:not([data-has-icon])]:ps-8",
)
function TriggerMenu<T = string>(props: TriggerMenuProps<T>) {
return <TriggerMenuRoot<T> {...props} />
}
/* The field people type in: a textarea by default, an input through `render`. */
function TriggerMenuInput({
className,
...props
}: React.ComponentProps<typeof TriggerMenuInputPart>) {
return (
<TriggerMenuInputPart
className={cn(
"block min-h-9 w-full min-w-0 resize-none rounded-[10px] bg-background px-3 py-2 text-[13px] leading-5 text-foreground outline-none placeholder:text-muted-foreground",
"[field-sizing:content] [&:is(textarea)]:min-h-[84px]",
"shadow-[0_0_0_1px_rgb(0_0_0/0.09),0_1px_2px_rgb(0_0_0/0.05)] dark:shadow-[0_0_0_1px_rgb(255_255_255/0.1)]",
"transition-shadow duration-[calc(150ms*var(--kf-speed,1))] motion-reduce:transition-none!",
"hover:shadow-[0_0_0_1px_rgb(0_0_0/0.16),0_1px_2px_rgb(0_0_0/0.05)] dark:hover:shadow-[0_0_0_1px_rgb(255_255_255/0.16)]",
"focus-visible:shadow-[0_0_0_1px_var(--ring)] focus-visible:ring-[3px] focus-visible:ring-ring/25 dark:focus-visible:shadow-[0_0_0_1px_var(--ring)]",
"aria-invalid:shadow-[0_0_0_1px_var(--destructive)] aria-invalid:focus-visible:ring-destructive/25 dark:aria-invalid:shadow-[0_0_0_1px_var(--destructive)]",
"disabled:cursor-not-allowed disabled:opacity-50 read-only:bg-muted/40",
className,
)}
{...props}
/>
)
}
function TriggerMenuContent({
className,
children,
sideOffset = 6,
...props
}: React.ComponentProps<typeof TriggerMenuContentPart>) {
return (
<TriggerMenuContentPart
sideOffset={sideOffset}
className={cn(sheet, className)}
{...props}
>
{children ?? <TriggerMenuList />}
</TriggerMenuContentPart>
)
}
function TriggerMenuList({
className,
children,
...props
}: React.ComponentProps<typeof TriggerMenuListPart>) {
return (
<TriggerMenuListPart
className={cn(
"max-h-[min(calc(var(--list-height,100vh)-8px),18rem)] scroll-py-1.5 overflow-y-auto overscroll-contain p-1.5 outline-none",
"aria-busy:opacity-60 before:rounded-[8px] before:bg-accent",
"has-[[data-disabled][data-highlighted]]:before:bg-accent/50",
"group-has-[[data-slot=trigger-menu-empty][data-empty]]/content:hidden",
className,
)}
{...props}
>
{children ?? ((state) => <TriggerMenuItems items={state.items} />)}
</TriggerMenuListPart>
)
}
function TriggerMenuItem<T = string>({
className,
...props
}: React.ComponentProps<typeof TriggerMenuItemPart<T>>) {
return <TriggerMenuItemPart<T> className={cn(row, className)} {...props} />
}
function TriggerMenuItemIcon({
className,
...props
}: React.ComponentProps<typeof TriggerMenuItemIconPart>) {
return (
<TriggerMenuItemIconPart
className={cn(
"flex size-4 shrink-0 items-center justify-center text-muted-foreground [&>svg]:size-4",
"group-data-highlighted/item:text-current",
"rtl:data-mirror:-scale-x-100",
className,
)}
{...props}
/>
)
}
function TriggerMenuGroup({
className,
...props
}: React.ComponentProps<typeof TriggerMenuGroupPart>) {
return <TriggerMenuGroupPart className={cn("flex flex-col", className)} {...props} />
}
function TriggerMenuGroupLabel({
className,
...props
}: React.ComponentProps<typeof TriggerMenuGroupLabelPart>) {
return (
<TriggerMenuGroupLabelPart
className={cn(
"px-2 pt-1.5 pb-1 text-[11px] leading-4 font-medium text-muted-foreground select-none",
className,
)}
{...props}
/>
)
}
function TriggerMenuSeparator({
className,
...props
}: React.ComponentProps<typeof TriggerMenuSeparatorPart>) {
return (
<TriggerMenuSeparatorPart
className={cn("-mx-1.5 my-1.5 h-px bg-border", className)}
{...props}
/>
)
}
/* Shown while nothing matches. Rendering it keeps the menu open with no matches. */
function TriggerMenuEmpty({
className,
...props
}: React.ComponentProps<typeof TriggerMenuEmptyPart>) {
return (
<TriggerMenuEmptyPart
className={cn(
"hidden px-3 py-5 text-center text-[13px] text-muted-foreground data-empty:block data-loading:block",
className,
)}
{...props}
/>
)
}
/* A polite live region. Hidden from sight by default, heard by screen readers. */
function TriggerMenuStatus({
className,
...props
}: React.ComponentProps<typeof TriggerMenuStatusPart>) {
return <TriggerMenuStatusPart className={cn("sr-only", className)} {...props} />
}
/* Ghost text at the caret for the arguments still to type. */
function TriggerMenuHint({
className,
...props
}: React.ComponentProps<typeof TriggerMenuHintPart>) {
return (
<TriggerMenuHintPart
className={cn("pointer-events-none text-[13px] text-muted-foreground/70 select-none", className)}
{...props}
/>
)
}
/* Renders suggestions passed as data with the styled parts above. */
function TriggerMenuItems({ items }: { items?: TriggerMenuData<unknown> }) {
return (items ?? []).map((entry, index) => {
if (typeof entry === "string") {
return (
<TriggerMenuItem key={entry} value={entry} label={entry}>
{entry}
</TriggerMenuItem>
)
}
if ("type" in entry && entry.type === "separator") {
return <TriggerMenuSeparator key={`separator-${index}`} />
}
if ("type" in entry && entry.type === "group") {
return (
<TriggerMenuGroup key={`group-${entry.label ?? index}`}>
{entry.label && <TriggerMenuGroupLabel>{entry.label}</TriggerMenuGroupLabel>}
<TriggerMenuItems items={entry.items} />
</TriggerMenuGroup>
)
}
const { value, label, disabled, keywords } = entry
return (
<TriggerMenuItem<unknown>
key={typeof value === "string" ? value : index}
value={value}
label={label}
disabled={disabled}
keywords={keywords}
>
{label}
</TriggerMenuItem>
)
})
}
export type { TriggerMenuData, TriggerMenuDataItem } from "@/components/keyframery/primitives/trigger-menu"
export {
createTriggerMenuController,
textFieldAdapter,
TriggerMenu,
TriggerMenuContent,
TriggerMenuEmpty,
TriggerMenuGroup,
TriggerMenuGroupLabel,
TriggerMenuHint,
TriggerMenuInput,
TriggerMenuItem,
TriggerMenuItemIcon,
TriggerMenuItems,
TriggerMenuList,
TriggerMenuSeparator,
TriggerMenuStatus,
}"use client"
/* Animated drop-in for `@ui-sdk/react/trigger-menu`: same parts, same props. Swap the import and keep your code.
This file adds motion only. Colours, radii, shadows and spacing stay yours.
- Content: Unfold from the caret (scale 0.86, 6px blur, 8px toward the line; spring in, quick out).
- List: rows Cascade in as the list opens, and one highlight Glides between them as you
arrow through (CSS anchor positioning). Its neutral surface follows the text colour; give
`before:bg-…` and `before:rounded-…` to restyle it. */
import {
TriggerMenuContent as TriggerMenuContentPart,
TriggerMenuItem as TriggerMenuItemPart,
TriggerMenuList as TriggerMenuListPart,
} from "@ui-sdk/react/trigger-menu"
import * as React from "react"
import { cn } from "@/lib/utils"
export * from "@ui-sdk/react/trigger-menu"
function TriggerMenuContent({ className, ...props }: React.ComponentProps<typeof TriggerMenuContentPart>) {
return (
<TriggerMenuContentPart
className={cn(
"group/kf-tm origin-(--transform-origin)",
"[transition:opacity_calc(380ms*var(--kf-speed,1))_var(--ease-spring),scale_calc(380ms*var(--kf-speed,1))_var(--ease-spring),translate_calc(380ms*var(--kf-speed,1))_var(--ease-spring),filter_calc(380ms*var(--kf-speed,1))_var(--ease-spring)]",
"data-[side=bottom]:[--kf-from:0_-8px] data-[side=top]:[--kf-from:0_8px] data-[side=left]:[--kf-from:8px_0] data-[side=right]:[--kf-from:-8px_0]",
"data-starting-style:[translate:var(--kf-from,0_0)] data-starting-style:scale-[0.86] data-starting-style:opacity-0 data-starting-style:blur-[6px]",
"data-ending-style:scale-[0.96] data-ending-style:opacity-0 data-ending-style:blur-[2px]",
"data-ending-style:[transition:opacity_calc(150ms*var(--kf-speed,1))_var(--ease-house),scale_calc(150ms*var(--kf-speed,1))_var(--ease-house),translate_calc(150ms*var(--kf-speed,1))_var(--ease-house),filter_calc(150ms*var(--kf-speed,1))_var(--ease-house)]",
"motion-reduce:[transition:none]!",
className,
)}
{...props}
/>
)
}
function TriggerMenuList({ className, ...props }: React.ComponentProps<typeof TriggerMenuListPart>) {
return (
<TriggerMenuListPart
className={cn(
/* Cascade: the list's children, one after another, while the content unfolds. */
"[&>*]:transition-[opacity,translate,filter] [&>*]:duration-[calc(420ms*var(--kf-speed,1))] [&>*]:ease-spring",
"[&>*]:[transition-delay:calc((min(sibling-index(),10)-1)*calc(32ms*var(--kf-speed,1)))]",
"group-data-starting-style/kf-tm:[&>*]:translate-y-2 group-data-starting-style/kf-tm:[&>*]:opacity-0 group-data-starting-style/kf-tm:[&>*]:blur-[4px]",
"group-data-ending-style/kf-tm:[&>*]:[transition-delay:0ms]",
"group-data-starting-style/kf-tm:[&>*]:[transition:none]",
/* Glide */
"relative isolate [anchor-scope:--kf-hl]",
"before:pointer-events-none before:absolute before:-z-10 before:hidden before:bg-[color-mix(in_oklch,currentColor_9%,transparent)]",
"before:[position-anchor:--kf-hl] before:top-[anchor(top)] before:right-[anchor(right)] before:bottom-[anchor(bottom)] before:left-[anchor(left)]",
"before:[transition:top_calc(260ms*var(--kf-speed,1))_var(--ease-spring),right_calc(260ms*var(--kf-speed,1))_var(--ease-spring),bottom_calc(260ms*var(--kf-speed,1))_var(--ease-spring),left_calc(260ms*var(--kf-speed,1))_var(--ease-spring),opacity_calc(150ms*var(--kf-speed,1))_var(--ease-house)]",
"has-[[data-highlighted]]:before:block starting:before:opacity-0",
"motion-reduce:[&>*]:[transition:none] motion-reduce:before:[transition:none]!",
className,
)}
{...props}
/>
)
}
function TriggerMenuItem<T = string>({ className, ...props }: React.ComponentProps<typeof TriggerMenuItemPart<T>>) {
return <TriggerMenuItemPart<T> className={cn("data-highlighted:[anchor-name:--kf-hl]", className)} {...props} />
}
export { TriggerMenuContent, TriggerMenuItem, TriggerMenuList }Questions
How does the animated Trigger Menu for UI SDK move?
Unfold: Typing @ or / opens a menu at the cursor. Cascade: Rows arrive one after another. Glide: One highlight glides between items.
Do I need Motion or Framer Motion for the animated Trigger Menu?
No. Every move is plain CSS, so there is nothing to install besides the component and UI SDK.
Can I keep my own styling and only take the motion?
Yes. Import from @/components/keyframery/primitives/trigger-menu instead. It has the same parts and props as @ui-sdk/react/trigger-menu and adds motion only.
What happens to the Trigger Menu when someone turns on reduced motion?
Nothing moves. State changes happen at once, or with a short fade.