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.
npx shadcn@latest add https://ui.bld8.dev/r/example-rich-text-review-form.jsonComplete source
/*!
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>;}