Give the editor a language and a name for screen readers. The editor loads CodeMirror when it mounts.
config-editor.tsx
CodeEditor
<div>| Prop | Type | Default | Description |
|---|---|---|---|
| auto | boolean | false | Focus the text box when the editor is ready. |
| palette | "color""ink""theme" | — | |
| value | string | — | The text (controlled). |
| default | string | — | The text at first (uncontrolled). |
| on | — | Runs on each edit by the user, with the whole text. Not on a value change. | |
| language | string | — | A language name or alias of #/lib/code-editor-languages-model (tsx, json, sh). |
| line | boolean | true | Line numbers in the gutter. Default true. |
| folding | boolean | true | Fold blocks from the gutter, and Cmd/Ctrl+Alt+[ ]. Default true. |
| wrap | boolean | — | Wrap long lines. Default: the Wrap toggle of the Code Block, else false (lines scroll). |
| read | boolean | false | The text can be read, selected, copied, and searched, not changed. |
| disabled | boolean | false | Not focusable and not editable; 50% opacity. |
| placeholder | string | — | The text of an empty editor. |
| tab | number | 2 | Spaces per indent level, and the width of a tab. Default 2. |
| indent | boolean | true | Tab indents and Shift+Tab outdents. Default true. Escape, then Tab, leaves the editor (no keyboard trap, WCAG 2.1.2); the description of the text box says so, and the status row shows it. |
| autocomplete | boolean | true | The completions of the language as you type, and on Ctrl+Space. Default true. |
| search | boolean | true | The find and replace bar on Cmd/Ctrl+F. Default true. |
| lint | LintSource | — | A CodeMirror lint source: its problems show as wavy lines, gutter marks, and tooltips. Keep it stable (a module function or a memo): a new function restarts the linter. |
| extensions | readonly Extension[] | — | More CodeMirror extensions, after the editor's own. Keep the array stable (a module constant or a memo): a new array reconfigures them. |
| name | string | — | The form field name: a hidden input carries the text. |
| form | string | — | The form of the hidden input, by id. |
| required | boolean | false | |
| invalid | boolean | false | The text is wrong: the destructive border and ring, and aria-invalid. |
| labels | Partial<CodeEditorLabels> | — | The words of the editor (CodeEditorLabels in #/lib/code-editor-state). Keep a custom unfold function stable: a new one rebuilds the fold gutter. |
| children | ReactNode | — | Parts after the code, inside the frame: CodeEditorStatus. |
| ...props | <div> attributes | — | Every other attribute goes to the <div>, with a ref. |
CodeEditorStatus
<div>| Prop | Type | Default | Description |
|---|---|---|---|
| ...props | <div> attributes | — | Every other attribute goes to the <div>, with a ref. |
| TaborShiftTab | Indents or outdents the line. With indentWithTab={false}, Tab moves the focus. |
|---|---|
| Escapeorthen Tab | Leaves the editor. |
| ⌘ForCtrlF | Opens the find and replace bar. |
| EnterorShiftEnter | In the find field: goes to the next or the previous match. |
| Escape | In the find bar: closes it and puts focus back in the code. |
| CtrlSpace | Opens the completions of the language. |
| ⌘⌥[orCtrlAlt[ | Folds the block at the cursor. Use ] to unfold it. |
| ⌘ZorCtrlZ | Undoes the last edit. Add Shift to redo. |
Built with
Installs with Code Editor
- Components
- Button,Code,Input Group,Kbd









