1.0.1 • Published 6 years ago

picr-react-content-editable v1.0.1

Weekly downloads
5
License
ISC
Repository
github
Last release
6 years ago

Picr react content editable

A simple implementation of content editable that autosizes input/textarea with minimum Javascript.

Installation

npm install picr-react-content-editable

The idea

The idea is pretty simple. Input field/textarea renders as absolute positioned element in a wrapper with height and width set to 100%. Input/Textarea value renders in the wrapper with transparent color that makes the text invisible and stretches the wrapper. Since the field has the same font style with the exception of the color, it has the same dynamic dimensions.

How to use

Demo on Codesandbox

import React, { Component } from 'react';
import ContentEditable from 'picr-react-content-editable';

class App extends Component {
  constructor(props) {
    super(props);

    this.state = {
      value: ''
    };
  }

  onInputChange = (e) => {
    this.setState({ value: e.target.value });
  }

  render() {
    return (
      <ContentEditable
        onChange={this.onInputChange}
        value={this.state.value}
      />
    );
  }
}

export default App;

Props

PropDescriptionTypeDefault
classNamecomponent wrapper class namestring''
fieldClassNameinput/textarea class namestring''
customElementcustom element that renders instead of default input/textareaReact component, DOMnull
typetype of field elementstring ('input|textarea')'input'
onChangeinput/textarea onchange callbackfunctionRequired
valueinput/textarea valuestringRequired
1.0.1

6 years ago

1.0.0

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago