Rich textarea
Everything the rich input does, with newlines. Enter breaks a line instead of doing nothing, and the value keeps them.
Installation
bunx --bun shadcn@latest add https://oss.flikk.dev/ui/r/rich-input.jsonUsage
import { defineInputField, RichTextarea } from "@/components/ui/rich/editor"const ref = defineInputField("ref", {
pattern: /\{\{([\w.]+)\}\}/,
render: ({ groups }) => <span>{groups[0]}</span>,
})
export function Body() {
const [value, setValue] = useState("Line one\nLine two")
return <RichTextarea components={[ref]} value={value} onValueChange={setValue} />
}Composition
RichTextarea
└── renderPicker
└── RichPickerThe same two nodes as the single line field, and the same reason: this is not a compound component. A token is a value you pass, not an element you nest.
The two share one core. Everything below is the difference, which is smaller than having two pages might suggest: Enter, and what happens to a newline.
Examples
Composed input
An input method writes into the field directly, the one case the component cannot intercept. Compose a word, accept a candidate, press Enter, then edit around it.
No fields
With nothing declared it is a textarea, and it is tested as one: value and caret against a native textarea after the same keystrokes, newlines included.
API reference
defineInputField(key, {
pattern: RegExp // a complete token
render: (match) => ReactNode // or { draft, resolved }
opens?: RegExp // an unfinished one, anchored at the caret
resolved?: RegExp // the settled form of an async token
resolve?: (match) => Promise<string | null>
editable?: boolean // caret may re-enter it. default false
className?: string // the chip shell
})Only pattern and render are load bearing. The rest is a thing you may want, and the surface never branches on what a token means.
<RichTextarea
components={fields}
value | defaultValue
onValueChange={(value: string) => void}
renderPicker={({ query, mode, current, rect, start, end, replace, close }) => ReactNode}
placeholder disabled className
ref={{ value, selectionStart, selectionEnd, setSelectionRange, focus, undo, redo }}
/>Identical to the single line field but for newlines: Enter inserts one, the value keeps it, and nothing strips it on the way in. A chip still cannot be split, and the caret still cannot land inside one, across lines as within them.
<RichPicker
query what is being typed
search (query) => items | Promise<items>
items or a fixed list
searchable render an input of its own
rect side bottom | top | left | right
onPick close
/>A convenience, not the interface. It owns the arrows, Tab, Enter, Escape and the care about a slow search landing after a faster one, so a host does not write that twice. Render your own list whenever the arrangement matters.