diff --git a/dashboard-client/app/app/src/App.js b/dashboard-client/app/app/src/App.js index e9cbf299a8..768e458133 100644 --- a/dashboard-client/app/app/src/App.js +++ b/dashboard-client/app/app/src/App.js @@ -22,17 +22,26 @@ class App extends Component { inputRef = React.createRef(); - handleInputChange = (event) => { - const { value } = event.target; + handleInputEvent = (event) => { + const { type, key, target: { value } } = event; - if (Number(value) || value === '') { - this.setState((prevState) => ({ number: value, foundPRs: [] })); + if (type === 'change') { + if (Number(value) || value === '') { + this.setState((prevState) => ({ number: value, foundPRs: [] })); + } + } + else if (type === 'keypress' && key === 'Enter') { + this.searchPRs(value); } } handleButtonClick = () => { const { number } = this.state; + this.searchPRs(number); + } + + searchPRs = (number) => { fetch(`https://pr-relations.glitch.me/pr/${number}`) .then((response) => response.json()) .then(({ ok, foundPRs }) => { @@ -52,12 +61,12 @@ class App extends Component { } render() { - const { handleButtonClick, handleInputChange, inputRef, state } = this; + const { handleButtonClick, handleInputEvent, inputRef, state } = this; const { number, foundPRs } = state; return ( - + diff --git a/dashboard-client/app/app/src/components/Input.js b/dashboard-client/app/app/src/components/Input.js index 4383004cac..a72712e38f 100644 --- a/dashboard-client/app/app/src/components/Input.js +++ b/dashboard-client/app/app/src/components/Input.js @@ -4,7 +4,8 @@ const Input = React.forwardRef((props, ref) => (