Editable Text

The Editable text component is used for inline renaming of some text. It appears as normal UI text but transforms into a text input field when the user clicks or focuses on it.

The text input inherits all font styling from its parent, to make the edit and read view transition seamless.

Import#

Chakra UI exports three components to handle this functionality.

  • CEditable: The wrapper component that providers context value.
  • CEditableInput: The edit view of the component. It shows when you click or focus on the text.
  • CEditablePreview: The read-only view of the component.
import { Editable, EditableInput, EditablePreview } from '@chakra-ui/vue';

Usage#

Take some chakra ⚡️ (click me)
Editable Example
<c-editable default-value="Take some chakra ⚡️ (click me)" font-size="2xl">
  <c-editable-preview />
  <c-editable-input />
</c-editable>

With custom controls#

In some cases, you might need to use custom controls to toggle the edit and read mode. We use the render prop pattern to provide access to the internal states of the component.

Take some chakra ⚡️ (click me)
Editable Example
<template>
  <c-editable default-value="Take some chakra ⚡️ (click me)" font-size="2xl">
    <template v-slot="{ isEditing, onSubmit, onCancel, onRequestEdit }">
      <c-editable-preview />
      <c-editable-input />

      <!-- Custom controls -->
      <c-flex mt="3">
        <c-button-group v-if="isEditing" size="sm">
          <c-icon-button icon="check" color="green" @click="onSubmit" />
          <c-icon-button icon="close" @click="onCancel" />
        </c-button-group>
        <c-icon-button v-else icon="edit" size="sm" @click="onRequestEdit" />
      </c-flex>
    </template>
  </c-editable>
</template>

Props#

CEditable Props#

CEditable component composes the Box component so can pass all CBox props. Here are the custom props:

NameTypeDefaultDescription
valuestringText value of the controlled input
defaultValuestringThe initial value of the Editable in both edit & preview mode
placeholderstring"Click to edit..."The placeholder text when the value is empty.
isDisabledbooleanIf true, the Editable will be disabled.
onChangefunctionCallback invoked when the user changes input.
onCancelfunctionCallback invoked when the user cancels input with the Esc key. It provides the last confirmed value as argument.
onSubmitfunctionCallback invoked when the user confirms value with enter key or by blurring the input.
onEditfunctionCallback invoked once the user enters edit mode.
isPreviewFocusablebooleantrueIf true, the read only view, has a tabindex set to 0 so it can receive focus via the keyboard or click.
startWithEditViewbooleanIf true, the Editable will start with edit mode by default.
submitOnBlurbooleantrueIf true, it'll update the value onBlur and turn off the edit mode.
selectAllOnFocusbooleantrueIf true, the input's text will be highlighted on focus.

Slots#

NameDescription
defaultThe content of the Editable Text. Ideally, only CEditablePreview and CEditableInput should be the children but you add other elements too

CEditableInput Props#

CEditableInput composes CPseudoBox so you can pass all CPseudoBox props. See PseudoBox component for list of props

CEditablePreview Props#

CEditablePreview composes CPseudoBox so you can pass all CPseudoBox props. See PseudoBox component for list of props

❤️ Contribute to this page

Caught a mistake or want to contribute to the documentation? Edit this page on GitHub!