Forms
Editable
Text that turns into a field when clicked: rename a project, a file, a title in place.
Ant Design: Typography editable
import { Editable } from '@alea/ui';
Examples
Rename in place
Click the text; Enter saves, Escape cancels. Names shorter than three letters are refused.
Props
Editable props
Text that turns into a field when clicked: rename in place (Chakra Editable, Ant Typography editable). Enter saves, Escape cancels.
| Prop | Type | Default | Description |
|---|---|---|---|
labelrequired | string | - | What the text is, for screen readers ("Project name"). |
className | string | - | |
defaultValue | string | '' | The text to start with. |
multiline | boolean | - | A text area instead of one line. |
onSave | ((value: string) => boolean | void) | - | Called with the new text when it is saved. Return false to refuse it (stays editing, marked invalid). |
placeholder | string | 'Empty' | Shown while empty. |
value | string | - | The text (controlled). |
Accessibility
- The text is a button named "Label: value. Edit"; the field takes focus and selects the text.
- A refused value keeps the field open and marked invalid; focus returns to the text after saving or cancelling.
Keyboard
| Key | Does |
|---|---|
| Enter or Space (on the text) | Starts editing |
| Enter | Saves (⌘Enter when multiline) |
| Escape | Cancels |
Do and don't
Do
- Use it where people rename things often.
- Return false from onSave to refuse a value.
Don't
- Don't use it for forms with several fields: use a Form.