Dice UI

Mention

A component that allows to mention items in a list by a trigger character.

API

Installation

pnpm add @diceui/mention

Installation with shadcn/ui

pnpm dlx shadcn@latest add @diceui/mention

Layout

Import the parts, and compose them together.

import {
  Mention,
  MentionLabel,
  MentionInput,
  MentionPortal,
  MentionContent,
  MentionItem,
} from "@diceui/mention";
 
return (
  <Mention>
    <MentionLabel />
    <MentionInput />
    <MentionPortal>
      <MentionContent>
        <MentionItem />
      </MentionContent>
    </MentionPortal>
  </Mention>
)

Examples

Custom Trigger

With Custom Filter

API Reference

Mention

The container for all mention parts. Mention tags can be styled using the data-tag attribute within the root.

Prop

Type

Data AttributeValue
[data-state]"open" | "closed"
[data-disabled]Present when disabled.

MentionLabel

An accessible label that describes the mention input. Associates with the input element for screen readers.

Prop

Type

MentionInput

The text input field that users can type into to trigger mentions.

Prop

Type

MentionPortal

A portal for rendering the mention content outside of its DOM hierarchy.

Prop

Type

MentionContent

The popover container for mention items. Positions the mention popover relative to the cursor position.

Prop

Type

Data AttributeValue
[data-state]"open" | "closed"
[data-side]"top" | "right" | "bottom" | "left"
[data-align]"start" | "center" | "end"
CSS VariableDescription
--dice-transform-originTransform origin for cursor positioning.
--dice-available-widthAvailable width in the viewport for the popover element.
--dice-available-heightAvailable height in the viewport for the popover element.

MentionItem

An interactive option in the mention list.

Prop

Type

Data AttributeValue
[data-highlighted]Present when the item is highlighted.
[data-disabled]Present when the item is disabled.
[data-value]The value of the item.

Accessibility

Keyboard Interactions

KeyDescription
EnterWhen open, selects the highlighted mention option.
ArrowUpWhen open, highlights the previous mention option.
ArrowDownWhen open, highlights the next mention option.
HomeWhen open, highlights the first mention option.
EndWhen open, highlights the last mention option.
EscapeCloses the mention popover and returns focus to the input.

On this page