OGE logoOGE

Rich Text Editor API

Every public member of <oge-editor>, its config provider, the reactive-forms validator and the shared command vocabulary. Back to the demos →

Properties Methods Events Types

OgeEditor

oge-editor

Properties 33

Value and forms

Name Type DefaultDescription
valuestring''The sanitized HTML value — two-way ([(value)]). The empty string when the document is empty. An external value is parsed through the editor’s allowlist; the editor ignores its own echo, so the caret and the history survive two-way binding.
disabledbooleanfalseNot editable and out of the Tab order (aria-disabled). Reactive forms’ disable() sets it too.
readonlybooleanfalseFocusable and selectable, but not editable (aria-readonly); every tool is disabled.
requiredbooleanfalseSets aria-required and the asterisk. Validation itself comes from the form (Validators.required, Signal Forms required()).
namestring''Written as data-name on the editing surface.
invalidbooleanfalseExternal invalid override, combined with the forms state.
touched / dirtybooleanfalseSignal Forms contract inputs; errors show once the field is touched.
errorsreadonly OgeFieldError[][]Signal Forms validation errors (bound by [formField]).
maxLengthnumber | undefinedundefinedMost characters (grapheme clusters) of text the document may hold. Typing and pasting stop there (announced), the counter shows the budget, and a longer external value shows the error.

Chrome

Name Type DefaultDescription
labelstring''Visible label above the editor; also its accessible name (aria-labelledby).
ariaLabelstring | undefinedundefinedAccessible name when there is no visible label; falls back to messages.editorLabel.
placeholderstring''Shown while the document is empty; also aria-placeholder.
hintstring | undefinedundefinedHelper text under the editor, hidden while an error shows; part of aria-describedby.
errorTextstring | undefinedundefinedExplicit error message — always wins over the resolved messages.
counter'none' | 'characters' | 'words' | 'both''none'Character / word counter under the editor (ICU plurals from messages.counter). With maxLength the character count reads 12 / 200.
toolbarreadonly OgeEditorToolbarEntry[] | false | undefinedundefinedToolbar entries: built-in tool names, 'separator' and OgeEditorCustomTool objects. undefined is the full default toolbar, false hides it.
toolbarOverflow'menu' | 'scroll' | 'wrap' | 'extended' | 'none''menu'What the toolbar does with tools that do not fit (the layout toolbar’s overflow).
height / minHeight / maxHeightnumber | string | undefinedundefinedSize of the editing area — a number is px, a string any CSS length. Without them the area starts at 160px and grows with its content.
resizablebooleanfalseAdds a vertical resize handle to the editing area.
spellcheckbooleantrueThe browser’s spell checking on the editing surface.
tabIndexnumber0Tab index of the editing surface.
autofocusbooleanfalseFocuses the editor after its first render.
idstring | undefinedundefinedBase of the generated element ids (content, label, hint, error, counter).

Behaviour (undefined = config)

