

<InteractiveDemo
  name="mention"
  controls="[
  {
    type: &#x22;string&#x22;,
    name: &#x22;label&#x22;,
    defaultValue: &#x22;Comment&#x22;,
  },
  {
    type: &#x22;string&#x22;,
    name: &#x22;placeholder&#x22;,
    defaultValue: &#x22;Type @ to mention someone...&#x22;,
  },
  {
    type: &#x22;string&#x22;,
    name: &#x22;description&#x22;,
    defaultValue: &#x22;&#x22;,
    placeholder: &#x22;Helper text&#x22;,
  },
  {
    type: &#x22;boolean&#x22;,
    name: &#x22;isDisabled&#x22;,
    defaultValue: false,
  },
  {
    type: &#x22;boolean&#x22;,
    name: &#x22;isReadOnly&#x22;,
    defaultValue: false,
  },
  {
    type: &#x22;enum&#x22;,
    name: &#x22;placement&#x22;,
    options: [&#x22;bottom start&#x22;, &#x22;bottom end&#x22;, &#x22;top start&#x22;, &#x22;top end&#x22;],
    defaultValue: &#x22;bottom start&#x22;,
  },
]"
/>

## Installation [#installation]

<InstallPrerequisite>
  Before adding components, init your project with your design system from the [Studio](/studio).
</InstallPrerequisite>

<CodeBlockTabs defaultValue="npm" groupId="package-manager">
  <CodeBlockTabsList>
    <CodeBlockTabsTrigger value="npm">
      npm
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="pnpm">
      pnpm
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="yarn">
      yarn
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="bun">
      bun
    </CodeBlockTabsTrigger>
  </CodeBlockTabsList>

  <CodeBlockTab value="npm">
    ```bash
    npx shadcn@latest add @dotui/mention
    ```
  </CodeBlockTab>

  <CodeBlockTab value="pnpm">
    ```bash
    pnpm dlx shadcn@latest add @dotui/mention
    ```
  </CodeBlockTab>

  <CodeBlockTab value="yarn">
    ```bash
    yarn dlx shadcn@latest add @dotui/mention
    ```
  </CodeBlockTab>

  <CodeBlockTab value="bun">
    ```bash
    bunx shadcn@latest add @dotui/mention
    ```
  </CodeBlockTab>
</CodeBlockTabs>

## Usage [#usage]

`Mention` wires a mention experience onto the [TokenField](/docs/components/token-field) component: compose a `TokenInput` for the editable area plus a `Popover` + `Menu` for the suggestions, and `Mention` injects the wiring (value, caret-anchored popover, filtering, keyboard navigation, insertion) through context. Typing the trigger character (`@` by default) opens the list at the caret and filters as you type; selecting an item inserts it as an inline token.

```tsx
import { Mention } from "@/components/ui/mention"
import { MenuContent, MenuItem } from "@/components/ui/menu"
import { Popover } from "@/components/ui/popover"
import { TokenInput } from "@/components/ui/token-field"
```

```tsx
<Mention allowsNewlines>
  <TokenInput aria-label="Comment" />
  <Popover>
    <MenuContent items={people}>
      {(person) => <MenuItem id={person.id}>{person.name}</MenuItem>}
    </MenuContent>
  </Popover>
</Mention>
```

Add a `Label` before the input when you want a visible label; otherwise give the input an `aria-label`. Without `allowsNewlines` the field stays single-line.

```tsx
<Mention allowsNewlines>
  <Label>Comment</Label>
  <TokenInput />
  <Popover>{/* ...suggestions */}</Popover>
</Mention>
```

## Anatomy [#anatomy]

```tsx
import { Mention } from "@/components/ui/mention"
import { MenuContent, MenuItem } from "@/components/ui/menu"
import { Popover } from "@/components/ui/popover"
import { TokenInput } from "@/components/ui/token-field"
```

```tsx
<Mention>
  <TokenInput />
  <Popover>
    <MenuContent>
      <MenuItem />
    </MenuContent>
  </Popover>
</Mention>
```

`Mention` owns the value and caret-anchored popover, the [TokenField](/docs/components/token-field)'s `TokenInput` renders the text and inline tokens, and the `Popover` + `MenuContent` render the suggestions. These are children, not props — there are no bespoke sub-components.

## Value [#value]

The value is a `TokenFieldValue` — a list of plain-text and token segments, imported from `react-aria-components`. Use `defaultValue` for uncontrolled state, or `value` with `onChange` to control it; `toString()` joins the segments back into plain text, and each token segment carries the inserted item's key as its `value`.

```tsx
import { TokenFieldValue } from "react-aria-components"

const [value, setValue] = React.useState(
  () =>
    new TokenFieldValue([
      { type: "text", text: "Hey " },
      { type: "token", text: "@alexmiller" },
    ]),
)

<Mention value={value} onChange={setValue}>
  {/* ... */}
</Mention>
```

## Triggers [#triggers]

The `trigger` prop changes the character that opens the list, and `getItemText` maps a selected item's key to the text inserted after the trigger.

```tsx
<Mention trigger="#" getItemText={(key) => String(key)}>
  {/* ... */}
</Mention>
```

Pass a regular expression to support several triggers at once. Children may be a function receiving the active trigger and query, so the suggestions can depend on which trigger the user typed.

```tsx
<Mention trigger={/[@/]/}>
  {({ trigger }) => (
    <>
      <TokenInput aria-label="Prompt" />
      <Popover>
        <MenuContent items={trigger === "/" ? commands : files}>
          {(item) => <MenuItem id={item.id}>{item.id}</MenuItem>}
        </MenuContent>
      </Popover>
    </>
  )}
</Mention>
```

## Placement [#placement]

Set `placement` to move the suggestions popover relative to the caret (default `"bottom start"`).

## Examples [#examples]

<Examples className="md:grid-cols-2">
  <Example name="mention/demos/basic" title="Basic" />

  <Example name="mention/demos/multiple-triggers" title="Multiple triggers" />

  <Example name="mention/demos/with-avatars" title="With avatars" />

  <Example name="mention/demos/with-input" title="Single-line" />

  <Example name="mention/demos/custom-trigger" title="Custom trigger" />

  <Example name="mention/demos/controlled" title="Controlled" />
</Examples>

## API Reference [#api-reference]

`Mention` composes the [TokenField](/docs/components/token-field)'s `TokenInput` for the editable area, and the [Popover](/docs/components/popover) and [Menu](/docs/components/menu) primitives for the suggestion list.

<Reference name="mention" />
