hydroxy

Mention input

A text field where @ lists people and / lists commands, filtered as you type. A picked row becomes a mention that carries an id and is deleted as one piece.

76 characters@Bo Chen → u_bo at 41..49

Usage

use hydroxy_leptos::mention_input::{Mention, MentionInput, MentionItem, MentionSource, MentionValue};
use leptos::prelude::*;

fn sources() -> Vec<MentionSource> {
    let people = vec![
        MentionItem::new("u_ana", "Ana Lima").description("Design lead"),
        MentionItem::new("u_bo", "Bo Chen").description("Backend"),
        MentionItem::new("u_dana", "Dana Ortiz").description("Product"),
        MentionItem::new("u_joan", "Joan Park").description("Support"),
        MentionItem::new("u_kofi", "Kofi Mensah").description("Data"),
        MentionItem::new("u_mira", "Mira Shah").description("Frontend"),
        MentionItem::new("u_sam", "Sam Okafor").description("QA"),
    ];
    let commands = vec![
        MentionItem::new("assign", "assign").description("Assign to someone"),
        MentionItem::new("due", "due").description("Set a due date"),
        MentionItem::new("label", "label").description("Add a label"),
        MentionItem::new("estimate", "estimate").description("Set points"),
        MentionItem::new("close", "close").description("Close the issue"),
    ];
    vec![MentionSource::new('@', "People", people), MentionSource::new('/', "Commands", commands)]
}

pub fn demo() -> AnyView {
    let start = "Checkout fails on Safari for some cards. @Bo Chen can you look at the logs? ";
    let value = RwSignal::new(MentionValue {
        text: start.into(),
        mentions: vec![Mention { id: "u_bo".into(), label: "Bo Chen".into(), trigger: '@', start: 41, end: 49 }],
    });

    view! {
        <div style="display: grid; gap: var(--space-4); max-width: 560px;">
            <MentionInput
                label="Comment"
                sources=sources()
                default_value=value.get_untracked()
                placeholder="Write a comment. @ mentions someone, / runs a command"
                on_change=move |v: MentionValue| value.set(v)
            />
            <div style="display: grid; gap: var(--space-1); font: var(--text-xs); color: var(--text-3);">
                <span>{move || value.with(|v| format!("{} characters", v.text.chars().count()))}</span>
                {move || {
                    value
                        .with(|v| v.mentions.clone())
                        .into_iter()
                        .map(|m| {
                            view! {
                                <code style="font-family: var(--font-mono);">
                                    {format!("{}{} → {} at {}..{}", m.trigger, m.label, m.id, m.start, m.end)}
                                </code>
                            }
                        })
                        .collect_view()
                }}
            </div>
        </div>
    }
    .into_any()
}

Anatomy

Componentdata-partRenders
MentionInputrootWrapper. data-open while a list shows, data-disabled
MentionInputlabelNames the field
MentionInputfieldThe bordered box. Holds the mirror, the textarea and the list
MentionInputmirroraria-hidden copy of the text behind the textarea, with the same metrics
MentionInputmentionSpan in the mirror that draws a mention's pill
MentionInputanchorEmpty span at the open trigger. The list is placed under it
MentionInputinputNative <textarea role=combobox>. Editing, selection and IME stay native
MentionInputpopoverThe floating list. Positioned from --mention-x and --mention-y
MentionInputlistboxrole=listbox, named after the source (People, Commands)
MentionInputoptionrole=option. data-highlighted on the active row
MentionInputoption-mark, option-label, option-descriptionTrigger badge, name and secondary text
MentionInputemptyShown when nothing matches
MentionInputstatusVisually hidden role=status with the result count

Keyboard

KeyDoes
@ or /At the start of a word: open that list. Keep typing to filter
ArrowDown / ArrowUpWith a list open: move the highlight, wrapping
Enter / TabWith a list open: insert the highlighted row as a mention
EscapeClose the list. It stays closed until you leave that trigger
Backspace / DeleteNext to a mention: remove the whole mention
ArrowLeft / ArrowRightStep over a mention in one press

Props