Name Type DefaultDescription
markdownShortcutsboolean | undefinedtrue# …###### , - , 1. , > , ``` at the start of a paragraph and --- + Enter turn into formats. One undo brings the typed characters back.
pasteMode'html' | 'text' | undefined'html''html' keeps (sanitized) formatting from the clipboard; 'text' inserts text only.
headingLevelsreadonly OgeEditorHeadingLevel[] | undefined[1, 2, 3, 4]Heading levels the block-format menu offers.
textColors / backgroundColorsOgeColorPalettePreset | readonly string[] | undefined'default'Palettes of the two colour popups — an @oge-ui/inputs palette preset or your own colour list. Colours are validated (no url(), var() or expressions).
allowedSchemesreadonly string[] | undefined[]Extra link schemes on top of sanitizeUrl’s allowlist (http, https, mailto, tel, ftp, sms). Script schemes can never be allowed.
allowDataImagesboolean | undefinedfalseKeep data:image/* sources (PNG, JPEG, GIF, WebP, AVIF, BMP — never SVG). blob: and file: images are always dropped.
messagesOgeEditorMessagesInput | undefinedundefinedPer-instance overrides of the user-facing strings, merged group by group over the config.

Read-only state

Name Type DefaultDescription
activeStateSignal<OgeEditorActiveState>—The formats under the selection — what the toolbar shows (marks, block format, list, alignment, link, colours).
characterCount / wordCountSignal<number>—Grapheme clusters and words (Intl.Segmenter) of the text.
canUndo / canRedoSignal<boolean>—Whether the history has a step back / forward.

Methods 14

Name Type Description
focus()voidMoves focus into the editing area and restores the caret.
blur()voidRemoves keyboard focus.
exec(command)(command: OgeEditorCommandName | OgeEditorCommand) => booleanRuns a command — a name ('bold', 'heading2', 'bulletList'…) or a command object ({ type: 'color', color: '#c00' }). Returns true when it changed something.
undo() / redo()() => booleanSteps through the editor’s own history.
insertText(text)(text: string) => voidInserts plain text at the selection (newlines become paragraphs).
insertHtml(html)(html: string) => voidInserts HTML at the selection — parsed through the editor’s allowlist first, like a paste.
insertLink(href, text?, newTab?)(href: string, text?: string, newTab?: boolean) => booleanLinks the selection, or inserts text (default: the address) as a link. Unsafe addresses are refused (false); new-tab links get rel="noopener noreferrer".
removeLink()() => booleanRemoves the link under the selection or around the caret.
insertImage(src, alt?)(src: string, alt?: string) => booleanInserts an image by URL; unsafe sources are refused.
selectAll()voidSelects the whole document.
getHtml() / getText()() => stringThe current value, or its text with blocks separated by newlines.
clear()voidEmpties the editor as one undoable change.
reset(value?)(value?: string) => voidLoads value (default: empty), clears the history and the touched / dirty state; on a reactive-forms binding it resets the control.
openLinkDialog() / openImageDialog()() => Promise<void>Opens the link or image prompt for the selection (also Ctrl+K and the toolbar tools), subject to dialogOpening.

Events 8

Name Type Description
valueCommittedOgeEditorValueCommittedEventEvery committed change: { value, previousValue, event }.
focused / blurredOgeEditorFocusEventFocus entered or left the editor (popups included).
touchvoidSignal Forms FormValueControl contract — once per blur.
selectionChangedOgeEditorSelectionChangedEventThe selection moved or its formats changed: { active }.
commandExecutedOgeEditorCommandExecutedEventA command ran (keyboard, toolbar or exec): { command, event }.
toolClickOgeEditorToolClickEventA toolbar tool was activated: { key, inMenu, event }.
pastingOgeEditorPastingEventCancelable: a paste or drop is about to be inserted. Set cancel, or rewrite html / text.
dialogOpeningOgeEditorDialogOpeningEventCancelable: the link or image dialog is about to open ({ kind, link, cancel }). Cancel it to show your own dialog, then call insertLink() / insertImage().

Types 15

Name Type Description
OgeEditorToolName'undo' | 'redo' | 'blockFormat' | 'bold' | 'italic' | 'underline' | 'strike' | 'code' | 'subscript' | 'superscript' | 'textColor' | 'backgroundColor' | 'link' | 'unlink' | 'image' | 'bulletList' | 'orderedList' | 'indent' | 'outdent' | 'blockquote' | 'codeBlock' | 'horizontalRule' | 'alignStart' | 'alignCenter' | 'alignEnd' | 'alignJustify' | 'directionLtr' | 'directionRtl' | 'clearFormatting'Built-in toolbar tools. OGE_DEFAULT_EDITOR_TOOLBAR is the default arrangement.
OgeEditorToolbarEntryOgeEditorToolName | 'separator' | OgeEditorCustomToolOne toolbar entry. Leading, trailing and doubled separators are dropped.
OgeEditorCustomTool{ key; text; icon?; hint?; shortcut?; isActive?(active); isDisabled?(active); run(context: OgeEditorToolContext) }A tool of your own. isActive makes it a toggle (aria-pressed); run receives exec, insertHtml, insertText, getHtml and the active state.
OgeEditorCommandName'bold' | 'italic' | … | 'heading1'…'heading6' | 'blockquote' | 'codeBlock' | 'bulletList' | 'orderedList' | 'indent' | 'outdent' | 'alignStart' | 'alignCenter' | 'alignEnd' | 'alignJustify' | 'horizontalRule' | 'clearFormatting' | 'unlink' | 'undo' | 'redo' | 'selectAll'Parameterless commands by name, for exec().
OgeEditorCommand{ type: 'toggleMark'; mark } | { type: 'blockFormat'; format; level? } | { type: 'list'; list } | { type: 'align'; align } | { type: 'color' | 'background'; color } | { type: 'link'; href; text?; newTab? } | { type: 'image'; src; alt? } | …A command object — the same vocabulary the toolbar and the keyboard map issue.
OgeEditorActiveState{ marks; blockFormat; list; align; dir; link; color; background; canIndent; canOutdent; collapsed }What the selection currently is.
OgeEditorMessagesinterfaceEvery user-facing string: tool names, block names, dialogs, colours, counter (ICU plurals), announcements, validation and key names. Translated in all ten @oge-ui/locales packs.
provideOgeEditorConfig(config)(config: OgeEditorConfigInput | (() => OgeEditorConfigInput)) => ProviderApp- or route-wide defaults and strings; a function makes them live.
ogeEditorMaxLength(max)(max: number, options?: OgeEditorParseOptions) => ValidatorFnReactive-forms validator that counts the text of the HTML value — Validators.maxLength would count the markup. Reports { ogeEditorMaxLength: { max, actual } }.
ogeSanitizeEditorHtml(html, options?)(html: string | null | undefined, options?: OgeEditorParseOptions) => stringThe editor’s allowlist as a function — for values that did not come through the editor. Only the editor’s own tags and attributes come out. Works on a server too: without DOMParser the editor’s own tokenizer reads the markup (the same one that server-renders the editing surface).
ogeEditorHtmlLength(html)(html: string | null | undefined, options?: OgeEditorParseOptions) => numberCharacters of an HTML value’s text — the measure maxLength applies.
ogeEditorCommandFromName(name)(name: OgeEditorCommandName) => OgeEditorCommandExpands a command name into its command object.
OGE_EDITOR_TRUSTED_TYPES_POLICY'oge-ui#editor'Name of the Trusted Types policy behind the editor’s one DOMParser call. List it in a trusted-types CSP directive.
OGE_EDITOR_CONFIG / OGE_DEFAULT_EDITOR_CONFIG / OGE_DEFAULT_EDITOR_MESSAGESInjectionToken<OgeEditorConfig> / OgeEditorConfig / OgeEditorMessagesThe config token every editor reads, and the shipped defaults.
OGE_DEFAULT_EDITOR_TOOLBARreadonly OgeEditorToolbarEntry[]The default toolbar arrangement — spread it to extend the default instead of replacing it.