Skip to content
Alea0.1

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.

PropTypeDefaultDescription
labelrequiredstring-What the text is, for screen readers ("Project name").
classNamestring-
defaultValuestring''The text to start with.
multilineboolean-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).
placeholderstring'Empty'Shown while empty.
valuestring-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

KeyDoes
Enter or Space (on the text)Starts editing
EnterSaves (⌘Enter when multiline)
EscapeCancels

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.
Tested with axe, keyboard and screen reader roles