Use enter and escape to stage changes to the cell name

Sort of confusing if you look at the implementation, but produces the
desired user experience. There’s a two-step saving process with cell
names now. The user has to change the cell name and hit Enter (or
manually blur) and the name is committed to CEO workingCellName state.
If they hit Escape it reverts to its name when the cell was initially
edited.
pull/2002/head
Alex P 2017-09-26 10:37:49 -07:00
parent c0329a823f
commit e296fa4656
1 changed files with 22 additions and 3 deletions

View File

@ -3,14 +3,31 @@ import React, {Component, PropTypes} from 'react'
class VisualizationName extends Component { class VisualizationName extends Component {
constructor(props) { constructor(props) {
super(props) super(props)
this.state = {
reset: false,
}
} }
handleInputBlur = e => { handleInputBlur = reset => e => {
this.props.onCellRename(e.target.value) console.log(reset, this.props.defaultName)
this.props.onCellRename(reset ? this.props.defaultName : e.target.value)
this.setState({reset: false})
}
handleKeyDown = e => {
if (e.key === 'Enter') {
this.inputRef.blur()
}
if (e.key === 'Escape') {
this.inputRef.value = this.props.defaultName
this.setState({reset: true}, () => this.inputRef.blur())
}
} }
render() { render() {
const {defaultName} = this.props const {defaultName} = this.props
const {reset} = this.state
return ( return (
<div className="graph-heading"> <div className="graph-heading">
@ -18,8 +35,10 @@ class VisualizationName extends Component {
type="text" type="text"
className="form-control input-md" className="form-control input-md"
defaultValue={defaultName} defaultValue={defaultName}
onBlur={this.handleInputBlur} onBlur={this.handleInputBlur(reset)}
onKeyDown={this.handleKeyDown}
placeholder="Name this Cell..." placeholder="Name this Cell..."
ref={r => (this.inputRef = r)}
/> />
</div> </div>
) )