allow user press Enter key to end editing title (#3112)

This commit is contained in:
Grace Guo
2017-07-17 08:58:10 -07:00
committed by Maxime Beauchemin
parent 091e93c831
commit 27fab0d54f

View File

@@ -23,6 +23,7 @@ class EditableTitle extends React.PureComponent {
this.handleClick = this.handleClick.bind(this);
this.handleBlur = this.handleBlur.bind(this);
this.handleChange = this.handleChange.bind(this);
this.handleKeyPress = this.handleKeyPress.bind(this);
}
handleClick() {
if (!this.props.canEdit) {
@@ -58,6 +59,13 @@ class EditableTitle extends React.PureComponent {
title: ev.target.value,
});
}
handleKeyPress(ev) {
if (ev.key === 'Enter') {
ev.preventDefault();
this.handleBlur();
}
}
render() {
return (
<span className="editable-title">
@@ -72,6 +80,7 @@ class EditableTitle extends React.PureComponent {
onChange={this.handleChange}
onBlur={this.handleBlur}
onClick={this.handleClick}
onKeyPress={this.handleKeyPress}
/>
</TooltipWrapper>
</span>