Editable

Text that turns into an input when the user clicks it, so they can change it in place.

Click to edit

Usage

Code
import { Editable } from '@leverui/components';
Code
<Editable.Root>
  <Editable.Preview />
  <Editable.Input />
</Editable.Root>

Examples

Double Click

Use the activationMode prop to make the content editable when users double click.

Double click to edit

Disabled

Use the disabled prop to disable the editable component.

Click to edit

Textarea

You can make a text area editable.

Click to edit

With Controls

Add controls such as "edit", "cancel" and "submit" to Editable for better user experience.

Click to edit

Controlled

Use the value and onValueChange props to control the editable component.

Click to edit

Store

An alternative way to control the editable component is to use the RootProvider component and the useEditable store hook. This way you can access the editable state and methods from outside the editable.

Click to edit
not editing

Guides

Multiline editing

Use Textarea in place of Input. It renders a native textarea.

State and validation

onValueChange, onValueCommit, and onValueRevert get the details of the change. disabled, readOnly, and required pass to the native input or textarea.

Caller-owned machine

Call useEditable inside a Solid owner, such as a component, and pass the accessor to RootProvider. Context gives you the current accessor.

Code
import { Editable, useEditable } from '@leverui/components';

export function EditableName() {
  const editable = useEditable({ defaultValue: 'Name' });
  return (
    <Editable.RootProvider value={editable}>
      <Editable.Preview />
      <Editable.Input />
    </Editable.RootProvider>
  );
}

Props

Root

PropDefaultTypeDescription
activationMode'focus''focus' | 'dblclick' | 'click' | 'none'What switches the preview to edit mode.
selectOnFocustruebooleanSelect the text when the input gets focus.
submitMode'both''enter' | 'blur' | 'none' | 'both'What saves the value: Enter, blur, both, or neither.
size'md''sm' | 'md' | 'lg'Component size.
asdivNative tagHTML tag to render.
asChild—Solid render functionRender your own element with the root's props.
unstyled—booleanTurn off the default styles.
autoResize—booleanResize to fit the content.
defaultEdit—booleanStart in edit mode.
defaultValue—stringStarting value.
disabled—booleanDisable the editable.
edit—booleanWhether edit mode is on.
finalFocusEl—() => HTMLElement | nullElement focused when editing ends.
form—stringForm the input belongs to.
id—stringUnique id.
ids—Element ID mapIds of the elements inside.
invalid—booleanMark the value as invalid.
maxLength—numberMost characters accepted.
name—stringname attribute. Sent with the form.
onEditChange—(details: EditChangeDetails) => voidCalled when edit mode turns on or off.
onFocusOutside—(event: FocusOutsideEvent) => voidCalled when focus moves outside.
onInteractOutside—(event: InteractOutsideEvent) => voidCalled on an interaction outside.
onPointerDownOutside—(event: PointerDownOutsideEvent) => voidCalled when the pointer is pressed outside.
onValueChange—(details: ValueChangeDetails) => voidCalled when the value changes.
onValueCommit—(details: ValueChangeDetails) => voidCalled when the value is saved.
onValueRevert—(details: ValueChangeDetails) => voidCalled when an edit is canceled.
placeholder—string | { edit: string; preview: string }Placeholder text. An object sets edit and preview apart.
readOnly—booleanMake the editable read-only.
required—booleanMark the editable as required.
translations—IntlTranslationsTranslated text.
value—stringCurrent value, when you control it.

Customize with CSS

Import the Lever UI stylesheet before your own CSS.

Classes: .leverui-editable__root, .leverui-editable__preview, .leverui-editable__input, .leverui-editable__textarea. The textarea also has the input class.

Attributes: data-size on the root, data-size-* for sizes set per screen size, and editing-state attributes on the parts.

Variables: --leverui-editable-gap, --leverui-editable-padding-block, --leverui-editable-padding-inline, --leverui-editable-control-height, --leverui-editable-font-size, --leverui-editable-focus-color.

The root and every part accept unstyled, class, style, native HTML attributes, refs, as, and asChild. Prop types follow the tag you pick: EditablePreviewProps<'a'> accepts an anchor's href.

Explorer

Click a part name in the sidebar to highlight it in the preview.

Component Anatomy

Hover to highlight, click to select parts