CodeEditor

A CodeMirror-backed JSX/JavaScript editor with syntax highlighting, dark/light theming, and Tab-to-indent.

Installation

npx dafink-ui add code-editor

Requires: @uiw/react-codemirror, @codemirror/lang-javascript, @codemirror/autocomplete

Demo

Props

NameTypeDefaultDescription
valuestring-Required. The current code string.
onChange(value: string) => void-Required. Fires with the updated value on every edit.
extensionsExtension[][]Extra CodeMirror extensions layered on top of the built-ins, e.g. a project-specific autocompletion({ override: [...] }) call.
aria-labelstring-Accessible name for the editor region.
classNamestring""Additional Tailwind classes merged onto the root wrapper.
minHeightstring-CSS min-height for the editor surface (e.g. "200px"). Keeps the editor from collapsing to a single line on short content.

Accessibility

CodeMirror gives the editable surface its own role="textbox" and aria-multiline="true" by default, plus whatever aria-label is passed in. This wrapper repurposes Tab for indentation instead of leaving it as the standard way to move focus off the editor, so Escape is the intentional way out: it blurs the editor and returns focus to the surrounding page, avoiding a WCAG 2.1.2 keyboard trap. Everything else (arrow-key caret movement, selection, undo/redo) is CodeMirror's own default keymap, unmodified by this component.

KeyFunction
tabIndents the current line, or accepts the selected autocomplete suggestion if a completion popup is open.
escapeBlurs the editor, returning focus to the surrounding page.