Skip to content
This repository has been archived by the owner on Oct 16, 2019. It is now read-only.

Commit

Permalink
Fix for ctrl key having no impact on submit process
Browse files Browse the repository at this point in the history
  • Loading branch information
joops75 committed Jun 18, 2018
1 parent 03c7a76 commit ee3ec38
Showing 1 changed file with 43 additions and 5 deletions.
48 changes: 43 additions & 5 deletions src/templates/Challenges/project/ProjectForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,55 @@ const options = {
};

export class ProjectForm extends PureComponent {
constructor(props) {
super(props);
this.state = {
keysDown: {
Control: false,
Enter: false
}
};
this.handleKeyDown = this.handleKeyDown.bind(this);
this.handleKeyUp = this.handleKeyUp.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
componentDidMount() {
this.props.updateProjectForm({});
window.addEventListener('keydown', this.handleKeyDown);
window.addEventListener('keyup', this.handleKeyUp);
}
componentDidUpdate() {
this.props.updateProjectForm({});
}
handleSubmit = values => {
this.props.openModal('completion');
this.props.updateProjectForm(values);
};

componentWillUnmount() {
window.removeEventListener('keydown', this.handleKeyDown);
window.removeEventListener('keyup', this.handleKeyUp);
}
handleKeyDown(e) {
if (e.key === 'Control') {
this.setState({ keysDown: { ...this.state.keysDown, Control: true } });
}
if (e.key === 'Enter') {
this.setState({ keysDown: { ...this.state.keysDown, Enter: true } });
}
}
handleKeyUp(e) {
if (e.key === 'Control') {
this.setState({ keysDown: { ...this.state.keysDown, Control: false } });
}
if (e.key === 'Enter') {
this.setState({ keysDown: { ...this.state.keysDown, Enter: false } });
}
}
handleSubmit(values) {
if (
this.state.keysDown.Control && this.state.keysDown.Enter ||
!this.state.keysDown.Enter
) {
this.props.openModal('completion');
this.props.updateProjectForm(values);
}
}
render() {
const { isSubmitting, isFrontEnd } = this.props;
const buttonCopy = isSubmitting
Expand Down

0 comments on commit ee3ec38

Please sign in to comment.