value="<h2>What's new</h2><p>Faster <strong>search</strong> and a new <a href='https://example.com'>export</a> option.</p><ul><li>Dark mode</li><li>Keyboard shortcuts</li></ul>"></focsd-rich-text>
</div>
Usage
Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.
return<focsd-rich-textref={ref}label="Release notes"name="notes"hint="Shown to customers on the changelog"value="<h2>…</focsd-rich-text>;
}
<scriptsetup>
import'@focsd-dev/editor';
</script>
<template>
<focsd-rich-text@change="onChange"label="Release notes"name="notes"hint="Shown to customers on the changelog"value="<h2>…</focsd-rich-text>
</template>
// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:
import'@focsd-dev/editor';
// template
<focsd-rich-text (change)="onChange($event)" label="Release notes" name="notes" hint="Shown to customers on the changelog" value="<h2>…</focsd-rich-text>
<script>
import'@focsd-dev/editor';
</script>
<focsd-rich-textonchange={(e) => console.log(e.target)}label="Release notes"name="notes"hint="Shown to customers on the changelog"value="<h2>…</focsd-rich-text>
API
Attributes
Attribute
Property
Type
Default
label
label
string
—
hint
hint
string
—
placeholder
placeholder
string
—
value
value
—
—
name
name
string
—
disabled
disabled
boolean
false
required
required
boolean
false
readonly
readOnly
boolean
false
aria-label
hostAriaLabel
string | null
null
aria-description
hostAriaDescription
string | null
null
aria-labelledby
hostAriaLabelledBy
string | null
null
aria-describedby
hostAriaDescribedBy
string | null
null
label-position
labelPosition
'top' | 'start' | 'end' | undefined
—
error
error
—
—
warning
warning
string | undefined
—
success
success
string | undefined
—
error-message
errorMessage
string | undefined
—
warning-message
warningMessage
string | undefined
—
warning-pattern
warningPattern
string | undefined
—
Methods
Method
Description
focus(options)
Focus the editable area.
openLinkForm()
Open the link form for the selection (prefilled with the current link).
describedByIds()
IDs to add to the inner control's aria-describedby: the hint, then the shown message.
checkValidity()
True when the value is valid; otherwise fires invalid and returns false, like native.
reportValidity()
Like checkValidity(), and also shows the browser's validation message when invalid.
setCustomValidity(message)
Set (non-empty) or clear (empty string) a custom validation error, like native controls.
setValidityState(flags, message, anchor)
For subclasses: set the validity flags and message. anchor is the element the browser points its message at.
validate()
Show (or clear) the error from the control's own checks: required, type, pattern, min,
max and the like. Uses error-message, else the browser's localized message. An error the
author set (a server error, say) is left as it is.
clearValidation()
Clear the error and warning that validate() and warning-pattern showed (a form reset does).
emitValue(commit)
For subclasses: fire the value events, as a native control does on a user edit: input
(bubbles, composed), then with commit also change (bubbles, stays in its tree).
idrefText(ids)
For subclasses: the text of the elements an ID reference list names, resolved in the host's
tree (ID references cannot cross a shadow root), joined by spaces.
Events
Event
Description
input
Fired on every edit.
change
Fired when the editor loses focus after its value changed.
Slots
Slot
Description
content
Created by the element: the editable area (do not supply your own).
CSS parts
Style the inside of the component with ::part(), for example focsd-rich-text::part(label).
Part
Description
label
The label.
hint
The hint.
error
The error message.
field
The frame around the toolbar and the editable area.
toolbar
The formatting toolbar.
tool
Each toolbar button (also `tool-active` when pressed).
separator
A divider between toolbar groups.
link-form
The link address form.
Accessibility
A multi-line role="textbox" named by its label, with the hint or error as its description.
The toolbar is an APG toolbar: one tab stop, arrow keys between buttons, aria-pressed for formats, and aria-keyshortcuts for each shortcut.
The value is HTML limited to the toolbar's formats: scripts, event handlers and unsafe links are removed, and links only accept web, mail, phone or same-site addresses.
Form-associated: name, required, disabled, readonly, reset and setCustomValidity work like a textarea.
Separate package (@focsd-dev/editor, about 141 KB gzip with Tiptap and ProseMirror): load it only on pages that need it, for example with import('@focsd-dev/editor').
Keyboard
Key
Action
Ctrl/Cmd + B, I, U
Bold, italic, underline
Ctrl/Cmd + K
Add or edit a link
Ctrl/Cmd + Alt + 2 / 3
Heading 2 / 3
Ctrl/Cmd + Shift + 7 / 8
Numbered / bulleted list
Ctrl/Cmd + Z, Shift + Z
Undo, redo
Tab / Shift + Tab (in a list)
Indent / outdent the item; elsewhere Tab leaves the editor
Arrow keys (toolbar)
Move between buttons
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.