---
title: "Combobox · UI SDK — StyleX Blocks"
description: "Filterable input with a suggestion popup, item indicators, and an empty state slot."
url: "https://stylexblocks.com/components/ui-sdk/combobox/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Combobox

Filterable input with a suggestion popup, item indicators, and an empty state slot.

- Behavior engine: UI SDK
- Also available for: [Ark UI](https://stylexblocks.com/components/ark-ui/combobox.md), [Base UI](https://stylexblocks.com/components/base-ui/combobox.md)
- Category: Form
- Variants: outline, subtle, flushed
- Sizes: xs, sm, md, lg
- Used in blocks: [Country Picker](https://stylexblocks.com/block/ui-sdk/country-picker.md), [Model Picker](https://stylexblocks.com/block/ui-sdk/model-picker.md), [Timezone Picker](https://stylexblocks.com/block/ui-sdk/timezone-picker.md)
- HTML page: https://stylexblocks.com/components/ui-sdk/combobox/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init --style ui-sdk
```

Then add the item as source you own:

```sh
npx stylexblocks add combobox
```

Equivalent: `npx shadcn add @stylexblocks/combobox`. Registry item JSON: https://stylexblocks.com/r/ui-sdk/combobox.json

## Usage

```tsx
import { Combobox } from "#components/ui/ui-sdk/combobox.tsx";

const cities = ["Amsterdam", "Berlin", "Lisbon", "Oslo", "Porto"];

export function Example() {
  return (
    // variant/size resolve once on Root; every part inherits them via
    // context — IndicatorGroup and ItemIndicator ship default icons.
    // Typing filters the rendered items by their text: no collection needed
    <Combobox.Root defaultValue="Amsterdam" variant="outline" size="md">
      <Combobox.Label>City</Combobox.Label>
      <Combobox.Control>
        <Combobox.Input placeholder="Search cities" />
        <Combobox.IndicatorGroup />
      </Combobox.Control>
      {/* Content opens in the browser's top layer, anchored to the input:
          no Portal or Positioner needed */}
      <Combobox.Content>
        <Combobox.Empty>No matches</Combobox.Empty>
        <Combobox.List>
          {cities.map((city) => (
            <Combobox.Item key={city} value={city}>
              <Combobox.ItemText>{city}</Combobox.ItemText>
              <Combobox.ItemIndicator />
            </Combobox.Item>
          ))}
        </Combobox.List>
      </Combobox.Content>
    </Combobox.Root>
  );
}

// controlled: <Combobox.Root value={city} onValueChange={(value) => setCity(value)}>
// several: <Combobox.Root multiple defaultValue={["Oslo"]}>
// match highlighting: <Combobox.ItemText /> (no children) marks the typed text
```

## Source

`components/ui/ui-sdk/combobox.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import { createContext, useContext, useMemo, useState } from "react";
import {
  Combobox as UiSdkCombobox,
  ComboboxClear,
  ComboboxContent,
  ComboboxEmpty,
  ComboboxGroup,
  ComboboxGroupLabel,
  ComboboxInput,
  ComboboxItem,
  ComboboxItemIndicator,
  ComboboxItemText,
  type ComboboxItemTextState,
  ComboboxLabel,
  ComboboxList,
  ComboboxTrigger,
  ComboboxValue,
  createComboboxController,
  type ComboboxController,
  type ComboboxProps,
  type ComboboxTriggerState,
  type ComboboxValueState,
} from "@ui-sdk/react/combobox";
import { mergeProps } from "@ui-sdk/react/primitive";
import { createSlotRecipeContext } from "#lib/ui-sdk/create-slot-recipe-context.tsx";
import {
  defineSlotRecipe,
  resolveSlotStyles,
  type SlotRecipeVariants,
  type StyleOverrideProps,
  type WithStyleOverrides,
} from "#lib/recipe-props.ts";
import { semanticShadows } from "@stylexblocks/ui/semantic-tokens/shadows.stylex.ts";
import {
  comboboxIndicatorGroupIconVars,
  comboboxItemIconVars,
} from '@stylexblocks/ui/slot-recipes/combobox.stylex.ts'

import { colorPalette } from '@stylexblocks/ui/color-palette.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 { lineHeights } from '@stylexblocks/ui/tokens/line-heights.stylex.ts'
import { radii } from '@stylexblocks/ui/tokens/radii.stylex.ts'
import { semanticColors } from '@stylexblocks/ui/semantic-tokens/colors.stylex.ts'
import { semanticRadii } from '@stylexblocks/ui/semantic-tokens/radii.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 comboboxRoot = stylex.create({
  base: {
    display: 'flex',
    flexDirection: 'column',
    gap: spacing._1_5,
    width: sizes.full,
  },
})

