Preview Updated 2026-05-10

Mention

Multi-line text input that opens a candidate dropdown when the trigger character (default @) is typed; ↑↓ to select, Enter / Tab to confirm.

Basic usage

CfMention overlays trigger-character recognition on a <textarea>. When @ appears before the cursor followed by an optional search string (no spaces), the dropdown opens and filters options by case-insensitive substring on that text.

When an option is picked, @<value> is inserted at the cursor — replacing the segment from the trigger to the current cursor position only, leaving subsequent text untouched.

<script setup lang="ts">
import { ref } from 'vue';
import { CfMention } from '@chufix-design/vue';

const text = ref('');
const options = [
{ value: 'alice', label: 'Alice Zhang', description: 'Frontend · Design System' },
{ value: 'bob', label: 'Bob Li', description: 'Backend · API Gateway' },
{ value: 'carol', label: 'Carol Liu', description: 'Product' },
{ value: 'david', label: 'David Wang', description: 'QA' },
{ value: 'eve', label: 'Eve Zhou', description: 'Ops', disabled: true },
];
</script>

<template>
<CfMention v-model="text" :options="options" />
</template>
import { useState } from 'react';
import { CfMention } from '@chufix-design/react';

export default function Demo() {
const [text, setText] = useState('');
const options = [
  { value: 'alice', label: 'Alice Zhang', description: 'Frontend · Design System' },
  { value: 'bob', label: 'Bob Li', description: 'Backend · API Gateway' },
  // ...
];
return <CfMention value={text} onChange={setText} options={options} />;
}

Custom trigger character

trigger can be any single character. Pass # for tag selection, / for a command palette. Position and keyboard behavior are identical.

<CfMention
v-model="text"
trigger="#"
:options="tags"
placeholder="Type # to pick a tag"
/>
<CfMention
value={text}
onChange={setText}
trigger="#"
options={tags}
placeholder="Type # to pick a tag"
/>

Read-only / disabled

readonly keeps the display but blocks typing in the textarea; disabled grays it out and removes focus. The candidate dropdown will not appear in either mode.

readonly
disabled
<CfMention :model-value="sample" :options="options" readonly />
<CfMention :model-value="sample" :options="options" disabled />
<CfMention value={sample} options={options} readonly />
<CfMention value={sample} options={options} disabled />

Keyboard interaction

While the dropdown is open, the following keys are supported:

KeyBehavior
/ Move the highlight between candidates
Enter / TabSelect the highlighted candidate
EscClose the dropdown without inserting
Printable charsLive-filter candidates
SpaceAuto-closes the dropdown (treated as end of mention)

disabled items cannot be selected by keyboard and mouse clicks on them are ignored.

API

PropTypeDefaultDescription
modelValue (Vue) / value (React)string''Text content
defaultValuestring''Uncontrolled initial value
optionsMentionOption[]{ value, label?, description?, disabled? }
triggerstring'@'Trigger character (single character)
rowsnumber4Textarea rows
placeholderstring'Type @ to mention'Textarea placeholder
disabled / readonlybooleanfalseDisable / read-only the editor
size'sm' | 'md' | 'lg''md'Font size
classNamestringForwarded to the root container

Events:

  • onChange(value) / update:modelValue — any text change
  • onSelect(option) / select — fires when a candidate is selected

Type exports:

interface MentionOption {
  value: string;
  label?: string;
  description?: string;
  disabled?: boolean;
}

反馈与讨论

Mention · Discussion

0
0 / 600
一键发送
正在加载评论...