Skip to content

Code Editor

Forms

A multi-line code editor with syntax highlighting, line numbers and undo history, themed with Atlas tokens and integrated with Signal Forms. The editing engine is pluggable: Atlas ships a CodeMirror 6 engine and you can swap it for another one without touching the components that use the editor.

atlas-code-editor

Examples

Large editor

A full-size editor on its own: pick the language, toggle line numbers and wrapping. Tab moves focus out; turn on "Tab indents" and Ctrl+M (Shift+Alt+M on macOS) switches Tab back to focus navigation.

Edit freely; nothing is saved.

9 lines · 199 characters

Read-only and disabled

A read-only editor stays focusable, so the text can be selected and copied; a disabled one takes no focus or input.

API

Generated from the library source, so it always matches the code.

AtlasCodeEditorComponent atlas-code-editor

InputTypeDefaultDescription
value two-waystring'' The text (two-way bindable).
language AtlasCodeEditorLanguage'plain' Language to highlight. The default engine knows 'plain' and 'json' .
placeholder string'' Text shown while the editor is empty. Not a label: name the editor with a label or ariaLabel .
lineNumbers booleantrue Show the line-number gutter.
lineWrapping booleanfalse Wrap long lines instead of scrolling horizontally.
indentWithTab booleanfalse Tab indents instead of moving focus. Off by default so keyboard users are never trapped; when on, Ctrl+M (Shift+Alt+M on macOS) switches Tab back to moving focus.
disabled booleanfalse Whether the editor is disabled (not focusable, no input).
errors readonly ValidationError.WithOptionalFieldTree[][] Validation errors of the bound field. Set by Signal Forms [field] .
required booleanfalse Whether a value is required. Set by Signal Forms [field] .
invalid booleanfalse Whether the field is invalid. Set by Signal Forms [field] .
touched booleanfalse Whether the user has interacted with the field. Set by Signal Forms [field] .
readonly booleanfalse Whether the text is read-only (still focusable and selectable). Set by Signal Forms [field] .
pending booleanfalse Whether async validation is running. Set by Signal Forms [field] .
name string'' Name of the field. Set by Signal Forms [field] .
ariaLabel string | nullnull Accessible name when no visible label names the editor (use one or the other, WCAG 2.5.3).
inputId string | undefinedundefinedid of the text surface. Inside atlas-form-field the field supplies one.
ariaDescribedBy string | nullnull Extra ids for aria-describedby , merged with the surrounding form field's hint or error.
class string'' Extra CSS classes on the editor box (set its height here, e.g. h-80 ); yours win on conflicts.
OutputPayloadDescription
touchvoid Emits when the editor loses focus, so Signal Forms marks the field touched.

Functions

FunctionDescription
provideAtlasCodeEditorEngine(engine: AtlasCodeEditorEngine): EnvironmentProviders Replaces the editing engine for the app (or a route's environment injector).

Types

AtlasCodeEditorAttributes

Attributes the engine puts on its focusable text surface (the element with role="textbox" ): id , aria-label , aria-labelledby , aria-describedby , aria-invalid , aria-required , aria-readonly , aria-disabled . Absent keys are removed.

type AtlasCodeEditorAttributes = Readonly<Record<string, string>>

AtlasCodeEditorCreateOptions

Everything an engine needs to create one editor.

Extends AtlasCodeEditorSettings

PropertyTypeDescription
value string Initial text.
onChange (value: string): void Called with the full text after every user edit (not after setValue ).
onBlur (): void Called when the text surface loses focus.

AtlasCodeEditorEngine

The editing engine behind atlas-code-editor . Atlas ships a CodeMirror 6 engine; provide another one (Monaco, a plain textarea…) with provideAtlasCodeEditorEngine() without touching the components that use the editor.

PropertyTypeDescription
create (host: HTMLElement, options: AtlasCodeEditorCreateOptions): AtlasCodeEditorInstance Creates an editor inside host (an empty element the component owns). Browser only.

AtlasCodeEditorInstance

One live editor created by an engine.

PropertyTypeDescription
setValue (value: string): void Replaces the text without calling onChange . A no-op when the text is unchanged.
update (settings: Partial<AtlasCodeEditorSettings>): void Applies changed settings.
focus (): void Moves focus to the text surface.
destroy (): void Removes the editor and its listeners.

AtlasCodeEditorLanguage

Language the editor highlights. The default CodeMirror engine knows 'plain' and 'json' ; an engine treats a name it does not know as plain text.

type AtlasCodeEditorLanguage = 'plain' | 'json' | (string & {})

AtlasCodeEditorSettings

Settings the editor can change after creation.

PropertyTypeDescription
language AtlasCodeEditorLanguage —
readonly boolean The text can be selected and copied, not changed. Stays focusable.
disabled boolean The editor takes no input and is not focusable.
lineNumbers boolean —
lineWrapping boolean —
indentWithTab boolean Tab indents instead of moving focus. The engine must keep a keyboard way out (WCAG 2.1.2): the CodeMirror engine toggles Tab back to focus navigation with Ctrl+M (Shift+Alt+M on macOS).
placeholder string —
attributes AtlasCodeEditorAttributes —