const comboboxRootSizes = stylex.create({
  xs: {
    '--combobox-input-height': sizes.controlXs,
    '--combobox-input-padding-x': spacing._2,
    '--combobox-indicator-size': sizes._3_5,
  },
  sm: {
    '--combobox-input-height': sizes.controlSm,
    '--combobox-input-padding-x': spacing._2_5,
    '--combobox-indicator-size': sizes._4,
  },
  md: {
    '--combobox-input-height': sizes.controlMd,
    '--combobox-input-padding-x': spacing._3,
    '--combobox-indicator-size': sizes._4,
  },
  lg: {
    '--combobox-input-height': sizes.controlLg,
    '--combobox-input-padding-x': spacing._4,
    '--combobox-indicator-size': sizes._5,
  },
})

const comboboxLabel = stylex.create({
  base: {
    fontWeight: fontWeights.medium,
    userSelect: 'none',
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
    opacity: {
      default: null,
      ':is(:disabled, [disabled], [data-disabled])': 0.5,
    },
    cursor: {
      default: null,
      ':is(:disabled, [disabled], [data-disabled])': 'not-allowed',
    },
  },
})

const comboboxInput = stylex.create({
  base: {
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'space-between',
    width: sizes.full,
    minHeight: 'var(--combobox-input-height)',
    paddingInline: 'var(--combobox-input-padding-x)',
    '--input-height': 'var(--combobox-input-height)',
    borderRadius: semanticRadii.control,
    outline: 'none',
    userSelect: 'none',
    textAlign: 'start',
    opacity: {
      default: null,
      ':is(:disabled, [disabled], [data-disabled])': 0.5,
    },
    cursor: {
      default: null,
      ':is(:disabled, [disabled], [data-disabled])': 'not-allowed',
    },
    '--focus-color': colorPalette.focusRing,
    '--error-color': semanticColors.borderError,
    '--focus-ring-color': {
      default: null,
      ':is([data-invalid], [aria-invalid="true"])': 'var(--error-color)',
    },
    borderColor: {
      default: null,
      ':is([data-invalid], [aria-invalid="true"])': 'var(--error-color)',
    },
  },
})

const comboboxInputSizes = stylex.create({
  xs: {
    fontSize: fontSizes.xs,
    lineHeight: lineHeights.xs,
  },
  sm: {
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
  },
  md: {
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
  },
  lg: {
    fontSize: fontSizes.md,
    lineHeight: lineHeights.md,
  },
})

const comboboxInputVariants = stylex.create({
  outline: {
    backgroundColor: semanticColors.bg,
    borderWidth: '1px',
    borderColor: {
      default: semanticColors.border,
      ':is([data-invalid], [aria-invalid="true"])': 'var(--error-color)',
    },
    outlineWidth: {
      default: null,
      ':focus-visible': 'var(--focus-ring-width, 0)',
    },
    outlineOffset: {
      default: null,
      ':focus-visible': '0px',
    },
    outlineStyle: {
      default: null,
      ':focus-visible': 'solid',
    },
    outlineColor: {
      default: null,
      ':focus-visible': colorPalette.focusRing,
    },
  },
  subtle: {
    borderWidth: '1px',
    borderColor: {
      default: 'transparent',
      ':is([data-invalid], [aria-invalid="true"])': 'var(--error-color)',
    },
    backgroundColor: semanticColors.bgMuted,
    outlineWidth: {
      default: null,
      ':focus-visible': 'var(--focus-ring-width, 0)',
    },
    outlineOffset: {
      default: null,
      ':focus-visible': '0px',
    },
    outlineStyle: {
      default: null,
      ':focus-visible': 'solid',
    },
    outlineColor: {
      default: null,
      ':focus-visible': colorPalette.focusRing,
    },
  },
  flushed: {
    backgroundColor: 'transparent',
    borderBottomWidth: '1px',
    borderBottomColor: semanticColors.border,
    borderRadius: 0,
    paddingInline: 0,
    borderColor: {
      default: null,
      ':is([data-invalid], [aria-invalid="true"])': 'var(--error-color)',
      ':focus-visible': 'var(--focus-color)',
    },
    boxShadow: {
      default: null,
      ':focus-visible': '0px 1px 0px 0px var(--focus-color)',
    },
  },
})