PropTypeNotes
labelStringRequired. Visible label
sourcesVec<MentionSource>Required. Each trigger character with its list name and items. MentionSource::new('@', "People", items); .start_only() for chat-style /commands
default_valueMentionValueInitial text and mentions. Mentions that do not match the text are dropped
on_changeCallback<MentionValue>The text plus each mention's id, label, trigger and char range
placeholderStringHint shown when empty
rowsu32Visible text rows. Default 3. The field can be resized taller
disabledboolGreyed out and not editable
Actions
Button
Icon button
Toolbar
Theme menu
Display
Avatar
Badge
Card
Chip
Code block
Markdown
Doc card
Due pill
Kbd
Priority mark
Source chip
Space icon
Status diamond
Tag
Value diff
Carousel
Reveal
Media timeline
QR code
Transcript viewer
Audio waveform
Audio player
Forms
Calendar
Checkbox
Combobox
Date picker
Color picker
Cron builder
Theme editor
Mention input
Signature pad
Image cropper
Date field
Date range picker
Duration field
Quantity stepper
Filter chip
Input
Markdown editor
Radio group
Search field
Segmented control
Select
Slider
Range slider
Rating
Toggle button
File dropzone
Upload queue
Attachment
Switch
Tags input
Number field
Money field
Phone field
Time field
OTP input
Password field
Questionnaire
Availability picker
Voice input
Recording control
Inline edit
Async validated input
Shortcut recorder
Data
Spreadsheet grid
Week scheduler
Virtual list
Stat card
Step track
Kanban board
Sortable list
Filter builder
Data table
Grid
Access editor
File manager
Gantt chart
Log stream
Diff viewer
JSON inspector
Terminal
Node editor
Whiteboard
Navigation
Table of contents
Breadcrumb
Tabs
Wizard
Nav item
Nav section
Tree view
Pagination
Menubar
Navigation menu
Saved views
Layout
Master detail
App shell
Sidebar layout
Resizable panels
Dashboard layout
Dock layout
Feedback
Callout
Check list
Empty state
Progress bar
Toast
Approval card
Skeleton
Notification center
Bars
Bar chart
Diverging bar chart
Span chart
Pictogram chart
Stacked bar chart
Funnel chart
Bullet chart
Waffle chart
Marimekko chart
Dot plot chart
Error bar chart
Pareto chart
Waterfall chart
Lollipop chart
Grouped bar chart
Bar race chart
KPIs and frames
Chart frame
Metric card
Sparkline
Points
Scatter chart
Smith chart
Strip plot
Beeswarm chart
Parallel coordinates
Ternary chart
Bland-Altman chart
Quiver chart
Connected scatter chart
Grids and tables
Heatmap chart
Chart table
Cohort chart
Radial
Radial charts
Radar chart
Polar area chart
Stat ring
Clock chart
Spiral chart
Lines and areas
Bump chart
Slope chart
Line chart
Composed chart
Small multiples
Cycle plot chart
Horizon chart
Stacked area chart
Threshold chart
Split line chart
Linked charts
Confidence band chart
Forecast fan chart
Step chart
Range area chart
Distributions
Contour chart
Histogram
Box plot
Density chart
Ridgeline chart
Violin chart
Q-Q chart
Survival chart
ECDF chart
Raincloud plot
Forest plot
Maps
Geo map
Bubble map
Hexbin map
Cartogram
Flow map
Parts of a whole
Donut chart
Voronoi treemap
Nested donut chart
Treemap chart
Sunburst chart
Bubble pack chart
Icicle chart
Flame graph chart
Pie chart
Word cloud
Relationships
Sankey chart
Network chart
Chord chart
UpSet chart
Venn chart
Alluvial chart
Adjacency matrix chart
Dependency graph chart
Tree chart
Arc diagram
Hive plot
Edge bundling
Finance
Candlestick chart
OHLC chart
Depth chart
Renko chart
Time
Timeline chart
Calendar heatmap chart
Spectrogram chart
Marey chart
Overlays
Tour
Lightbox
Alert dialog
Command palette
Dialog
Menu
Popover
Tooltip
Sheet
Hover card
Context menu
Utilities
Pacer
Hotkeys
Disclosure
Accordion
Collapsible
Chat
Chat bubble
Voice session
Composer
Thread
Thread list
Assistant composer
Assistant MCP
Assistant modal
Assistant thread
Assistant thread list
Message scroller
Insight note
Emoji picker
Tool trace
Model picker
Citation popover
Activity
Activity feed
Comment thread
Timeline
Presence bar
Live cursors
Reaction bar
Guides
Getting started
All components
All charts