For AI agents: the complete documentation index is available at https://ifhover.github.io/leaf-ui/v/0.6.0/llms.txt, the full documentation bundle is available at https://ifhover.github.io/leaf-ui/v/0.6.0/llms-full.txt, and this page is available as Markdown at https://ifhover.github.io/leaf-ui/v/0.6.0/components/mentions.md.
  • 简体中文
  • Mentions 提及

    在文本中插入成员或内容引用。

    基础用法

    basic.tsx
    import { Mentions } from '@ifhover/leaf-ui';
    
    export function MentionsBasic() {
      return (
        <Mentions
          aria-label={'评论'}
          placeholder={'输入 @ 提及团队成员'}
          options={[
            { value: 'ada', label: 'Ada' },
            { value: 'lin', label: 'Lin' },
            { value: 'morgan', label: 'Morgan', disabled: true },
          ]}
        />
      );
    }
    

    不同的前缀

    basic.tsx
    import { Mentions } from '@ifhover/leaf-ui';
    
    export function MentionsPrefixes() {
      return (
        <Mentions
          prefixes={['@', '#']}
          aria-label={'项目备注'}
          placeholder={'使用 @ 或 # 插入引用'}
          options={[
            { value: 'design', label: '设计' },
            { value: 'engineering', label: '工程' },
          ]}
        />
      );
    }
    

    MentionOption

    属性类型默认值说明
    valuestring—必需。受控值。
    labelReactNode—展示文字或内容。
    searchLabelstring—搜索时使用的纯文本。
    disabledboolean—禁用交互。

    Mentions API

    属性类型默认值说明
    size'sm' | 'md' | 'lg'—展示尺寸。
    status'error' | 'warning'—设置 status。
    resize'none' | 'vertical' | 'both'—设置 resize。
    autoSizeboolean | TextareaAutoSize—设置 autoSize。
    showCountboolean | ((value: string, maxLength?: number) => ReactNode)—设置 showCount。
    popupPlacement'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'left' | 'left-start' | 'left-end' | 'right' | 'right-start' | 'right-end'—浮层相对触发控件的位置。
    popupClassNamestring—浮层的自定义类名。
    popupStyleCSSProperties—浮层的自定义样式。
    popupRender(content: React.ReactNode) => React.ReactNode—包装或补充面板内容,保留传入的内容以维持交互。
    getPopupContainer() => Element | DocumentFragment—返回浮层的挂载容器,也可返回 ShadowRoot。
    valuestring—受控值。
    defaultValuestring''初始值;非受控模式支持表单重置。
    onChange(value: string) => void—值发生变化时调用。
    onSearch(query: string, prefix: string) => void—搜索文字改变时调用。
    onSelect(option: MentionOption, prefix: string) => void—条目被选择时调用。
    optionsreadonly MentionOption[]—必需。可供选择的选项。
    prefixesreadonly string[]—可触发建议的文本前缀。
    splitstring' '插入引用后追加的分隔文字。
    loadingboolean—展示加载状态。
    notFoundContentReactNode—没有匹配选项时的内容。

    类型与交互

    组装可复用配置时,可导入对应的属性和数据类型。

    import type { MentionOption, MentionsProps } from '@ifhover/leaf-ui';

    为仅展示图标的操作提供可访问名称。交互控件支持键盘操作,并跟随 ConfigProvider 的主题和减少动画设置。