Html Area
<et2-htmlarea> | Et2HtmlArea
Rich text editor widget built on TinyMCE’s web component.
Et2HtmlArea provides both rich text and plain text editing modes, integrates with EGroupware
upload and language preferences, and exposes a small extension surface for editor-specific integrations such
as custom toolbar buttons.
Examples
Toolbar Mode vs Preference
The mode property controls whether the editor uses one of the built-in toolbar presets or the
user’s rte_toolbar preference.
mode="simple"uses the simple presetmode="extended"uses the extended presetmode="advanced"uses the advanced presetmode="ascii"renders a plain textarea- empty
modeuses therte_toolbarpreference
If you want the editor to follow the user’s selected toolbar features, leave mode empty.
<et2-htmlarea label="Preference-driven toolbar"></et2-htmlarea>
If you need a fixed toolbar regardless of the user preference, set mode explicitly.
<et2-htmlarea label="Simple preset" mode="simple"></et2-htmlarea>
To hide the toolbar entirely, use noToolbar.
<et2-htmlarea label="No toolbar" noToolbar></et2-htmlarea>
Plain Text Mode
mode="ascii" renders a textarea instead of TinyMCE when editable, while preserving the same
value, disabled, placeholder, focus, input, and change contracts as rich text mode.
<et2-htmlarea label="Plain text" mode="ascii" placeholder="Enter plain text"></et2-htmlarea>
Readonly Rendering
Readonly htmlareas render their value directly instead of initializing TinyMCE or a textarea. Rich text
values are rendered as HTML; mode="ascii" values are rendered as literal text.
The lightweight et2-htmlarea_ro element is registered for readonly widget substitution,
including nextmatch detached row updates.
File Selection And Uploads
Dropped and pasted images upload through EGroupware’s HTMLArea upload endpoint by default. Set
image-upload to a VFS target widget id, content path, absolute path, or external URL when the
upload destination needs to be explicit.
TinyMCE’s image, media, and file dialogs use the EGroupware VFS picker unless a custom
filePickerCallback property is assigned.
Submit-time Formatting
Set apply-default-font when saved markup needs to carry the user’s preferred font and size
inline, such as mail compose content that may be read by clients that strip editor CSS. The normalization
happens during getValue(true), so it affects submitted rich-text content rather than the live
editor appearance.
Custom Toolbar Buttons
Integrations can extend the TinyMCE toolbar without reaching through the legacy
editor property. Add the toolbar item name with addToolbarItem(), then register
the TinyMCE UI in registerEditorSetupHook(). TinyMCE documents the available toolbar button
APIs in its
custom toolbar buttons documentation.
The hook must be registered before TinyMCE finishes initializing. If an integration wraps or creates the
htmlarea, call these methods as soon as the Et2HtmlArea instance is available.
import type {Et2HtmlArea} from "./Et2HtmlArea";
function addInsertGreetingButton(htmlarea : Et2HtmlArea)
{
htmlarea.addToolbarItem("insertGreeting");
htmlarea.registerEditorSetupHook("example-greeting-button", editor =>
{
editor.ui.registry.addButton("insertGreeting", {
text: "Greeting",
tooltip: "Insert greeting",
onAction: () =>
{
editor.insertContent("<p>Hello</p>");
}
});
});
}
Use a stable, integration-specific key for registerEditorSetupHook() so it can be replaced or
removed later with unregisterEditorSetupHook(). The toolbar item name passed to
addToolbarItem() must match the TinyMCE control name registered with
editor.ui.registry.
Legacy Compatibility
The component keeps a small compatibility bridge while older integrations move off direct TinyMCE access:
tinymceresolves with the TinyMCE editor arrayeditorexposes the active TinyMCE editor-
file_picker_callback,images_upload_handler,valid_children, andtoolbar_modemap to their modern camelCase properties
New integrations should prefer the component properties plus addToolbarItem() and
registerEditorSetupHook() for editor UI extensions.
Slots
| Name | Description |
|---|---|
label
|
The editor’s label. Alternatively, use the label attribute. |
help-text
|
Text that describes how to use the editor. Alternatively, use the statustext attribute.
|
Learn more about using slots.
Properties
| Name | Description | Reflects | Type | Default |
|---|---|---|---|---|
accesskey
|
Accesskey provides a hint for generating a keyboard shortcut for the current element. The attribute value must consist of a single printable character. |
|
string
|
- |
actions
|
Set Actions on the widget Each action is defined as an object: move: { type: “drop”, acceptedTypes: “mail”, icon: “move”, caption: “Move to” onExecute: javascript:mail_move” } This will turn the widget into a drop target for “mail” drag types. When “mail” drag types are dropped, the global function mail_move(egwAction action, egwActionObject sender) will be called. The ID of the dragged “mail” will be in sender.id, some information about the sender will be in sender.context. The etemplate2 widget involved can typically be found in action.parent.data.widget, so your handler can operate in the widget context easily. The location varies depending on your action though. It might be action.parent.parent.data.widget To customise how the actions are handled for a particular widget, override _link_actions(). It handles the more widget-specific parts. |
object
|
- | |
align
|
Used by Et2Box to determine alignment. Allowed values are left, right |
|
string
|
- |
applyDefaultFont
apply-default-font
|
Force default font and size as style attribute into the markup. Also ensures all non-block elements are wrapped in p. Use this when users really want the font & size (email). |
boolean
|
false
|
|
autofocus
|
Have browser focus this input on load. Overrides etemplate2.focusOnFirstInput(), use only once per page https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attributes |
|
boolean
|
- |
class
|
CSS Class. This class is applied to the outside, on the web component itself. Due to how WebComponents work, this might not change anything inside the component. |
|
string
|
- |
data
|
Set the dataset from a CSV |
string
|
- | |
deferredProperties
|
Any attribute that refers to row content cannot be resolved immediately, but some like booleans cannot stay a string because it’s a boolean attribute. We store them for later, and parse when they’re fully in their row. If you are creating a widget that can go in a nextmatch row, and it has boolean attributes that can change for each row, add those attributes into deferredProperties | - | - | |
disabled
|
Defines whether this widget is visibly disabled. The widget is still visible, but clearly cannot be interacted with. Widgets disabled in the template will not return a value to the application code, even if re-enabled via javascript before submitting. To allow a disabled widget to be re-enabled and return a value, disable via javascript in the app’s et2_ready() instead of an attribute in the template file. |
|
boolean
|
false
|
dom_id
|
Get the actual DOM ID, which has been prefixed to make sure it’s unique. |
string
|
- | |
filePickerCallback
|
Callback function to get called when file picker is clicked. |
TinyMceFilePickerCallback | null
|
null
|
|
hasFeedbackFor
|
Get a list of feedback types |
string[]
|
- | |
height
|
Height. Applied to the widget host by Et2Widget; the editor fills the host and does not
mirror this into TinyMCE’s own sizing config.
|
string
|
""
|
|
hidden
|
The widget is not visible. As far as the user is concerned, the widget does not exist. Widgets hidden with an attribute in the template may not be created in the DOM, and will not return a value. Widgets can be hidden after creation, and they may return a value if hidden this way. |
|
boolean
|
- |
id
|
Get the ID of the widget |
string
|
- | |
imagesUploadHandler
|
Callback function for handling image upload. |
TinyMceUploadHandler | null
|
null
|
|
imageUpload
image-upload
|
URL to upload dragged or pasted images, or the id of a link_to-style widget whose VFS path should receive the upload. |
string
|
""
|
|
label
|
The label of the widget Legacy support for labels with %s that get wrapped around the widget Not the best way go with webComponents - shouldn’t modify their DOM like this |
string
|
- | |
mode
|
One of {ascii|simple|extended|advanced}.
simple, extended, and advanced force built-in toolbar presets
and do not use the rte_toolbar preference. Leave mode empty to use the user
preference-driven toolbar.
|
HtmlAreaMode | string
|
""
|
|
noLang
|
Disable any translations for the widget |
boolean
|
- | |
noMenubar
no-menubar
|
Disables the menubar at the top of the editor. |
boolean
|
false
|
|
noStatusbar
no-statusbar
|
Disables the status bar on the bottom of the editor. The status bar is off by default. Set
no-statusbar="false" in modern usage, or statusbar="true" in legacy
templates, to enable it.
|
boolean
|
true
|
|
noToolbar
no-toolbar
|
Disables the toolbar at the top of the editor. |
boolean
|
false
|
|
parentId
|
Parent is different than what is specified in the template / hierarchy. Widget ID of another node to insert this node into instead of the normal location |
string
|
- | |
placeholder
|
Placeholder text shown when the editor is empty. |
string
|
""
|
|
statustext
|
Tooltip which is shown for this element on hover |
|
string
|
- |
styles
|
WebComponent * | - | - | |
toolbarMode
toolbar-mode
|
Controls how toolbar items are shown when space is limited. |
"floating" | "sliding" | "scrolling" | "wrap"
|
"sliding"
|
|
translate
|
List of properties that get translated Done separately to not interfere with properties - if we re-define label property, labels go missing. | - | - | |
validChildren
valid-children
|
Enables to control what child tag is allowed or not allowed of the present tag. For instance: +body[style], makes style tag allowed inside body. |
string
|
"+body[style]"
|
|
value
|
The value of the widget. |
string
|
""
|
|
width
|
Width. Applied to the widget host by Et2Widget; the editor fills the host and does not
mirror this into TinyMCE’s own sizing config.
|
string
|
""
|
|
_menubar
|
Menubar visibility is still subject to the legacy user preference. The TinyMCE web component parses
menubar as false | string, not a boolean. When enabled, provide the
default menu list explicitly instead of the string "true", which TinyMCE interprets as
a menu named true.
|
string | false
|
- | |
_requestedToolbarSetting
|
Toolbar selection comes from the user preference when mode is not fixed. The modern component API
only supports explicit disable via noToolbar.
|
string
|
- | |
editor
|
Compatibility bridge: legacy callers expect direct access to the editor instance.
New integrations should add explicit component APIs instead. |
TinyMceEditor | null
|
- | |
file_picker_callback
|
Compatibility bridge: TinyMCE callback surface retained for migration.
Replace with explicit component APIs where possible. |
TinyMceFilePickerCallback | null
|
- | |
images_upload_handler
|
Compatibility bridge: legacy TinyMCE callback surface retained for migration.
Replace with explicit component APIs where possible. |
TinyMceUploadHandler | null
|
- | |
needed
|
Compatibility for deprecated name “needed”
use required instead |
- | - | |
options
|
Get property-values as object
use widget methods |
object
|
- | |
supportedWidgetClasses
|
et2_widget compatability
Legacy compatability. Some legacy widgets check their parent to see whats allowed |
array
|
[]
|
|
tinymce
|
Compatibility bridge: legacy integrations still expect a tinymce promise resolving like
tinymce.init().
New integrations should use the component instance directly. |
Promise
|
new Promise(resolve => { this._resolveTinymce = resolve; })
|
|
toolbar_mode
|
Compatibility bridge for legacy snake_case property naming.
Use toolbarMode. |
string
|
- | |
valid_children
|
Compatibility bridge for legacy snake_case property naming.
Use validChildren. |
string
|
- | |
updateComplete |
A read-only promise that resolves when the component has finished updating. |
Learn more about attributes and properties.
Events
| Name | React Event | Description | Event Detail |
|---|---|---|---|
focus |
Emitted when the editor receives focus. |
FocusEvent
|
|
blur |
Emitted when focus leaves the editor, including TinyMCE chrome and dialogs. |
FocusEvent
|
|
input |
Emitted when user input changes the editor value. |
Event
|
|
change |
Emitted when the user commits an editor value change. |
Event
|
Learn more about events.
Methods
| Name | Description | Arguments |
|---|---|---|
addToolbarItem()
|
Append a toolbar item to the computed toolbar for integrations that extend the editor UI before TinyMCE initializes. |
item: string
|
checkCreateNamespace()
|
Checks whether a namespace exists for this element in the content array. If yes, an own perspective of the content array is created. If not, the parent content manager is used. Constructor attributes are passed in case a child needs to make decisions | - |
clone()
|
Creates a copy of this widget. |
_parent: et2_widget
|
createElementFromNode()
|
Create a et2_widget from an XML node. First the type and attributes are read from the node. Then the readonly & modifications arrays are checked for changes specific to the loaded data. Then the appropriate constructor is called. After the constructor returns, the widget has a chance to further initialize itself from the XML node when the widget’s loadFromXML() method is called with the node. |
_node: , _name:
|
et2HandleBlur()
|
If the value is unchanged, put any held validation messages back Named et2HandleBlur to avoid overwriting handleBlur() in Shoelace components |
event: FocusEvent
|
et2HandleFocus()
|
When input receives focus, clear any validation errors. If the value is the same on blur, we’ll put them back The ones from the server (ManualMessage) can interfere with submitting. Named et2HandleFocus to avoid overwriting handleFocus() in Shoelace components |
_ev: FocusEvent
|
getArrayMgr()
|
Returns the array manager object for the given part |
managed_array_type: string
|
getArrayMgrs()
|
Returns an associative array containing the top-most array managers. |
_mgrs: object
|
getChildren()
|
Get child widgets Use |
- |
getInputNode()
|
Get input to e.g. set aria-attributes | - |
getInstanceManager()
|
Returns the instance manager | - |
getPath()
|
Returns the path into the data array. By default, array manager takes care of this, but some extensions need to override this | - |
getRoot()
|
Returns the base widget Usually this is the same as getInstanceManager().widgetContainer | - |
getValue()
|
Serialize the widget value, optionally normalizing rich-text content for submit. Mail clients often strip editor-level CSS, so users expect their preferred font and size to survive in the markup itself. This is not ideal, but it is easier to do here before submit than to do it server-side. |
submit_value: boolean
|
handleSlChange()
|
Handle sl-change event from Shoelace components and dispatch a change event so anything listening for change events can react to it instead of having to listen for both sl-change and change. |
event:
|
isValid()
|
Used by etemplate2 to determine if we can submit or not |
messages:
|
loadFromXML()
|
Loads the widget tree from an XML node |
_node:
|
loadingFinished()
|
Needed for legacy compatability. |
promises: Promise[]
|
parseXMLAttrs()
|
The parseXMLAttrs function takes an XML DOM attributes object and adds the given attributes to the _target associative array. This function also parses the legacyOptions. N.B. This is only used for legacy widgets. WebComponents use transformAttributes() and do their own handling of attributes. |
_attrsObj: , _target: object, _proto: et2_widget
|
registerEditorSetupHook()
|
Register a TinyMCE setup hook for integrations that need to add custom UI such as toolbar buttons before the editor finishes initializing. |
key: string, hook: TinyMceSetupHook
|
set_label()
|
NOT the setter, since we cannot add to the DOM before connectedCallback() TODO: This is not best practice. Should just set property, DOM modification should be done in render https://lit-element.polymer-project.org/guide/templates#design-a-performant-template |
value: string
|
setArrayMgr()
|
Sets the array manager for the given part |
_part: string, _mgr: object
|
setArrayMgrs()
|
Sets all array manager objects - this function can be used to set the root array managers of the container object. |
_mgrs: object
|
setInstanceManager()
|
Set the instance manager Normally this is not needed as it’s set on the top-level container, and we just return that reference |
manager: etemplate2
|
submit()
|
Called whenever the template gets submitted. We return false if the widget is not valid, which cancels the submission. |
_values:
|
unregisterEditorSetupHook()
|
Remove a previously registered TinyMCE setup hook. |
key: string
|
validate()
|
Massively simplified validate, as compared to what ValidatorMixin gives us, since ValidatorMixin extends FormControlMixin which breaks SlSelect’s render() We take all validators for the widget, and if there’s a value (or field is required) we check the value with each validator. For array values we check each element with each validator. If the value does not pass the validator, we collect the message and display feedback to the user. We handle validation errors from the server with ManualMessages, which always “fail”. If the value is empty, we only validate if the field is required. |
skipManual:
|
_applyDefaultFontToContent()
|
Inline the preferred font and size on saved content for mail workflows. | - |
_ensurePopupSinkStyles()
|
TinyMCE’s web component renders the popup sink inside its own shadow root. In split mode that sink still participates in tab-panel scrolling unless we force it out of layout flow. | - |
_filePickerMeta()
|
Provide TinyMCE with the metadata it expects for the selected VFS file. |
file: FileInfo | undefined, meta: Parameters<TinyMceFilePickerCallback>[2]
|
_get_action_links()
|
Get all action-links / id’s of 1.-level actions from a given action object This can be overwritten to not allow all actions, by not returning them here. |
actions:
|
_getImageUploadUrl()
|
Resolve the TinyMCE image upload URL. When imageUpload points at a
link_to-style widget or content-path value, the upload endpoint needs the current
request id and widget id so the server can store the file in the right VFS location. Without
imageUpload, use the plain endpoint so TinyMCE can still upload dropped or pasted
images.
|
- |
_getTinyMceConfig()
|
Build the TinyMCE config from the component’s current state. Keep this bridge limited to TinyMCE
options that the web component cannot reliably express as simple HTML attributes.
Attribute-supported options are rendered directly in _renderEditor() so there is a
single source of truth for the visible editor chrome.
|
- |
_handleAsciiChange()
|
Re-emit textarea change events through the widget host. | - |
_handleAsciiInput()
|
Keep textarea mode aligned with the widget value contract. |
event: Event
|
_handleClick()
|
Click handler calling custom handler set via onclick attribute to this.onclick |
_ev: MouseEvent
|
_handleFilePickerCallback()
|
Route TinyMCE’s file picker through a custom override when provided, or through the default EGroupware VFS picker otherwise. |
callback: Parameters<TinyMceFilePickerCallback>[0], value:
Parameters<TinyMceFilePickerCallback>[1], meta:
Parameters<TinyMceFilePickerCallback>[2]
|
_handleTinyMceSetup()
|
Attach TinyMCE event handlers and bridge them onto the host widget API. |
editor: TinyMceEditor
|
_hasInternalFocus()
|
Check whether focus is still logically inside the widget, including TinyMCE’s iframe, menus, and shadow-host transitions. | - |
_labelTemplate()
|
Common sub-template to add a label. This goes inside the form control wrapper div, before and at the same depth as the input controls. | - |
_link_actions()
|
Link the actions to the DOM nodes / widget bits. |
actions: object
|
_oldChange()
|
Change handler calling custom handler set via onchange attribute |
_ev: Event
|
_openDefaultFilePicker()
|
Open EGroupware’s VFS picker for TinyMCE’s image, media, and generic file dialogs. This restores the legacy browse workflow while keeping the callback override available as an explicit escape hatch. |
callback: Parameters<TinyMceFilePickerCallback>[0], meta:
Parameters<TinyMceFilePickerCallback>[2]
|
_publishCallbacks()
|
Publish callback paths for TinyMCE web-component options that are supported as global-path
attributes, such as setup and images_upload_handler.
|
- |
_publishConfig()
|
Publish the current editor config through the global bridge required by TinyMCE’s web component. Why
this exists: The installed @tinymce/tinymce-webcomponent reads config from
an HTML attribute and interprets its value as a global object path. It does not expose a
property-based config API we can bind directly from Lit. Lifecycle: - on every render, we overwrite
this instance’s entry with the latest computed config - the returned string is passed to
<tinymce-editor config="..."> - on disconnect,
_removePublishedConfig() removes the stale entry Scope: The bridge is intentionally
isolated to this one helper so the rest of the component can continue to work with normal local
config objects.
|
- |
_queueHostBlur()
|
Delay host blur long enough to ignore TinyMCE’s internal focus transitions. | - |
_raiseDialogAboveTinyMce()
|
TinyMCE dialogs stack above Shoelace’s default dialog z-index. Raise only this transient VFS picker instance so it can sit above the active Insert/edit image/media/file dialog without changing global dialog layering. |
dialog: Et2VfsSelectDialog
|
_removePublishedCallbacks()
|
Remove this instance’s published callback bridge on disconnect. | - |
_removePublishedConfig()
|
Remove this instance’s published config when the component disconnects. TinyMCE resolves the config lazily from the global path string, so stale entries would otherwise accumulate across component lifecycles. | - |
_renderEditor()
|
Render the active editor implementation for the current mode. | - |
_set_label()
|
Do some fancy stuff on the label, splitting it up if there’s a %s in it Normally called from updated(), the “normal” setter stuff has already been run before this is called. We only override our special cases (%s) because the normal label has been set by the parent |
value: string
|
_setAriaAttributes()
|
Set aria-attributes on our input node | - |
_syncValueFromEditor()
|
Mirror editor content into the widget value and emit host input/change events. |
dispatchChange: boolean
|
_syncValueToEditor()
|
Push the current widget value into the active editor implementation. | - |
_wrapTextNodes()
|
Wrap loose text and inline nodes in paragraphs so default block styling can be written into the saved markup. | - |
destroy()
|
et2_widget compatability
true |
- |
set_class()
|
Set the widget class
Use this.class or this.classList instead |
new_class: string
|
set_disabled()
|
Wrapper on this.disabled because legacy had it.
Use widget.disabled for visually disabled, widget.hidden for visually hidden. Disabled vs Readonly vs Hidden |
value: boolean
|
set_statustext()
|
supports legacy set_statustext
use this.statustext |
value: string
|
Learn more about methods.
Parts
| Name | Description |
|---|---|
form-control |
The form control wrapper containing label, editor, and help text. |
form-control-input |
The editor wrapper. |
readonly-content |
The readonly value container when readonly is set. |
Learn more about customizing CSS parts.