const comboboxTrigger = stylex.create({
  base: {
    display: 'inline-flex',
    alignItems: 'center',
    justifyContent: 'center',
    pointerEvents: 'auto',
    '--input-height': 'var(--combobox-input-height)',
  },
})

const comboboxTriggerSizes = stylex.create({
  xs: {
    fontSize: fontSizes.xs,
    lineHeight: lineHeights.xs,
    gap: spacing._1,
  },
  sm: {
    fontSize: fontSizes.xs,
    lineHeight: lineHeights.xs,
    gap: spacing._1,
  },
  md: {
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
    gap: spacing._2,
  },
  lg: {
    fontSize: fontSizes.md,
    lineHeight: lineHeights.md,
    paddingBlock: spacing._3,
    gap: spacing._2,
  },
})

const comboboxClearTrigger = stylex.create({
  base: {
    color: semanticColors.fgMuted,
    pointerEvents: 'auto',
    outlineWidth: {
      default: null,
      ':focus-visible': 'var(--focus-ring-width, 0)',
    },
    outlineOffset: {
      default: null,
      ':focus-visible': '0px',
    },
    outlineStyle: {
      default: null,
      ':focus-visible': 'solid',
    },
    outlineColor: {
      default: null,
      ':focus-visible': colorPalette.focusRing,
    },
    focusRingWidth: '2px',
    borderRadius: semanticRadii.control,
  },
})

const comboboxControl = stylex.create({
  base: {
    position: 'relative',
  },
})

const comboboxIndicatorGroup = stylex.create({
  base: {
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center',
    gap: spacing._1,
    position: 'absolute',
    insetInlineEnd: 0,
    top: 0,
    bottom: 0,
    pointerEvents: 'none',
    paddingInline: 'var(--combobox-input-padding-x)',
    [comboboxIndicatorGroupIconVars.width]: 'var(--combobox-indicator-size)',
    [comboboxIndicatorGroupIconVars.height]: 'var(--combobox-indicator-size)',
  },
})

const comboboxIndicatorGroupVariants = stylex.create({
  flushed: {
    paddingInline: 0,
  },
})

const comboboxIndicatorGroupIcon = stylex.create({
  base: {
    width: comboboxIndicatorGroupIconVars.width,
    height: comboboxIndicatorGroupIconVars.height,
  },
})

const comboboxContent = stylex.create({
  base: {
    display: 'flex',
    flexDirection: 'column',
    '--menu-z-index': zIndices.layer3,
    zIndex: 'calc(var(--menu-z-index) + var(--layer-index, 0))',
    outline: 'none',
    maxHeight: 'var(--available-height)',
    overflowY: 'auto',
    animationName: {
      default: null,
      ':is([data-open], [data-state="open"])': 'fade-in, slide-from-top',
      ':is([data-closed], [data-state="closed"])': 'fade-out',
    },
    animationDuration: {
      default: null,
      ':is([data-open], [data-state="open"])': durations.fast,
      ':is([data-closed], [data-state="closed"])': durations.faster,
    },
  },
})

