Editable Code Block
EditableCodeBlock provides a rich code editing experience with syntax highlighting, line numbers, code folding, and inline error reporting. Built on Monaco Editor (the editor that powers VS Code).Editable Code Block is currently in alpha. The API may change significantly in future releases.
Installation
Usage
JavaScript Code
JSON Editor
With Inline Error
Highlight errors inline with hover messages:Read-Only Mode
Without Line Numbers
With Minimap
Python Code
Props
The programming language for syntax highlighting (e.g., “javascript”, “typescript”, “json”, “python”, “html”, “css”).
The current code content.
Callback fired when the code changes. Receives the new code value.
Show or hide line numbers in the gutter.
Enable code folding (collapsing sections of code).
Make the editor read-only (non-editable).
Show indentation guide lines.
Show a minimap (overview) of the code on the right side.
Allow scrolling beyond the last line of code.
Range object specifying the location of an error in the code.
Hover message(s) to display when hovering over the error range. Set to null to clear the message.
Overrides the default element name for customization.
Supported Languages
EditableCodeBlock supports many programming languages including:- JavaScript / TypeScript
- JSON
- HTML / CSS
- Python
- Java
- C / C++ / C#
- PHP
- Ruby
- Go
- SQL
- Markdown
- And many more
Best Practices
Do
- Use EditableCodeBlock for code input that needs syntax highlighting
- Provide clear labels explaining what code is expected
- Use appropriate language for accurate syntax highlighting
- Show inline errors for validation feedback
- Use read-only mode for code snippets that shouldn’t be edited
- Consider using a minimap for very long code
Don’t
- Don’t use for simple text input (use TextArea instead)
- Don’t use for short single-line code (use Input with type=“text”)
- Don’t forget to handle the onChange callback
- Don’t use without proper validation for user-submitted code
- Don’t enable too many features for simple use cases
Accessibility
- EditableCodeBlock is built on Monaco Editor which has built-in accessibility features
- Keyboard navigation is fully supported
- Screen readers can read code line by line
- Provide clear labels for the editor
- Error messages should be announced to screen readers
- Consider providing alternative ways to input code for users who may have difficulty
Keyboard Shortcuts
EditableCodeBlock inherits Monaco Editor’s keyboard shortcuts:- Ctrl/Cmd + F: Find
- Ctrl/Cmd + H: Find and replace
- Ctrl/Cmd + Z: Undo
- Ctrl/Cmd + Y: Redo
- Tab: Indent
- Shift + Tab: Outdent
- And many more standard editor shortcuts
Performance
- EditableCodeBlock loads Monaco Editor which is a large dependency
- Consider code splitting if not used on initial page load
- For very large files, performance may degrade
- Use read-only mode when editing is not needed to improve performance
Related Components
- Code Block - Display-only code blocks
- Inline Code - Inline code snippets
- TextArea - Multi-line text input