Editors
TinyMCE
A rich text editor built on TinyMCE 8 (self-hosted, GPL), as a form field: label, help text and validation error around it, and its content saved as HTML in a hidden field. It follows the app's language and the light and dark color scheme, and uploads images to the server.
Nothing to show
A "Body" label over a TinyMCE editor with a toolbar: undo and redo, text formatting, block types, colors, font size, sub and superscript, alignment, links, lists, images and media, tables, quote, and source code. Each change is saved as HTML in a hidden field named body, sent with the form.
Bound to Livewire #
The editor opens with the HTML of $body, with only the text, list and link buttons, and each change sets the property. Setting $body on the server replaces the content shown.
<p>Hello <strong>world</strong></p>
Nothing to show
Your own configuration #
options is merged over the configuration the component builds; data-options does the same from JavaScript, for functions. A setup of your own runs after the component's, so the value keeps syncing.
Nothing to show
Read-only #
readonly or disabled switch the editor to read-only mode. With toolbar set to none only the content is left.
Nothing to show
Events #
rendered fires on the tag when the editor is ready, and again after it is created for a color scheme change, with the instance in $event.detail.editor.
Nothing to show
Customization #
Classes on the tag go to the field control; editor: attributes reach the editor box. The field props (description, help) work as on any field.
Nothing to show
Reference
tk:tinymce
| Prop | Type | Default | Description |
|---|---|---|---|
toolbar |
string | all groups | The toolbar groups, separated by spaces: text, heading (block types), color, size, script, align, link, list, media, table, quote, code. full turns on all of them, none hides the toolbar. Undo and redo are always there. |
upload |
array | false | on | How images are uploaded, as on tk:quill: disk, directory, types, maxSize, guest, url. false keeps images inline. |
options |
array | [] |
TinyMCE configuration, merged over the component's. |
scripts |
array | [] |
URLs of scripts loaded after TinyMCE, for plugins. |
styles |
array | [] |
URLs of stylesheets loaded after it. |
Also accepts the field props and the field control props. wire:model and x-model bind the HTML as a string.
Slots
| Slot | Description |
|---|---|
| default | The initial HTML, in place of value. |
Events
| Event | Detail | When |
|---|---|---|
rendered |
{ editor }, the TinyMCE instance |
The editor is ready, also after it is created again for a color scheme change. Dispatched on the hidden field; does not bubble. |
upload-failed |
{ error, file, type, message } |
An image could not be uploaded. Dispatched on the hidden field; bubbles and is cancelable. No toast is shown: message goes back to TinyMCE, which shows it in its own notice and drops the image. |
started, completed, failed |
TinyMCE starts loading, is ready, or could not be loaded or started. Dispatched on the editor box (listen with the editor: prefix); do not bubble. |
Events
Nothing to show
Customization
Classes on the tag go to the field control; other attributes go to the hidden field. The editor box takes the editor: prefix, and the parts around the field the prefixes of the field props.
Nothing to show
Accessibility
TinyMCE's own: the editing area is an iframe with a labelled body, following the field's aria-describedby and aria-invalid (a Livewire validation error is announced), the toolbar is a WAI-ARIA toolbar (Alt+F10 moves to it), and Alt+0 opens its keyboard help.
Behavior notes
- TinyMCE 8 is loaded from jsDelivr with the
gpllicense key, and its translation fromtinymce-i18n, when the first editor needs them. When the app already putswindow.tinymceon the page, TinyMCE is not requested; thescriptsandstylesof the tag still load, and so does the translation. - The language follows the app's locale; a language with no translation stays in English.
- The skin follows the
darkclass of<html>: when it changes, the editor is created again with the other skin, keeping its content. disabledandreadonlyswitch the editor to read-only mode, also when toggled later.- Inside a Livewire component, when the field is bound (
wire:model, or the automatic binding fromname),valueand the slot are ignored: the bound property is the value. - The HTML the field sends comes from the browser and can hold anything: sanitize it on the server before showing it to other users.