Before you continue, check out a successor to this repo: React Inline Edit Kit. It is more functional, and will be maintained in future.
This is a simple React component for in-place text editing. It turns into an <input /> when focused, and tries to validate and save input on Enter or blur. Esc works as well for cancelling.
Watch a demo, then check out demo/index.jsx for a quick example.
npm install react-edit-inline --save-dev
text:stringinitial textparamName:stringname of the parameter to be returned tochangefunctionchange:functionfunction 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, default1maxLength:number maximum text length, default256editingElement:string element name to use when in edit mode (DOM must havevalueproperty) defaultinputstaticElement:string element name for displaying data defaultspanediting:boolean If true, element will be in edit modetabIndex:number tab index used for focusing with TAB key default0stopPropagation:boolean If true, the event onClick will not be further propagated.
importReactfrom'react';importInlineEditfrom'react-edit-inline';classMyParentComponentextendsReact.Component{constructor(props){super(props);this.dataChanged=this.dataChanged.bind(this);this.state={message: 'ReactInline demo'}}dataChanged(data){// data = { description: "New validated text comes here" }// Update your model from hereconsole.log(data)this.setState({...data})}customValidateText(text){return(text.length>0&&text.length<64);}render(){return(<div><h2>{this.state.message}</h2><span>Edit me: </span><InlineEditvalidate={this.customValidateText}activeClassName="editing"text={this.state.message}paramName="message"change={this.dataChanged}style={{backgroundColor: 'yellow',minWidth: 150,display: 'inline-block',margin: 0,padding: 0,fontSize: 15,outline: 0,border: 0}}/></div>)}}