const comboboxContentSizes = stylex.create({
  xs: {
    '--combobox-item-padding-x': spacing._1,
    '--combobox-item-padding-y': spacing._0_5,
    '--combobox-indicator-size': sizes._3_5,
    borderRadius: semanticRadii.panel,
    padding: spacing._0_5,
    fontSize: fontSizes.xs,
    lineHeight: lineHeights.xs,
  },
  sm: {
    '--combobox-item-padding-x': spacing._1_5,
    '--combobox-item-padding-y': spacing._1,
    '--combobox-indicator-size': sizes._4,
    borderRadius: semanticRadii.panel,
    padding: spacing._1,
    fontSize: fontSizes.xs,
    lineHeight: lineHeights.xs,
  },
  md: {
    '--combobox-item-padding-x': spacing._2,
    '--combobox-item-padding-y': spacing._1_5,
    '--combobox-indicator-size': sizes._4,
    borderRadius: semanticRadii.panel,
    padding: spacing._1,
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
  },
  lg: {
    '--combobox-item-padding-y': spacing._2,
    '--combobox-item-padding-x': spacing._3,
    '--combobox-indicator-size': sizes._5,
    borderRadius: semanticRadii.panel,
    padding: spacing._1,
    fontSize: fontSizes.md,
    lineHeight: lineHeights.md,
  },
})

const comboboxItem = stylex.create({
  base: {
    position: 'relative',
    userSelect: 'none',
    display: 'flex',
    alignItems: 'center',
    gap: spacing._2,
    paddingBlock: 'var(--combobox-item-padding-y)',
    paddingInline: 'var(--combobox-item-padding-x)',
    cursor: cursor.option,
    justifyContent: 'space-between',
    flex: 1,
    textAlign: 'start',
    borderRadius: semanticRadii.control,
    pointerEvents: {
      default: null,
      ':is(:disabled, [disabled], [data-disabled])': 'none',
    },
    opacity: {
      default: null,
      ':is(:disabled, [disabled], [data-disabled])': 0.5,
    },
    [comboboxItemIconVars.width]: 'var(--combobox-indicator-size)',
    [comboboxItemIconVars.height]: 'var(--combobox-indicator-size)',
  },
})

const comboboxItemSizes = stylex.create({
  xs: {
    borderRadius: `max(0px, calc(${semanticRadii.panel} - ${sizes._0_5}))`,
  },
  sm: {
    borderRadius: `max(0px, calc(${semanticRadii.panel} - ${sizes._0_5}))`,
  },
  md: {
    borderRadius: `max(0px, calc(${semanticRadii.panel} - ${sizes._1}))`,
  },
  lg: {
    borderRadius: `max(0px, calc(${semanticRadii.panel} - ${sizes._1}))`,
  },
})

const comboboxItemIcon = stylex.create({
  base: {
    width: comboboxItemIconVars.width,
    height: comboboxItemIconVars.height,
  },
})

const comboboxEmpty = stylex.create({
  base: {
    paddingBlock: 'var(--combobox-item-padding-y)',
    paddingInline: 'var(--combobox-item-padding-x)',
  },
})

const comboboxItemText = stylex.create({
  base: {
    flex: 1,
  },
})

const comboboxItemGroup = stylex.create({
  base: {
    paddingBottom: {
      default: 'var(--combobox-item-padding-y)',
      ':last-child': 0,
    },
  },
})

const comboboxItemGroupLabel = stylex.create({
  base: {
    fontWeight: fontWeights.medium,
    paddingBlock: 'var(--combobox-item-padding-y)',
    paddingInline: 'var(--combobox-item-padding-x)',
  },
})

const comboboxItemIndicator = stylex.create({
  base: {},
})

const comboboxItemIndicatorSizes = stylex.create({
  md: {
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center',
  },
})

export type ComboboxVariant = keyof typeof comboboxInputVariants

export type ComboboxSize = keyof typeof comboboxRootSizes

