Rich text editor: the same document model, commands, shortcuts and value formats (HTML, Markdown, JSON) as the web RichTextEditor.
35 exports
Live example
The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.
Preview
Weekly note
This editor supports bold, italic, underline, strikethrough, inline code and highlight. There are links too.
Finish the design
Write the tests
Mobile
Try the Markdown shortcuts: type ## , - , 1. , [ ] , > or ```ts at the start of a line.
export function Hello({ name }: { name: string }) {
return <p>Hello {name}!</p>;
}
Type / on an empty line to add a block, mention someone with @.
Value (html)
<h2>Weekly note</h2>
<p>This editor supports <strong>bold</strong>, <em>italic</em>, <u>underline</u>, <s>strikethrough</s>, <code>inline code</code> and <mark>highlight</mark>. There are <a href="https://github.com/yasinsensoy/ui">links</a> too.</p>
<ul data-type="task"><li data-checked="true">Finish the design</li><li data-checked="false">Write the tests<ul data-type="task"><li data-checked="false">Mobile</li></ul></li></ul>
<blockquote>Try the Markdown shortcuts: type <code>## </code>, <code>- </code>, <code>1. </code>, <code>[ ] </code>, <code>> </code> or <code>```ts</code> at the start of a line.</blockquote>
<pre data-language="tsx"><code>export function Hello({ name }: { name: string }) {
return <p>Hello {name}!</p>;
}</code></pre>
<p>Type <code>/</code> on an empty line to add a block, mention someone with <code>@</code>.</p>
Code
TSX
import { RichTextEditor, RichTextView } from "@yasinsensoy/native";<RichTextEditor placeholder="Write something…" mentions={[{ trigger: "@", items: personSearch }, { trigger: "#", items: tags }]} onImageUpload={async (file) => (await upload(file)).url} onValueChange={setContent}/>// To display it (server component, code blocks with CodeBlock):<RichTextView value={content} />
Events
Events appear here when you interact with the preview.
Control with a ref and RichTextView
Control with a ref
Try the buttons.
Form field (required, 280 characters, Markdown)
Read-only display (RichTextView)
Weekly note
This editor supports bold, italic, underline, strikethrough, inline code and highlight. There are links too.
Finish the design
Write the tests
Mobile
Try the Markdown shortcuts: type ## , - , 1. , [ ] , > or ```ts at the start of a line.
TSX
export function Hello({ name }: { name: string }) { return <p>Hello {name}!</p>;}
Type / on an empty line to add a block, mention someone with @.
Rich text editor: the same document model, commands, shortcuts and value formats (HTML, Markdown, JSON) as the web RichTextEditor. No WebView; each paragraph is its own native text input, so keyboard, autocorrect, dictation and selection on iOS and Android are the system's own.
Shortcuts:# , - , 1. , [ ] , > , ``````, ---, bold`… convert as you type; deleting right after undoes it.
`/` menu and mentions: a suggestion list under the line; server search (cancellable) is supported.
Undo / redo: typing groups undo in one step (300 steps).
Mobile differences: a toolbar (scrolls horizontally) and the system's own selection menu replace the selection bubble; selection stays within one paragraph.
RichTextEditor with its label, description and error message. With name it binds to the nearest Form: the value is stored in the format format and the error shows on blur or on submit.
Shows rich text (HTML, Markdown or JSON). Same core and same typography as the web RichTextView and RichTextEditor; what you write looks the same as what is published.
Safe: HTML is not executed and no WebView is used; the content is converted to native elements. Unknown tags, scripts and unsafe URLs are dropped.
Converts rich text to HTML. The input is sanitized; the output contains only known tags and safe URLs, so it can be shown with dangerouslySetInnerHTML. Also runs on the server.
Suggestions: an array or a function called with the typed query (server search). The function can cancel stale searches via signal. An array is filtered by name.
Props of the RichTextEditor component (same names as web).
Name
Type
Default
Description
variant?
"outline" | "filled" | "underline" | "ghost"
"outline"
Field appearance.
effect?
EffectProp
Effect of the field box. See EffectProp.
value?
RichTextValue
Controlled value. Its format is set by format.
defaultValue?
RichTextValue
Uncontrolled initial value.
onValueChange?
(value: RichTextValue) => void
Called with the new value when the content changes. An empty document yields "" (an empty document in json).
format?
RichTextFormat
"html"
Value format: "html", "markdown" or "json".
placeholder?
string
Placeholder shown while the document is empty.
toolbar?
boolean | readonly RichTextToolbarItem[]
true
Toolbar: true shows the default tools, false hides it, an array shows only those tools (in order). Scrolls horizontally on phones.
markdownShortcuts?
boolean
true
Markdown shortcuts: # heading, - list, 1. numbered list, [ ] to-do, > quote, `````` code block, --- rule, bold, italic, code, ~~strike~~, ==highlight==`. Typed addresses become links. Backspace right after a shortcut undoes it.
slashCommands?
boolean | readonly RichTextSlashCommand[]
true
Slash (/) menu: typing / at the start of a line or after a space opens the block insert list. An array adds your own commands after the built-in ones. false disables it.
Mention sources: @ people, # tags and so on. See RichTextMentionSource.
onImageUpload?
(file: PickedFile) => Promise<string>
Image uploader. When given, "Upload from file" picks from the gallery (requires @yasinsensoy/native/file-system); upload the file to your server and return its URL. The image looks faded while uploading; it is removed on error.
maxLength?
number
Maximum characters. Input beyond it is blocked.
showCount?
boolean | "words"
Counter on the bottom line: true characters, "words" words. Turns on when maxLength is set.
readOnly?
boolean
Read-only: the toolbar is hidden and typing is disabled.
disabled?
boolean
Disabled.
autoFocus?
boolean
Focus when the screen opens.
required?
boolean
Cannot be left empty in a form (whitespace only also counts as empty).
invalid?
boolean
Mark as invalid (red border).
aria-label?
string
messages.editor
Screen reader name.
spellCheck?
boolean
true
Spell check and autocorrect.
minHeight?
number
120
Minimum height of the content area (pixels).
maxHeight?
number
Maximum height of the content area; beyond it the editor scrolls inside and the toolbar stays visible. If omitted it grows with the content.
Props of the RichTextField component: field frame + all editor props.
TypeScript
type RichTextFieldProps = FieldProps & Omit<RichTextEditorProps, "invalid">
Extends: FieldProps
Name
Type
Default
Description
variant?
"outline" | "filled" | "underline" | "ghost"
"outline"
Field appearance.
effect?
EffectProp
Effect of the field box. See EffectProp.
value?
RichTextValue
Controlled value. Its format is set by format.
defaultValue?
RichTextValue
Uncontrolled initial value.
onValueChange?
(value: RichTextValue) => void
Called with the new value when the content changes. An empty document yields "" (an empty document in json).
format?
RichTextFormat
"html"
Value format: "html", "markdown" or "json".
placeholder?
string
Placeholder shown while the document is empty.
toolbar?
boolean | readonly RichTextToolbarItem[]
true
Toolbar: true shows the default tools, false hides it, an array shows only those tools (in order). Scrolls horizontally on phones.
markdownShortcuts?
boolean
true
Markdown shortcuts: # heading, - list, 1. numbered list, [ ] to-do, > quote, `````` code block, --- rule, bold, italic, code, ~~strike~~, ==highlight==`. Typed addresses become links. Backspace right after a shortcut undoes it.
slashCommands?
boolean | readonly RichTextSlashCommand[]
true
Slash (/) menu: typing / at the start of a line or after a space opens the block insert list. An array adds your own commands after the built-in ones. false disables it.
Mention sources: @ people, # tags and so on. See RichTextMentionSource.
onImageUpload?
(file: PickedFile) => Promise<string>
Image uploader. When given, "Upload from file" picks from the gallery (requires @yasinsensoy/native/file-system); upload the file to your server and return its URL. The image looks faded while uploading; it is removed on error.
maxLength?
number
Maximum characters. Input beyond it is blocked.
showCount?
boolean | "words"
Counter on the bottom line: true characters, "words" words. Turns on when maxLength is set.
readOnly?
boolean
Read-only: the toolbar is hidden and typing is disabled.
disabled?
boolean
Disabled.
autoFocus?
boolean
Focus when the screen opens.
required?
boolean
Cannot be left empty in a form (whitespace only also counts as empty).
aria-label?
string
messages.editor
Screen reader name.
spellCheck?
boolean
true
Spell check and autocorrect.
minHeight?
number
120
Minimum height of the content area (pixels).
maxHeight?
number
Maximum height of the content area; beyond it the editor scrolls inside and the toolbar stays visible. If omitted it grows with the content.
<RichTextEditorformat="markdown"defaultValue="**Hello**"onValueChange={setContent}/><RichTextEditormentions={{ items: people }}onImageUpload={async(f)=>(awaitupload(f)).url}/>