Simple React component for in-place text editing. It turns into an <input />
when disturbed, and tries to validate and save input on Enter or blur
. Esc works as well for cancelling.
npm install react-edit-inline --save-dev
text
:string
initial textparamName
:string
name of the parameter to be returned tochange
functionchange
:function
function to call when new text is changed and validated, it will receive{paramName: value}
className
:string
CSS class nameactiveClassName
:string
CSS class replacement for when in edit modevalidate
:function
boolean function for custom validation, using this overrides the two props belowminLength
:number
minimum text length, default1
maxLength
:number
maximum text length, default256
import React from 'react';
import InlineEdit from 'react-edit-inline';
class MyParentComponent extends React.Component {
constructor(props) {
super(props);
this.dataChanged = this.dataChanged.bind(this);
}
dataChanged(data) {
// data = { description: "New validated text comes here" }
// Update your model from here
}
customValidateText(text) {
return (text.length > 8 && text.length < 64);
}
render() {
return (<div>
<h2>Edit this string</h2>
<InlineEdit
validate={this.customValidateText}
activeClassName="editing"
text={this.props.myObject.description}
paramName="description"
change={this.dataChanged}
/>
</div>)
}
}
export default MyParentComponent;