const comboboxRecipe = defineSlotRecipe({
  slots: {
    root: { styles: comboboxRoot, sizes: comboboxRootSizes },
    label: { styles: comboboxLabel },
    input: {
      styles: comboboxInput,
      sizes: comboboxInputSizes,
      variants: comboboxInputVariants,
    },
    trigger: { styles: comboboxTrigger, sizes: comboboxTriggerSizes },
    clearTrigger: { styles: comboboxClearTrigger },
    control: { styles: comboboxControl },
    indicatorGroup: {
      styles: comboboxIndicatorGroup,
      variants: comboboxIndicatorGroupVariants,
    },
    content: { styles: comboboxContent, sizes: comboboxContentSizes },
    item: { styles: comboboxItem, sizes: comboboxItemSizes },
    empty: { styles: comboboxEmpty },
    itemText: { styles: comboboxItemText },
    itemGroup: { styles: comboboxItemGroup },
    itemGroupLabel: { styles: comboboxItemGroupLabel },
    itemIndicator: { styles: comboboxItemIndicator, sizes: comboboxItemIndicatorSizes },
  },
  defaultVariants: { size: "md", variant: "outline" },
});

// chrome the generated recipe leaves to the composition layer: unstyled
// trigger buttons, popup panel surface, and item hover feedback. UI SDK's
// Content is a top-layer popover that keeps the browser's own popover
// border, so the panel clears it and only lays out while open;
// `--anchor-width` matches the input.
const chrome = stylex.create({
  btnReset: {
    appearance: "none",
    backgroundColor: "transparent",
    borderWidth: 0,
    borderStyle: "none",
    padding: 0,
    margin: 0,
    fontFamily: "inherit",
    fontSize: "inherit",
    color: "inherit",
    cursor: "pointer",
    textAlign: "inherit",
  },
  anchor: { position: "relative" },
  panel: {
    display: {
      default: null,
      ":popover-open": "flex",
    },
    borderWidth: 0,
    borderStyle: "none",
    color: "inherit",
    backgroundColor: semanticColors.bgPanel,
    boxShadow: semanticShadows.overlay,
    minWidth: "var(--anchor-width)",
  },
  // UI SDK sets `data-highlighted` for pointer hover and keyboard moves alike
  itemHover: {
    backgroundColor: {
      default: null,
      ":hover": semanticColors.bgMuted,
      "[data-highlighted]": semanticColors.bgMuted,
    },
    outline: "none",
  },
  // Empty renders only while nothing matches
  empty: {
    display: {
      default: null,
      ":empty": "none",
    },
  },
});

const panelLocal = stylex.create({
  fieldTrigger: {
    // the variant recipes set border width/color but rely on the UA border
    // style of a native input; a reset button needs it explicit
    borderStyle: "solid",
    cursor: "pointer",
    textAlign: "start",
    display: "flex",
    alignItems: "center",
    justifyContent: "space-between",
    gap: "0.5rem",
  },
  fieldValue: {
    alignItems: "center",
    display: "inline-flex",
    minWidth: 0,
  },
  fieldPlaceholder: {
    color: semanticColors.fgSubtle,
  },
  panel: {
    flexDirection: "column",
    overflow: "hidden",
    padding: 0,
  },
  search: {
    borderBlockEndColor: semanticColors.border,
    borderBlockEndStyle: "solid",
    borderBlockEndWidth: "1px",
    borderRadius: 0,
    flexShrink: 0,
  },
  searchInput: {
    backgroundColor: "transparent",
    borderRadius: 0,
    borderStyle: "none",
    color: "inherit",
    minHeight: "unset",
    outlineStyle: "none",
    paddingBlock: "var(--combobox-item-padding-y)",
    paddingInline: "var(--combobox-item-padding-x)",
    width: "100%",
  },
  panelList: {
    borderRadius: 0,
    flexGrow: 1,
    overflowY: "auto",
  },
});

function ChevronDownIcon(props: React.ComponentProps<"svg">) {
  return (
    <svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true" {...props}>
      <path d="m4 6 4 4 4-4" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
    </svg>
  );
}

function CheckIcon(props: React.ComponentProps<"svg">) {
  return (
    <svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true" {...props}>
      <path d="m3.5 8.5 3 3 6-7" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
    </svg>
  );
}

const { withProvider, withContext, VariantContext } =
  createSlotRecipeContext(comboboxRecipe);

type ComboboxVariants = SlotRecipeVariants<typeof comboboxRecipe>;

/** Variant props for components built on Combobox (e.g. the picker blocks). */
export type ComboboxVariantProps = Partial<ComboboxVariants>;

