Editable
EditableText 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.
Import
Chakra UI exports 3 components to handle this functionality.
Editable: The wrapper component that provides context value.EditableInput: The edit view of the component. It shows when you click or focus on the text.EditableTextarea: Use the textarea element to handle multi line text input in an editable context.EditablePreview: The read-only view of the component.
import {
Editable,
EditableInput,
EditableTextarea,
EditablePreview,
} from '@chakra-ui/react';
Usage
The editable's text input and preview inherits all font styling from the root
Editable container in order to make the edit and read view transition
seamless.
Usage with textarea
With custom input and 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 state of
the component. You may want to customize the EditableInput as well. This can
be achieved by using a custom Input component in the as prop.
Styling the editable
Please see the recipe for a styled example.
Props
Editable Props
colorScheme
colorSchemeColor Schemes for Editable are not implemented in the default theme. You can extend the theme to implement them.
stringdefaultValue
defaultValueThe initial value of the Editable in both edit & preview mode
stringisDisabled
isDisabledIf true, the Editable will be disabled.
booleanisPreviewFocusable
isPreviewFocusableIf true, the read only view, has a tabIndex set to 0
so it can receive focus via the keyboard or click.
booleantrueonCancel
onCancelCallback invoked when user cancels input with the Esc key.
It provides the last confirmed value as argument.
((previousValue: string) => void)onChange
onChangeCallback invoked when user changes input.
((nextValue: string) => void)onEdit
onEditCallback invoked once the user enters edit mode.
(() => void)onSubmit
onSubmitCallback invoked when user confirms value with enter key or by blurring input.
((nextValue: string) => void)placeholder
placeholderThe placeholder text when the value is empty.
stringselectAllOnFocus
selectAllOnFocusIf true, the input's text will be highlighted on focus.
booleantruesize
sizeSizes for Editable are not implemented in the default theme. You can extend the theme to implement them.
stringstartWithEditView
startWithEditViewIf true, the Editable will start with edit mode by default.
booleansubmitOnBlur
submitOnBlurIf true, it'll update the value onBlur and turn off the edit mode.
booleantruevalue
valueThe value of the Editable in both edit & preview mode
stringvariant
variantVariants for Editable are not implemented in the default theme. You can extend the theme to implement them.
string