All components smmd
Trigger Menu
Caret-anchored top-layer suggestion menu opened by typing triggers such as @ for mentions or / for commands.
Ask Elena Park — type @ or /
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import { TokenInput } from "#components/ui/ui-sdk/token-input.tsx";import { TriggerMenu, type TriggerDefinition, type TriggerMenuDataItem,} from "#components/ui/ui-sdk/trigger-menu.tsx";
const triggers: TriggerDefinition<string>[] = [ { char: "@", type: "mention", items: [ { value: "elena", label: "Elena Park" }, { value: "marcus", label: "Marcus Cole" }, ], }, { char: "/", type: "command", items: [ { value: "triage", label: "triage" }, { value: "changelog", label: "changelog" }, ], },];
export function Example() { return ( // Inside TokenInput.Root, TriggerMenu automatically binds to the token // editor and inserts atomic tokens; standalone, render TriggerMenu.Input. <TokenInput.Root> <TokenInput.Editor placeholder="Type @ to mention or / for commands…" /> <TriggerMenu.Root triggers={triggers} size="md"> <TriggerMenu.Content> <TriggerMenu.Empty>No matches</TriggerMenu.Empty> <TriggerMenu.List> {(state) => (state.items as TriggerMenuDataItem<string>[]).map((item) => ( <TriggerMenu.Item key={item.value} value={item.value} label={item.label}> {state.trigger === "/" ? `/${item.label}` : item.label} </TriggerMenu.Item> )) } </TriggerMenu.List> </TriggerMenu.Content> </TriggerMenu.Root> </TokenInput.Root> );}Sizes
Ask Elena Park — type @ or /
Ask Elena Park — type @ or /
With standalone textarea
Render TriggerMenu.Input outside TokenInput to attach caret-anchored @ mention and / command menus to a plain textarea.
1234567<TriggerMenu.Root triggers={triggers}> <TriggerMenu.Input rows={3} placeholder="Type @ or /…" /> <TriggerMenu.Content> <TriggerMenu.Empty>No matches</TriggerMenu.Empty> <TriggerMenu.List /> </TriggerMenu.Content></TriggerMenu.Root>Install
1npx stylexblocks add trigger-menuSource
components/ui/ui-sdk/trigger-menu.tsx
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455import * as stylex from "@stylexjs/stylex";import { createTriggerMenuController, textFieldAdapter, TriggerMenu as UiSdkTriggerMenu, TriggerMenuContent, TriggerMenuEmpty, TriggerMenuGroup, TriggerMenuGroupLabel, TriggerMenuHint, TriggerMenuInput, TriggerMenuItem, TriggerMenuItemIcon, TriggerMenuItems, TriggerMenuList, TriggerMenuSeparator, TriggerMenuStatus, type EditorChange, type EditorReplaceOptions, type ListFilter, type ListItem, type ListSeparator, type TextEditorAdapter, type TextRange, type TextRect, type Token, type TokenInsert, type TriggerAfter, type TriggerArgument, type TriggerBoundary, type TriggerDefinition, type TriggerItemsLoader, type TriggerMatch, type TriggerMenuApi, type TriggerMenuChangeOptions, type TriggerMenuContentProps, type TriggerMenuContentState, type TriggerMenuController, type TriggerMenuData, type TriggerMenuDataGroup, type TriggerMenuDataItem, type TriggerMenuDismissReason, type TriggerMenuEmptyState, type TriggerMenuHintState, type TriggerMenuInputState, type TriggerMenuItemIconProps, type TriggerMenuItemIconState, type TriggerMenuItemProps, type TriggerMenuItemState, type TriggerMenuOpenChangeReason, type TriggerMenuOptions, type TriggerMenuPrimitive, type TriggerMenuProps, type TriggerMenuQueryChangeReason, type TriggerMenuSelectDetails, type TriggerMenuStatusState, type TriggerRule,} from "@ui-sdk/react/trigger-menu";import { createSlotRecipeContext } from "#lib/ui-sdk/create-slot-recipe-context.tsx";import { defineSlotRecipe, type SlotRecipeVariants, type StyleOverrideProps,} from "#lib/recipe-props.ts";import { colorPalette } from "@stylexblocks/ui/color-palette.stylex.ts";import { semanticColors } from "@stylexblocks/ui/semantic-tokens/colors.stylex.ts";import { semanticRadii } from "@stylexblocks/ui/semantic-tokens/radii.stylex.ts";import { semanticShadows } from "@stylexblocks/ui/semantic-tokens/shadows.stylex.ts";import { cursor } from "@stylexblocks/ui/tokens/cursor.stylex.ts";import { durations } from "@stylexblocks/ui/tokens/durations.stylex.ts";import { fontSizes } from "@stylexblocks/ui/tokens/font-sizes.stylex.ts";import { fontWeights } from "@stylexblocks/ui/tokens/font-weights.stylex.ts";import { fonts } from "@stylexblocks/ui/tokens/fonts.stylex.ts";import { letterSpacings } from "@stylexblocks/ui/tokens/letter-spacings.stylex.ts";import { lineHeights } from "@stylexblocks/ui/tokens/line-heights.stylex.ts";import { sizes } from "@stylexblocks/ui/tokens/sizes.stylex.ts";import { spacing } from "@stylexblocks/ui/tokens/spacing.stylex.ts";import { zIndices } from "@stylexblocks/ui/tokens/z-indices.stylex.ts";
const triggerMenuInput = stylex.create({ base: { appearance: "none", backgroundColor: semanticColors.bg, borderColor: { default: semanticColors.border, ":focus-visible": colorPalette.focusRing, }, borderRadius: semanticRadii.control, borderStyle: "solid", borderWidth: "1px", boxSizing: "border-box", color: semanticColors.fg, fontFamily: fonts.body, minWidth: 0, outlineColor: { default: "transparent", ":focus-visible": colorPalette.focusRing, }, outlineOffset: "0px", outlineStyle: { default: "none", ":focus-visible": "solid", }, outlineWidth: { default: "0px", ":focus-visible": "1px", }, resize: "vertical", textAlign: "start", transitionDuration: durations.moderate, transitionProperty: "border-color, box-shadow", width: sizes.full, },});
const triggerMenuInputSizes = stylex.create({ sm: { fontSize: fontSizes.xs, lineHeight: lineHeights.sm, paddingBlock: spacing._1_5, paddingInline: spacing._2_5, }, md: { fontSize: fontSizes.sm, lineHeight: lineHeights.md, paddingBlock: spacing._2, paddingInline: spacing._3, },});
const triggerMenuContent = stylex.create({ base: { animationDuration: { default: null, ":is([data-open])": durations.fast, ":is([data-closed])": durations.faster, }, animationName: { default: null, ":is([data-open])": "fade-in, slide-from-top", ":is([data-closed])": "fade-out", }, backgroundColor: semanticColors.bgPanel, borderRadius: semanticRadii.panel, borderStyle: "none", borderWidth: 0, boxShadow: semanticShadows.overlay, boxSizing: "border-box", color: semanticColors.fg, display: { default: null, ":popover-open": "flex", }, flexDirection: "column", fontFamily: fonts.body, gap: spacing._0_5, marginBlock: 0, marginInline: 0, maxHeight: "min(16rem, var(--available-height, 16rem))", minWidth: "13rem", outlineStyle: "none", overflowX: "hidden", overflowY: "auto", scrollbarWidth: "thin", transformOrigin: "var(--transform-origin)", zIndex: zIndices.dropdown, },});
const triggerMenuContentSizes = stylex.create({ sm: { paddingBlock: spacing._1, paddingInline: spacing._1, }, md: { paddingBlock: spacing._1_5, paddingInline: spacing._1_5, },});
const triggerMenuList = stylex.create({ base: { display: "flex", flexDirection: "column", gap: spacing._0_5, opacity: { default: null, ':is([aria-busy="true"])': 0.6, }, transitionDuration: durations.fast, transitionProperty: "opacity", },});
const triggerMenuItem = stylex.create({ base: { alignItems: "center", backgroundColor: { default: "transparent", ":is([data-highlighted])": semanticColors.bgSubtle, }, borderRadius: semanticRadii.control, boxSizing: "border-box", color: semanticColors.fg, cursor: { default: cursor.option, ":is([data-disabled])": cursor.disabled, }, display: "flex", flexGrow: 0, flexShrink: 0, fontFamily: fonts.body, justifyContent: "space-between", opacity: { default: null, ":is([data-disabled])": 0.5, }, outlineStyle: "none", position: "relative", textAlign: "start", userSelect: "none", width: sizes.full, },});
const triggerMenuItemSizes = stylex.create({ sm: { fontSize: fontSizes.xs, gap: spacing._1_5, lineHeight: lineHeights.xs, minHeight: sizes._6, paddingBlock: spacing._1, paddingInline: spacing._2, }, md: { fontSize: fontSizes.sm, gap: spacing._2, lineHeight: lineHeights.sm, minHeight: sizes._7, paddingBlock: spacing._1_5, paddingInline: spacing._2, },});
const triggerMenuItemIcon = stylex.create({ base: { alignItems: "center", color: semanticColors.fgMuted, display: "inline-flex", flexShrink: 0, height: sizes._4, justifyContent: "center", width: sizes._4, },});
const triggerMenuGroup = stylex.create({ base: { display: "flex", flexDirection: "column", gap: spacing._0_5, },});
const triggerMenuGroupLabel = stylex.create({ base: { alignItems: "center", color: semanticColors.fgSubtle, display: "flex", fontWeight: fontWeights.medium, letterSpacing: letterSpacings.wide, userSelect: "none", },});
const triggerMenuGroupLabelSizes = stylex.create({ sm: { fontSize: fontSizes._2xs, lineHeight: lineHeights._2xs, paddingBlock: spacing._1, paddingInline: spacing._2, }, md: { fontSize: fontSizes.xs, lineHeight: lineHeights.xs, paddingBlock: spacing._1, paddingInline: spacing._2, },});
const triggerMenuSeparator = stylex.create({ base: { backgroundColor: semanticColors.borderSubtle, height: "1px", marginBlock: spacing._1, marginInline: spacing._1, },});
const triggerMenuEmpty = stylex.create({ base: { color: semanticColors.fgMuted, display: { default: null, ":empty": "none", }, fontSize: fontSizes.xs, lineHeight: lineHeights.xs, paddingBlock: spacing._2, paddingInline: spacing._2_5, textAlign: "start", },});
const triggerMenuStatus = stylex.create({ base: { color: semanticColors.fgMuted, fontSize: fontSizes.xs, lineHeight: lineHeights.xs, paddingBlock: spacing._1, paddingInline: spacing._2, },});
const triggerMenuHint = stylex.create({ base: { color: semanticColors.fgSubtle, fontFamily: fonts.body, pointerEvents: "none", userSelect: "none", },});
const triggerMenuRecipe = defineSlotRecipe({ slots: { input: { styles: triggerMenuInput, sizes: triggerMenuInputSizes }, content: { styles: triggerMenuContent, sizes: triggerMenuContentSizes }, list: { styles: triggerMenuList }, item: { styles: triggerMenuItem, sizes: triggerMenuItemSizes }, itemIcon: { styles: triggerMenuItemIcon }, group: { styles: triggerMenuGroup }, groupLabel: { styles: triggerMenuGroupLabel, sizes: triggerMenuGroupLabelSizes }, separator: { styles: triggerMenuSeparator }, empty: { styles: triggerMenuEmpty }, status: { styles: triggerMenuStatus }, hint: { styles: triggerMenuHint }, }, defaultVariants: { size: "md" },});
const { withRootProvider, withContext } = createSlotRecipeContext(triggerMenuRecipe);
type TriggerMenuVariants = SlotRecipeVariants<typeof triggerMenuRecipe>;
export type TriggerMenuVariantProps = Partial<TriggerMenuVariants>;
const StyledRoot = withRootProvider( UiSdkTriggerMenu as React.ComponentType<TriggerMenuProps<unknown>>, "TriggerMenuRoot",);
function Root<T = string>(props: TriggerMenuProps<T> & Partial<TriggerMenuVariants>) { return <StyledRoot {...(props as React.ComponentProps<typeof StyledRoot>)} />;}Root.displayName = "TriggerMenuRoot";
const StyledContent = withContext(TriggerMenuContent, "content", "TriggerMenuContent");
function Content(props: React.ComponentProps<typeof StyledContent>) { const { sideOffset = 6, ...rest } = props; return <StyledContent sideOffset={sideOffset} {...rest} />;}Content.displayName = "TriggerMenuContent";
const StyledItem = withContext(TriggerMenuItem, "item", "TriggerMenuItem");
function Item<T = string>( props: Omit<React.ComponentProps<typeof TriggerMenuItem<T>>, "style"> & StyleOverrideProps,) { return <StyledItem {...(props as React.ComponentProps<typeof StyledItem>)} />;}Item.displayName = "TriggerMenuItem";
/** * TriggerMenu — UI SDK's caret-anchored suggestion menu wearing the StyleX * slot recipe. Opens in the browser's top layer when the user types a trigger * character such as `@` or `/`. Inside `TokenInput.Root`, omit `Input` so it * automatically binds to the token editor; standalone, render `TriggerMenu.Input` * (or pass an `editor` adapter). */export const TriggerMenu = { Root, Input: withContext(TriggerMenuInput, "input", "TriggerMenuInput"), Content, List: withContext(TriggerMenuList, "list", "TriggerMenuList"), Item, ItemIcon: withContext(TriggerMenuItemIcon, "itemIcon", "TriggerMenuItemIcon"), Group: withContext(TriggerMenuGroup, "group", "TriggerMenuGroup"), GroupLabel: withContext(TriggerMenuGroupLabel, "groupLabel", "TriggerMenuGroupLabel"), Separator: withContext(TriggerMenuSeparator, "separator", "TriggerMenuSeparator"), Empty: withContext(TriggerMenuEmpty, "empty", "TriggerMenuEmpty"), Status: withContext(TriggerMenuStatus, "status", "TriggerMenuStatus"), Hint: withContext(TriggerMenuHint, "hint", "TriggerMenuHint"), Items: TriggerMenuItems,};
export type TriggerMenuRootProps<T = string> = TriggerMenuProps<T> & Partial<TriggerMenuVariants>;
export { createTriggerMenuController, textFieldAdapter };
export type { EditorChange, EditorReplaceOptions, ListFilter, ListItem, ListSeparator, StyleOverrideProps, TextEditorAdapter, TextRange, TextRect, Token, TokenInsert, TriggerAfter, TriggerArgument, TriggerBoundary, TriggerDefinition, TriggerItemsLoader, TriggerMatch, TriggerMenuApi, TriggerMenuChangeOptions, TriggerMenuContentProps, TriggerMenuContentState, TriggerMenuController, TriggerMenuData, TriggerMenuDataGroup, TriggerMenuDataItem, TriggerMenuDismissReason, TriggerMenuEmptyState, TriggerMenuHintState, TriggerMenuInputState, TriggerMenuItemIconProps, TriggerMenuItemIconState, TriggerMenuItemProps, TriggerMenuItemState, TriggerMenuOpenChangeReason, TriggerMenuOptions, TriggerMenuPrimitive, TriggerMenuProps, TriggerMenuQueryChangeReason, TriggerMenuSelectDetails, TriggerMenuStatusState, TriggerRule,};
Examples
Installable blocks built with Trigger Menu — real use cases, delivered as source you own.
AI Chat Landing
Zero-state AI entry surface centered on a single composer with a collapsible attachment drawer, @ mention and / command typeahead, mode menus, and category-driven suggestion cards.