// The input-inside-popup layout: FieldTrigger registers itself here so the
// Panel anchors to it, the query resets on every open, and focus returns
// to it on close (UI SDK leaves that wiring to the composition).
interface PanelLayout {
  fieldTrigger: HTMLButtonElement | null;
  setFieldTrigger: (node: HTMLButtonElement | null) => void;
}

const PanelLayoutContext = createContext<PanelLayout>({
  fieldTrigger: null,
  setFieldTrigger: () => {},
});

type RootNodeProps = ComboboxProps<unknown, boolean | undefined> & {
  className?: string;
  style?: React.CSSProperties;
};

function ComboboxRootNode(props: RootNodeProps) {
  const {
    className,
    style,
    children,
    controller,
    onOpenChange,
    onOpenChangeComplete,
    ...rest
  } = props;
  const [ownController] = useState(() => createComboboxController());
  const api = (controller ?? ownController) as ComboboxController<unknown, boolean>;
  const [fieldTrigger, setFieldTrigger] = useState<HTMLButtonElement | null>(null);
  const layout = useMemo(() => ({ fieldTrigger, setFieldTrigger }), [fieldTrigger]);
  return (
    <div className={className} style={style}>
      <PanelLayoutContext.Provider value={layout}>
        <UiSdkCombobox
          {...(rest as ComboboxProps<unknown>)}
          controller={api as never}
          onOpenChange={(open, details) => {
            onOpenChange?.(open, details);
            if (open && fieldTrigger) api.setQuery("");
          }}
          onOpenChangeComplete={(open) => {
            onOpenChangeComplete?.(open);
            if (!open && fieldTrigger) fieldTrigger.focus();
          }}
        >
          {children}
        </UiSdkCombobox>
      </PanelLayoutContext.Provider>
    </div>
  );
}

const StyledRoot = withProvider(ComboboxRootNode, "root", "ComboboxRoot");

/**
 * Combobox — UI SDK's combobox parts wearing the generated slot recipe.
 * `<Combobox.Root variant size>` renders the recipe's root layout element
 * around UI SDK's context-only Combobox; every part inherits the variants
 * through context. Typing filters the rendered Items by their text (or
 * `label` / `keywords`), so no collection or filter hook is needed. Content
 * opens in the browser's top layer anchored to the input: there is no
 * Portal or Positioner part. IndicatorGroup and ItemIndicator ship default
 * chevron / check icons.
 */
function Root<Value = string, Multiple extends boolean | undefined = false>(
  props: ComboboxProps<Value, Multiple> &
    Partial<ComboboxVariants> &
    StyleOverrideProps & { className?: string },
) {
  return <StyledRoot {...(props as React.ComponentProps<typeof StyledRoot>)} />;
}
Root.displayName = "ComboboxRoot";

const StyledIndicatorGroup = withContext("div", "indicatorGroup", "ComboboxIndicatorGroup");

function IndicatorGroup(props: React.ComponentProps<typeof StyledIndicatorGroup>) {
  const { children, ...rest } = props;
  return (
    <StyledIndicatorGroup {...rest}>
      {children ?? <ChevronDownIcon {...stylex.props(comboboxIndicatorGroupIcon.base)} />}
    </StyledIndicatorGroup>
  );
}
IndicatorGroup.displayName = "ComboboxIndicatorGroup";

const StyledItemIndicator = withContext(
  ComboboxItemIndicator,
  (v) => [
    ...resolveSlotStyles(comboboxRecipe.slots.itemIndicator, v),
    comboboxItemIndicatorSizes.md,
  ],
  "ComboboxItemIndicator",
);

function ItemIndicator(props: React.ComponentProps<typeof StyledItemIndicator>) {
  const { children, ...rest } = props;
  return (
    <StyledItemIndicator {...rest}>
      {children ?? <CheckIcon {...stylex.props(comboboxItemIcon.base)} />}
    </StyledItemIndicator>
  );
}
ItemIndicator.displayName = "ComboboxItemIndicator";

const StyledIcon = withContext("span", () => [], "ComboboxIcon");

