Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-edit-text

bymi1516kMIT5.1.1TypeScript support: definitely-typed

Simple editable text component for React

react, edit, text, react-edit-text, editable, input, textbox, textarea

readme

React Edit Text

Quality Gate Status travis npm npm

This is an easy-to-use editable text component for React. Simply click on the textbox to edit!

Made with ❤️ by Brian Min

demo

Demo

Please visit https://brianmin.com/react-edit-text/ for a live demo and various examples.

Install

npm install react-edit-text --save

Type definitions

npm install @types/react-edit-text --save-dev

Usage

Make sure to import the CSS stylesheet before using the component.

import React from 'react';

import { EditText, EditTextarea } from 'react-edit-text';
import 'react-edit-text/dist/index.css';

export default function Example() {
  return (
    <div>
      <EditText showEditButton />
      <EditTextarea />
    </div>
  );
}

Props

Shared props

Prop Type Required Default Description
id string No | HTML DOM id attribute
name string No | HTML input name attribute
className string No | HTML class attribute for the display component
inputClassName string No | HTML class attribute for the input component
value string No | Value of the component
defaultValue string No | Default value of the component
placeholder string No '' Placeholder value
formatDisplayText function No (x) => x Callback function applied on the value to display the formatted value
onSave function No | Callback function triggered when input is saved
onChange function No | Callback function triggered when input is changed
onEditMode function No | Callback function triggered when component is clicked
onBlur function No | Callback function triggered when input is blurred
style object No | Sets CSS style of input and view component
readonly bool No false Disables the input and only displays the view component

EditText props

Prop Type Required Default Description
type string No 'text' HTML DOM input text type
inline bool No false Sets inline display
showEditButton bool No false Displays an edit button that can be pressed to enable edit mode
editButtonContent node No editIcon Sets the content for the edit button. This can be any valid element
editButtonProps object No {} Sets the props passed to the edit button. This can be any valid DOM attribute

EditTextarea props

Prop Type Required Default Description
rows number | 'auto' No 3 Number of visible rows

Contributing

Contributions are very much appreciated and welcome. Please refer to the contributing guidelines for more details.

License

MIT © Brian Min

changelog

5.1.1 (2023-07-12)

Bug Fixes

5.1.0 (2023-03-14)

Bug Fixes

Features

5.0.2 (2022-06-08)

Bug Fixes

5.0.1 (2022-06-02)

Bug Fixes

  • remove enzyme, update tests and remove/update dependencies with vulnerabilities (#35) (4b1d37a)

5.0.0 (2022-06-01)

  • fix!: onChange prop to return DOM event rather than just the new value (#32) (e9e59b3), closes #32

BREAKING CHANGES

  • onChange will now return the DOM event rather than just the new value

4.4.1 (2022-05-30)

Bug Fixes

  • pass inline prop to Input component (#31) (f18a50b)

4.4.0 (2022-03-21)

Features

  • 11: add props for displaying edit button and refactor project with react hooks (#23) (78de49d)

4.3.0 (2022-03-01)

Bug Fixes

Features

  • add formatDisplayText prop for providing callback function to format display text (cac7fda)

4.2.0 (2021-08-22)

Features

4.1.0 (2021-07-26)

Features

  • add onEditMode callback prop (836e58d)

4.0.3 (2021-04-03)

Bug Fixes

  • force minor version update to update readme in npmjs (d079ab9)

4.0.2 (2021-04-03)

Bug Fixes

  • setSelectionRange causing bugs for input types that are not text (777fba9)

4.0.1 (2021-03-09)

Bug Fixes

  • upgrade package to fix security issue (96b5914)

4.0.0 (2021-02-19)

Features

  • add previousValue field to onSave callback response (3057b92)
  • move cursor to end of text on focus (3fde4bd)

BREAKING CHANGES

  • fix handleBlur to correctly revert changes when escape key is pressed

3.0.1 (2021-01-13)

Bug Fixes

  • allow onSave callback to be triggered when used with onChange (6508ea4)

3.0.0 (2021-01-13)

Features

  • add controllable component for both EditText and EditTextarea (5d34a65)
  • add controlled values (defaultValue, value, onChange) (516dd3c)

BREAKING CHANGES

  • add defaultValue and onChange props to allow controllable components

2.1.3 (2020-11-17)

Bug Fixes

  • EditTextarea: fix newline not showing in view mode bug (6a21fa4)

2.1.2 (2020-11-16)

Bug Fixes

2.1.1 (2020-11-16)

Bug Fixes

  • fix browser compatibility issue with thin scrollbar (822ec70)

2.1.0 (2020-11-16)

Features

  • add scrollbar thin UI for EditTextarea (82ccfd8)

2.0.0 (2020-11-05)

Features

  • EditTextarea: add textarea component (9b88363)
  • example: update documentation page (16da811)
  • add EditTextarea component (bc4eb9a)

BREAKING CHANGES

  • split up default export into EditText and EditTextarea exports

1.1.0 (2020-10-28)

Features

  • add readonly prop (47d5a38)
  • example: add example for readonly prop (34d7646)

1.0.1 (2020-10-28)

Bug Fixes

  • styles: fix invalid css color for placeholder (1bf8159)

1.0.0 (2020-10-14)

Features

  • EditText: add EditText component (a953e78)
  • example: add demo web page (854e68c)