Skip to content
This repository has been archived by the owner on Sep 14, 2020. It is now read-only.

All the cleanup #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
border: none;
border-bottom: solid;
}
.App input[type="button"]{
.App input[type="submit"]{
color: white;
background: rgba(0,0,0,0.31);
border: none;
Expand Down
37 changes: 15 additions & 22 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,31 @@ class App extends Component {
this.input.focus()
}

handleKeyPress = e => {
const { showAnswer } = this.state;
if (e.key === 'Enter') {
if (!showAnswer && this.input.value.length === 0) return
this.toggleShowAnswer()
}
}

toggleShowAnswer = () => {
toggleShowAnswer (evt) {
evt.preventDefault();
const { showAnswer } = this.state;
this.setState({showAnswer: !showAnswer})
if (!showAnswer && !this.input.value) return;
this.setState({showAnswer: !showAnswer});
if (showAnswer) this.back.focus()
}

render() {
const {showAnswer} = this.state;
return (
<div className="App">
{!showAnswer &&
<div>
How do I&nbsp;
<input ref={(input) => {this.input = input;}} type="text" onKeyDown={this.handleKeyPress}></input>
?
</div>
}
{showAnswer &&
<form className="App" onSubmit={this.toggleShowAnswer.bind(this)}>
{showAnswer ? (
<div>
<p>Don't</p>
<input type="button" onClick={this.toggleShowAnswer} ref={(back) => {this.back = back;}} value="Back"/>
<input type="submit" ref={(back) => {this.back = back;}} value="Back"/>
</div>
}
</div>
) : (
<div>
How do I&nbsp;
<input ref={(input) => {this.input = input;}} type="text"></input>
?
</div>
)}
</form>
);
}
}
Expand Down