/**
 * Icon — trigger chevron for the input-inside-popup pattern, where the
 * trigger (not the input) is the visible form control. Ships the default
 * chevron; pass children to replace it.
 */
function Icon(props: React.ComponentProps<typeof StyledIcon>) {
  const { children, ...rest } = props;
  return (
    <StyledIcon aria-hidden="true" {...rest}>
      {children ?? <ChevronDownIcon {...stylex.props(comboboxIndicatorGroupIcon.base)} />}
    </StyledIcon>
  );
}
Icon.displayName = "ComboboxIcon";

const StyledContent = withContext(
  ComboboxContent,
  (v) => [...resolveSlotStyles(comboboxRecipe.slots.content, v), chrome.panel],
  "ComboboxContent",
);

function Content(props: React.ComponentProps<typeof StyledContent>) {
  return <StyledContent sideOffset={4} {...props} />;
}
Content.displayName = "ComboboxContent";

const StyledItem = withContext(
  ComboboxItem,
  (v) => [...resolveSlotStyles(comboboxRecipe.slots.item, v), chrome.itemHover],
  "ComboboxItem",
);

function Item<Value = string>(
  props: Omit<React.ComponentProps<typeof ComboboxItem<Value>>, "style"> & StyleOverrideProps,
) {
  return <StyledItem {...(props as React.ComponentProps<typeof StyledItem>)} />;
}
Item.displayName = "ComboboxItem";

const StyledFieldTrigger = withContext(
  ComboboxTrigger,
  (v) => [
    chrome.btnReset,
    ...resolveSlotStyles(comboboxRecipe.slots.input, v),
    panelLocal.fieldTrigger,
  ],
  "ComboboxFieldTrigger",
);

/**
 * FieldTrigger — the select-look trigger for the popup layout: wears the
 * input recipe as a button and ships the default chevron. Pair with
 * `Combobox.FieldValue` for the selected label, and `Combobox.Panel` +
 * `Combobox.Search` for the popup; the Panel anchors to it, the search
 * query resets on each open, and focus returns to it on close.
 */
function FieldTrigger(props: React.ComponentProps<typeof StyledFieldTrigger>) {
  const { children, ...rest } = props;
  const { setFieldTrigger } = useContext(PanelLayoutContext);
  return (
    <StyledFieldTrigger ref={setFieldTrigger} {...rest}>
      {(state: ComboboxTriggerState) => (
        <>
          {typeof children === "function" ? children(state) : children}
          <ChevronDownIcon {...stylex.props(comboboxIndicatorGroupIcon.base)} />
        </>
      )}
    </StyledFieldTrigger>
  );
}
FieldTrigger.displayName = "ComboboxFieldTrigger";

const FieldValueBox = withContext("span", () => [panelLocal.fieldValue], "ComboboxFieldValueBox");

/**
 * FieldValue — the trigger's value slot: wraps `Combobox.Value` with the
 * selection layout (icon + label compositions stay on one line) and falls
 * back to a muted `placeholder` while nothing is selected. Children are a
 * node, or a function receiving the selected value (return null for the
 * placeholder); without children it shows the selected item's label.
 */
function FieldValue(
  props: StyleOverrideProps & {
    className?: string;
    placeholder?: React.ReactNode;
    children?: React.ReactNode | ((value: unknown) => React.ReactNode);
  },
) {
  const { placeholder, children, palette, style, className } = props;
  const fallback = <span {...stylex.props(panelLocal.fieldPlaceholder)}>{placeholder}</span>;
  return (
    <FieldValueBox palette={palette} style={style} className={className}>
      <ComboboxValue>
        {(state: ComboboxValueState) => {
          const empty =
            state.value == null || (Array.isArray(state.value) && state.value.length === 0);
          if (empty) return fallback;
          if (typeof children === "function") return children(state.value) ?? fallback;
          return children ?? (state.label || fallback);
        }}
      </ComboboxValue>
    </FieldValueBox>
  );
}
FieldValue.displayName = "ComboboxFieldValue";

const StyledPanel = withContext(
  ComboboxContent,
  (v) => [
    ...resolveSlotStyles(comboboxRecipe.slots.content, v),
    chrome.panel,
    panelLocal.panel,
  ],
  "ComboboxPanel",
);

