Forms

Rich-text editor.

Structured content with formatting, native forms and safe serialization.

LIVE PREVIEWTry it. It works.

Install the source

Terminal
npx shadcn@latest add https://ui.bld8.dev/r/rich-text-editor.json

Registry setup · Examples · API and behavior · Open the playground

COMPLETE EXAMPLES

Use it in context.

Each example includes its imports, data and state. The preview runs that same source. Include the stylesheet once in your application.

A structured note with native form ownership

Write and format a note, submit its canonical JSON through an external form, and reset without losing controlled ownership. Read-only text stays submitted; disabled text is excluded.

Keyboard

  • Tab enters the formatting toolbar and editable document. Standard editor shortcuts format and undo.
  • Submitting an empty required note focuses the real editor. Reset restores defaults unless cancelled.

States covered

  • External form
  • Required editor focus
  • Native and prevented reset
  • Read only
  • Disabled exclusion
  • Structured JSON submission

Install this complete example and its component dependencies.

Terminal
npx shadcn@latest add https://ui.bld8.dev/r/example-rich-text-review-form.json
Complete source
React / TypeScript
/*!
MIT License

Copyright (c) 2026 Jaison

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
'use client';
import '@bld8/ui/styles.css';
import {useId,useState} from 'react';
import {Button,Checkbox,RichTextEditor,richTextToText,type RichTextDocument,UIProvider} from '@bld8/ui';
const locked:RichTextDocument={type:'doc',content:[{type:'paragraph',content:[{type:'text',text:'Read-only reference.'}]}]};
export default function RichReviewForm(){const id=useId(),[prevent,setPrevent]=useState(false),[changes,setChanges]=useState(0),[status,setStatus]=useState('No note submitted.');return <UIProvider><div style={{display:'grid',gap:24,maxWidth:760}}>
  <RichTextEditor label="Review note" name="note" form={id} required onValueChange={()=>setChanges(value=>value+1)} hint="A local note. Nothing is sent."/>
  <RichTextEditor label="Locked reference" name="locked" form={id} defaultValue={locked} readOnly toolbar="none"/>
  <RichTextEditor label="Unavailable reference" name="disabled" form={id} defaultValue={locked} disabled toolbar="none"/>
  <Checkbox label="Prevent note reset" checked={prevent} onCheckedChange={setPrevent}/>
  <form id={id} aria-label="Review note form" onReset={event=>{if(prevent){event.preventDefault();setStatus('Note reset prevented.');}else setStatus('Note defaults restored.');}} onSubmit={event=>{event.preventDefault();const data=new FormData(event.currentTarget);setStatus('Note: '+richTextToText(JSON.parse(String(data.get('note'))))+' | Locked: '+richTextToText(JSON.parse(String(data.get('locked'))))+' | Disabled: '+data.has('disabled'));}}>
    <div style={{display:'flex',gap:12,flexWrap:'wrap'}}><Button type="submit">Read note values</Button><Button type="reset" variant="secondary">Reset note</Button></div>
  </form><p role="status">{status}</p><p data-rich-changes>{'Changes: '+changes}</p>
</div></UIProvider>;}

Controlled content without cursor jumps

Echo a fresh JSON object on each edit while preserving the active selection. Apply a new document identity to start a separate history, and inspect escaped HTML output as text.

Keyboard

  • Edit in the middle of a sentence; controlled JSON echoes keep the caret in place.
  • Use formatting or keyboard shortcuts, then Undo/Redo. Replace the document to begin a new history.
  • Select text and use Edit link; unsafe destinations are rejected without changing the document.

States covered

  • Controlled JSON
  • Selection-safe echoes
  • Undo and redo
  • Document identity
  • Safe link editing
  • Safe HTML serialization

Install this complete example and its component dependencies.

Terminal
npx shadcn@latest add https://ui.bld8.dev/r/example-rich-text-controlled-document.json
Complete source
React / TypeScript
/*!
MIT License

Copyright (c) 2026 Jaison

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
'use client';
import '@bld8/ui/styles.css';
import {useState} from 'react';
import {Button,Checkbox,RichTextEditor,richTextToHtml,type RichTextDocument,UIProvider} from '@bld8/ui';
const first:RichTextDocument={type:'doc',content:[{type:'paragraph',content:[{type:'text',text:'Keep the useful details together.'}]}]};
export default function ControlledRichText(){const [value,setValue]=useState(first),[identity,setIdentity]=useState(0),[readOnly,setReadOnly]=useState(false);return <UIProvider><div style={{display:'grid',gap:20,maxWidth:760}}>
  <RichTextEditor label="Controlled note" name="controlledNote" value={value} onValueChange={next=>setValue(JSON.parse(JSON.stringify(next)))} documentKey={String(identity)} readOnly={readOnly}/>
  <div style={{display:'flex',gap:12,flexWrap:'wrap'}}><Button variant="secondary" onClick={()=>{setValue({type:'doc',content:[{type:'paragraph',content:[{type:'text',text:'A separate review.'}]}]});setIdentity(value=>value+1);}}>Replace document</Button><Checkbox label="Read-only note" checked={readOnly} onCheckedChange={setReadOnly}/></div>
  <pre data-rich-html style={{whiteSpace:'pre-wrap',overflowWrap:'anywhere',maxWidth:'100%'}}>{richTextToHtml(value)}</pre>
</div></UIProvider>;}

A scoped Arabic editing surface

The editor, formatting popup and mention choices inherit an explicit local language, direction and theme. Host labels and directory identities remain application-owned.

Keyboard

  • Tab enters the toolbar; its directional arrows follow RTL. Editor shortcuts keep their native editing semantics.
  • Type @ to search the authored Arabic directory. Escape closes suggestions and keeps the text.

States covered

  • Scoped RTL
  • Dark theme
  • Local message overrides
  • Arabic directory labels
  • Stable IDs
  • Reduced motion

Install this complete example and its component dependencies.

Terminal
npx shadcn@latest add https://ui.bld8.dev/r/example-rich-text-scoped-arabic.json
Complete source
React / TypeScript
/*!
MIT License

Copyright (c) 2026 Jaison

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
'use client';
import '@bld8/ui/styles.css';
import {RichTextEditor,UIProvider,type RichTextMentionSource,type RichTextDocument} from '@bld8/ui';
const content:RichTextDocument={type:'doc',content:[{type:'paragraph',content:[{type:'text',text:'تفاصيل صغيرة تجعل المراجعة أوضح.'}]}]};
const source:RichTextMentionSource=async({query,signal})=>signal.aborted?[]:[{id:'reviewer-maya',label:'مايا',description:'هندسة الواجهات'},{id:'reviewer-sam',label:'سام',description:'أنظمة التصميم'}].filter(person=>person.label.includes(query));
export default function ArabicRichText(){return <UIProvider theme="dark" locale="ar" direction="rtl" motion="reduced" messages={{'rich.formatting':'تنسيق النص','rich.bold':'غامق','rich.italic':'مائل','rich.strike':'يتوسطه خط','rich.block':'نمط النص','rich.paragraph':'فقرة','rich.heading1':'عنوان ١','rich.heading2':'عنوان ٢','rich.heading3':'عنوان ٣','rich.bullets':'قائمة نقطية','rich.ordered':'قائمة مرقمة','rich.codeBlock':'كتلة برمجية','rich.editLink':'تعديل الرابط','rich.linkAddress':'عنوان الرابط','rich.undo':'تراجع','rich.redo':'إعادة','rich.mention':'إشارة إلى شخص','rich.people':'أشخاص للإشارة','rich.noPeople':'لا توجد أسماء مطابقة.'}}><div style={{padding:24,background:'var(--bui-surface)',borderRadius:12}}><RichTextEditor label="ملاحظة المراجعة" defaultValue={content} mentionSource={source} hint="الأسماء المعروضة لا تغيّر المعرّفات المخزنة."/></div></UIProvider>;}

Document boundaries and rejected controlled edits

Switch an uncontrolled document without carrying its defaults or history into another record. Rejected controlled edits restore the accepted JSON; unsupported content in a new document never reveals the previous document.

Keyboard

  • Tab enters either editor. Rejected controlled edits keep the accepted text and named form value aligned.
  • Switch a document identity to start fresh defaults and history; native reset uses the current document default.

States covered

  • uncontrolled document identity
  • fresh reset defaults
  • controlled rejection
  • invalid new document
  • separate history
  • native canonical JSON

Install this complete example and its component dependencies.

Terminal
npx shadcn@latest add https://ui.bld8.dev/r/example-rich-text-document-boundaries.json
Complete source
React / TypeScript
/*!
MIT License

Copyright (c) 2026 Jaison

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
'use client';
import '@bld8/ui/styles.css';
import {useId,useState} from 'react';
import {Button,Checkbox,RichTextEditor,type RichTextDocument,UIProvider} from '@bld8/ui';
const first:RichTextDocument={type:'doc',content:[{type:'paragraph',content:[{type:'text',text:'Private document A.'}]}]};
const second:RichTextDocument={type:'doc',content:[{type:'paragraph',content:[{type:'text',text:'Document B starts here.'}]}]};
export default function DocumentBoundaries(){const form=useId(),[record,setRecord]=useState('a'),[value,setValue]=useState(first),[identity,setIdentity]=useState('accepted'),[reject,setReject]=useState(true),[attempts,setAttempts]=useState(0);return <UIProvider><div style={{display:'grid',gap:24,maxWidth:760}}>
<RichTextEditor label="Uncontrolled record" name="record" form={form} documentKey={record} defaultValue={record==='a'?first:second}/>
<Button variant="secondary" onClick={()=>setRecord('b')}>Open second uncontrolled document</Button>
<RichTextEditor label="Controlled boundary note" name="controlled" form={form} documentKey={identity} value={value} onValueChange={next=>{setAttempts(count=>count+1);if(!reject)setValue(next);}}/>
<Checkbox label="Reject controlled edits" checked={reject} onCheckedChange={setReject}/>
<div style={{display:'flex',gap:12,flexWrap:'wrap'}}><Button variant="secondary" onClick={()=>{setValue({type:'doc',content:[{type:'image'}]} as unknown as RichTextDocument);setIdentity('unsupported');}}>Open unsupported controlled document</Button><Button variant="ghost" onClick={()=>{setValue(second);setIdentity('second');}}>Open second controlled document</Button></div>
<form id={form}><Button variant="secondary" type="reset">Reset boundary documents</Button></form><p data-rejected-attempts>{'Edit attempts: '+attempts}</p>
</div></UIProvider>;}

Quick reference

React / TypeScript
<RichTextEditor label="Project notes" name="notes" />

In the workspace or ZIP starter, import components from @bld8/ui and include @bld8/ui/styles.css once. Registry installations use your local bld8/ source path. Wrap overlays in UIProvider.

API & behaviour

JSON-only schema, safe explicit links and plain-text paste. Optional formatting and contextual toolbar, history, native form ownership/reset, read-only mode and document boundaries. No media hosting or collaboration service is included.

RichTextEditor

RichTextEditor public properties
PropTypeDefault
labelRequiredstring—
classNamestring | undefined—
contextToolbarboolean | undefinedtrue
defaultValueRichTextDocument | undefinedEMPTY_RICH_TEXT_DOCUMENT
disabledboolean | undefinedfalse
documentKeystring | undefined

Changes establish a new document/history boundary. Controlled value echoes preserve selection.

''
errorstring | undefined—
formstring | undefined—
hintstring | undefined—
inputRefRef<HTMLDivElement> | undefined—
maxLengthnumber | undefined

Plain-text character limit, from 1 to 100,000. Structured documents are additionally bounded.

20000
mentionDebounceMsnumber | undefined150
mentionSourceRichTextMentionSource | undefined—
mentionSourceKeystring | undefined''
namestring | undefined—
onBlur(() => void) | undefined—
onValueChange((value: RichTextDocument) => void) | undefined—
placeholderstring | undefined—
readOnlyboolean | undefinedfalse
requiredboolean | undefinedfalse
toolbar"none" | "full" | "compact" | undefined'full'
valueRichTextDocument | undefined—

RichTextEditorProps

RichTextEditorProps public properties
PropTypeDefault
labelRequiredstring—
classNamestring | undefined—
contextToolbarboolean | undefined—
defaultValueRichTextDocument | undefined—
disabledboolean | undefined—
documentKeystring | undefined

Changes establish a new document/history boundary. Controlled value echoes preserve selection.

—
errorstring | undefined—
formstring | undefined—
hintstring | undefined—
inputRefRef<HTMLDivElement> | undefined—
maxLengthnumber | undefined

Plain-text character limit, from 1 to 100,000. Structured documents are additionally bounded.

—
mentionDebounceMsnumber | undefined—
mentionSourceRichTextMentionSource | undefined—
mentionSourceKeystring | undefined—
namestring | undefined—
onBlur(() => void) | undefined—
onValueChange((value: RichTextDocument) => void) | undefined—
placeholderstring | undefined—
readOnlyboolean | undefined—
requiredboolean | undefined—
toolbar"none" | "full" | "compact" | undefined—
valueRichTextDocument | undefined—

RichTextDocument

RichTextDocument public properties
PropTypeDefault
contentRequiredRichTextNode[]—
typeRequired"doc"—

RichTextMentionSource

(request:RichTextMentionRequest)=>Promise<readonly RichTextMention[]>

RichTextMention

RichTextMention public properties
PropTypeDefault
idRequiredstring—
labelRequiredstring—
descriptionstring | undefined—
disabledboolean | undefined—

Tables come from the public TypeScript declarations. Related types and function parameters are shown alongside their component. A dash means no default is declared at the public function boundary.

Related controls

Notes to self

Test this component with real content, keyboard input and both themes. The example is a starting point; labels, error handling and behaviour still need to fit the application.