Ui3nEditable
Inline editable text component. Click on the text to enter edit mode, press Enter or click the checkmark to confirm, press Escape or click the cross to cancel.
Props
| Name | Type | Default | Description |
|---|---|---|---|
id | string | undefined | — | Root element id |
name | string | undefined | — | HTML name attribute for form submission |
modelValue* | string | — | Current value of the editable content |
placeholder | string | undefined | — | Placeholder text |
maxLength | number | undefined | — | Maximum length of the text |
maxWidth | string | number | undefined | — | Maximum width of the component |
tooltipWidth | number | undefined | — | Tooltip width |
disabled | boolean | undefined | — | Component disabled flag |
selectAllOnFocus | boolean | undefined | — | Flag for automatic selection of all text on focus |
disallowEmptyValue | boolean | undefined | — | Flag to prevent empty values |
validator | ((value: string) => string | true) | undefined | — | Check of a changed value on completion: returns true to accept it, or the error text to reject it. A rejected value is reverted to the initial one and the `invalid` event is emitted instead of `update:modelValue` |
Events
| Event Name | Arguments / Value Type | Description |
|---|---|---|
update:modelValue | value: string | — |
done | | — |
cancel | | — |
focusin | value: FocusEvent | — |
focusout | | — |
toggle:editMode | value: boolean | — |
invalid | error: string, value: string | — |
Public Methods & Exposes
| Method Name | Signature / Type | Description |
|---|---|---|
clear() | () => void | Clears the value |
reset() | () => void | Shows the current modelValue again and leaves the edit mode; for a rejection known later, e.g. a failed save |
CSS Variables
Set any of these where you need it — on :root, on a container, or on the element itself through [data-ui3n] — and the component follows. Leave them alone and it uses the defaults below.
| Name | Default |
|---|---|
--ui3n-editable-border-radius | 4px |
--ui3n-editable-button-hover-bg-color | var(--color-bg-button-secondary-hover) |
--ui3n-editable-button-size | 16px |
--ui3n-editable-edit-bg-color | var(--color-bg-control-primary-default, #fff) |
--ui3n-editable-edit-border-color | var(--color-border-table-accent-default) |
--ui3n-editable-edit-border-warning-color | var(--error-content-default) |
--ui3n-editable-empty-color | var(--color-text-table-secondary-default) |
--ui3n-editable-font-size | 12px |
--ui3n-editable-height | 24px |
--ui3n-editable-hover-bg-color | var(--color-bg-control-primary-hover) |
--ui3n-editable-max-width | 100% |
--ui3n-editable-min-width | 60px |
--ui3n-editable-placeholder-color | var(--color-text-table-secondary-default) |
--ui3n-editable-text-color | var(--color-text-table-primary-default) |
Usage Examples
Basic usage
Basic usage
Click on the text to enter edit mode. Press Enter to confirm or Escape to cancel.
Disallow empty value
Disallow empty value
Using disallowEmptyValue prop prevents saving an empty value. The input border turns red when the value is empty.
Disabled state
Disabled state
Disabled component does not allow entering edit mode.
Validation and reverting a rejected value
Validation and reverting a rejected value
The validator prop checks a changed value on completion. A rejected value is reverted and the invalid event is emitted instead of update:modelValue. When a value is rejected later (e.g. saving fails), call the exposed reset() to show the current modelValue again.