/** Panel — the popup for the input-inside-popup layout, anchored to FieldTrigger. */
function Panel(props: React.ComponentProps<typeof StyledPanel>) {
  const { fieldTrigger } = useContext(PanelLayoutContext);
  return <StyledPanel sideOffset={4} anchor={fieldTrigger} {...props} />;
}
Panel.displayName = "ComboboxPanel";

/**
 * Search — the popup's input row. The row mirrors the content recipe's
 * padding and the input adopts the item metrics, so the input's text column
 * lines up exactly with the item text below it. Focused when the Panel opens.
 */
function Search(
  props: WithStyleOverrides<React.ComponentProps<typeof ComboboxInput>> & {
    className?: string;
  },
) {
  const { palette, style, className, ...rest } = props;
  const v = useContext(VariantContext);
  return (
    <div {...stylex.props(comboboxContentSizes[v.size], panelLocal.search, style)}>
      <ComboboxInput
        autoFocus
        {...mergeProps(rest, stylex.props(palette, panelLocal.searchInput), { className })}
      />
    </div>
  );
}
Search.displayName = "ComboboxSearch";

// typed-text matches are marked by UI SDK with a <mark>; draw them as
// emphasis instead of the browser's yellow highlighter
const matchMark = stylex.create({
  base: { backgroundColor: "transparent", color: "inherit", fontWeight: 600 },
});

const StyledItemText = withContext(ComboboxItemText, "itemText", "ComboboxItemText");

/**
 * ItemText — the item's label with the typed text marked. Plain-text
 * children (or none: the item's label) are marked; other children render
 * as given.
 */
function ItemText(props: React.ComponentProps<typeof StyledItemText>) {
  const { children, ...rest } = props;
  if (children != null && typeof children !== "string") {
    return <StyledItemText {...rest}>{children}</StyledItemText>;
  }
  return (
    <StyledItemText {...rest}>
      {(state: ComboboxItemTextState) =>
        state.segments.map((segment, i) =>
          segment.match ? (
            <mark key={i} {...stylex.props(matchMark.base)}>
              {segment.text}
            </mark>
          ) : (
            segment.text
          ),
        )
      }
    </StyledItemText>
  );
}
ItemText.displayName = "ComboboxItemText";

export const Combobox = {
  Root,
  Label: withContext(ComboboxLabel, "label", "ComboboxLabel"),
  Control: withContext(
    "div",
    (v) => [...resolveSlotStyles(comboboxRecipe.slots.control, v), chrome.anchor],
    "ComboboxControl",
  ),
  Input: withContext(ComboboxInput, "input", "ComboboxInput"),
  Trigger: withContext(
    ComboboxTrigger,
    (v) => [chrome.btnReset, ...resolveSlotStyles(comboboxRecipe.slots.trigger, v)],
    "ComboboxTrigger",
  ),
  Clear: withContext(
    ComboboxClear,
    (v) => [chrome.btnReset, ...resolveSlotStyles(comboboxRecipe.slots.clearTrigger, v)],
    "ComboboxClear",
  ),
  IndicatorGroup,
  // the selected label (or a function of the value state), e.g. on a trigger
  Value: ComboboxValue,
  Icon,
  Content,
  List: ComboboxList,
  Item,
  ItemText,
  ItemIndicator,
  Empty: withContext(
    ComboboxEmpty,
    (v) => [...resolveSlotStyles(comboboxRecipe.slots.empty, v), chrome.empty],
    "ComboboxEmpty",
  ),
  Group: withContext(ComboboxGroup, "itemGroup", "ComboboxGroup"),
  GroupLabel: withContext(ComboboxGroupLabel, "itemGroupLabel", "ComboboxGroupLabel"),
  // input-inside-popup layout
  FieldTrigger,
  FieldValue,
  Panel,
  Search,
  PanelList: withContext(
    "div",
    (v) => [comboboxContentSizes[v.size], panelLocal.panelList],
    "ComboboxPanelList",
  ),
};

export { createComboboxController };
```
