# react-editable-text

> Editable text line or box component for [facebook react](https://facebook.github.io/react/).

Latest version **1.2.1** (published 2019-10-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-editable-text
pnpm add react-editable-text
yarn add react-editable-text
bun add react-editable-text
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.1 |
| Published | 2019-10-12 |
| First published | 2016-03-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 291.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | gomo |

## Links

- npm: https://www.npmjs.com/package/react-editable-text
- Repository: https://github.com/gomo/react-editable-text
- Homepage: https://github.com/gomo/react-editable-text#readme
- Issues: https://github.com/gomo/react-editable-text/issues
- npm.io page: https://npm.io/package/react-editable-text

## Dependencies (1)

- [classnames](https://npm.io/package/classnames.md) ^2.2.6

## Recent versions

- 1.2.1 (latest) — 2019-10-12
- 1.2.0 — 2019-10-12
- 1.1.0 — 2018-12-02
- 1.0.0 — 2018-12-02
- 0.0.9 — 2018-03-18
- 0.0.8 — 2018-03-18
- 0.0.7 — 2016-03-26
- 0.0.6 — 2016-03-19
- 0.0.5 — 2016-03-16
- 0.0.4 — 2016-03-06
- 0.0.3 — 2016-03-05
- 0.0.2 — 2016-03-05
- 0.0.1 — 2016-03-05

## README

# react-editable-text

Editable text line or box component for [facebook react](https://facebook.github.io/react/).`Box` use `textarea` element, `Line` use `input[type=text]` element.

I recommend using with [Bootstrap](http://getbootstrap.com/).

## Install

```
npm install react-editable-text --save-dev
```

## How to use

```es6
import React from 'react';
import Box from 'react-editable-text/Box';
import Line from 'react-editable-text/Line';

export default class GuestEditView extends React.Component
{
  constructor(props) {
    super(props);
  }

  onSaveMemo(memo, textarea){
    setTimeout(() => {
      console.log(memo);
      textarea.fix();
    }, 600);
  }

  render() {
    return (
      <div>
        <Line
          label='<i class="fa fa-user"></i>'
          onSave={(value, editable) => this.onSave(value, editable)}
          editLabel='<i class="fa fa-pencil"></i>'
          saveLabel='<i class="fa fa-floppy-o"></i>'
          cancelLabel='<i class="fa fa-ban"></i>'
          value='Initial line value'
          needsSaveOnKeyPress = {(e) => this.needsSaveOnKeyPressInInputText(e)}
        />
        <Box
          label='<i class="fa fa-list-alt"></i>&nbsp;Memo'
          onSave={(value, editable) => this.onSave(value, editable)}
          editLabel='<i class="fa fa-pencil"></i>'
          saveLabel='<i class="fa fa-floppy-o"></i>'
          cancelLabel='<i class="fa fa-ban"></i>'
          value='Initial box value'
          needsSaveOnKeyPress = {(e) => this.needsSaveOnKeyPressInTextarea(e)}
        />
      </div>
    );
  }
}

```

`onSave` sample is here. Second arg `editable` is this component.

```js
  onSave(value, editable){
    $.ajax({
      url: '/ajax/save',
      data:{value: value}
    }).done(() => {
      // change to fix mode
      editable.success();
    }).fail(() => {
      // back to edit mode
      editable.fail();
    });
  }
```

If you want save when some key press in the element, Set callback to `needsSaveOnKeyPress` props, and return `true`.The arg is keypress event.

```js
  needsSaveOnKeyPressInInputText(e){
    if(e.charCode == 13){
      return true;
    }

    return false;
  }

  needsSaveOnKeyPressInTextarea(e){
    if(e.charCode == 13 && e.shiftKey){
      return true;
    }

    return false;
  }
```

All labels are set to [dangerouslySetInnerHTML](https://facebook.github.io/react/tips/dangerously-set-inner-html.html).Please note the "cross-site scripting".

All props list is [here](src/Editable.es6#L57-L67)

---
_Source: https://npm.io/package/react-editable-text · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
