Ir al contenido
Español
Campo con menciones viene con Pro. La vista previa aparece al desbloquearlo.

Cómo funciona

There is no contenteditable. The textarea draws only the caret and selection; a mirror with the same box model sits behind it and draws the text, with each mention as an accent token. A hidden second mirror measures the caret so the list opens under the @, clamped inside the field. Text stays a plain string, easy to store and diff.

Úsalo para

  • Comments, replies and notes where people notify teammates by name.
  • Any message field that must keep native mobile keyboards, autocorrect and IME.

Busca otra opción cuando

  • Rich formatting (bold, links, images): use a rich-text editor.
  • Picking recipients only, without free text: use a tags input or multi-select.

Uso

import { useState } from 'react'
import { MentionInput } from './MentionInput.jsx'

const people = [
  { id: 'm', name: 'Mira Holt', role: 'Design lead' },
  { id: 'j', name: 'Jonas Reed', role: 'Illustrator' },
]

export function Reply() {
  const [text, setText] = useState('')
  return (
    <MentionInput
      aria-label="Reply"
      value={text}
      onChange={(next, mentioned) => setText(next)}
      people={people}
      placeholder="Type @ to mention someone"
    />
  )
}

Propiedades

PropiedadTipoPor defectoQué hace
people{ id?, name, role?, handle?, color? }[]—Who can be mentioned. A word of name or the handle is matched from its start.
valuestring—Controlled text. Mentions are stored as plain "@Name".
defaultValuestring''Initial text when uncontrolled.
onChange(text, mentioned: Person[]) => void—Called on every edit with the text and the people currently mentioned in it.
triggerstring'@'Character that starts a mention; it must follow a space or the start.
rowsnumber3Visible rows of the textarea.
maxLengthnumber—Character limit; shows a counter that turns amber past 90%.
renderPerson(person) => ReactNode—Replaces the default initial avatar in the list.
labelsobject—Replaces built-in text: people, noMatch, mentioned.
...restTextareaHTMLAttributes—Go to the textarea, including onKeyDown (called after list navigation) and aria-label. List layer: --ds-mention-z (30).

Accesibilidad

  • The textarea is a combobox (aria-autocomplete="list", aria-multiline) controlling a listbox; the highlighted person is announced through aria-activedescendant.
  • Keyboard: Down / Up move through people, Enter or Tab insert, Esc closes the list and keeps the text; Backspace after a token removes the whole name.
  • Each inserted mention is announced in a polite live region. The visible text is the real text, so screen readers read "@Name" naturally.
  • People rows are 44px. Reduced motion removes the list and token glow animations.

Movimiento

The list scales in from 0.96 and 4px above in 200ms ease-out. A new token starts with a stronger tint and a 4px glow that settle over 360ms. The field turns white with a halo in 220ms.

Añádelo a tu proyecto

Los miembros Pro copian un prompt y su agente de programación instala el código, igual que con los gratuitos.

MentionInput.jsxmention-input.csstokens.cssREADME.md

Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

Formularios
Cuadrícula de disponibilidad viene con Pro. La vista previa aparece al desbloquearlo.
Operaciones booleanas viene con Pro. La vista previa aparece al desbloquearlo.
Selector en cascada viene con Pro. La vista previa aparece al desbloquearlo.