aboutsummaryrefslogtreecommitdiff
path: root/src/client/react/components/container/Search.js
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2018-02-07 15:21:34 +0100
committerNoah Loomans <noahloomans@gmail.com>2018-02-07 15:21:34 +0100
commit90eb2fec5e6e28b05f0b9511e8e539bcc42e0033 (patch)
tree80aadea4f2e6d50d7729f15edadb204d1217ab88 /src/client/react/components/container/Search.js
parentc325916e381d6ac13fcc840b2d4baa87913a3184 (diff)
Escape resets the search box
Diffstat (limited to 'src/client/react/components/container/Search.js')
-rw-r--r--src/client/react/components/container/Search.js57
1 files changed, 32 insertions, 25 deletions
diff --git a/src/client/react/components/container/Search.js b/src/client/react/components/container/Search.js
index 32996e3..8ca386c 100644
--- a/src/client/react/components/container/Search.js
+++ b/src/client/react/components/container/Search.js
@@ -51,32 +51,39 @@ class Search extends React.Component {
}
onKeyDown(event) {
- if (event.key === 'ArrowUp' || event.key === 'ArrowDown' || event.key === 'Enter') {
- event.preventDefault();
- switch (event.key) {
- case 'ArrowUp':
- this.props.dispatch(changeSelectedResult(-1));
- break;
- case 'ArrowDown':
- this.props.dispatch(changeSelectedResult(+1));
- break;
- case 'Enter': {
- const result = this.props.selectedResult || this.props.results[0];
- const urlUser = userFromMatch(this.props.match);
-
- if (result === urlUser) {
- // EDGE CASE: The user is set if the user changes, but it doesn't
- // change if the result is already the one we are viewing.
- // Therefor, we need to dispatch the SET_USER command manually.
- this.props.dispatch(setUser(urlUser));
- } else if (result) {
- this.props.history.push(`/${result}`);
- }
- break;
+ const urlUser = userFromMatch(this.props.match);
+ const result = this.props.selectedResult || this.props.results[0];
+
+ switch (event.key) {
+ case 'ArrowUp':
+ event.preventDefault();
+ this.props.dispatch(changeSelectedResult(-1));
+ break;
+
+ case 'ArrowDown':
+ event.preventDefault();
+ this.props.dispatch(changeSelectedResult(+1));
+ break;
+
+ case 'Escape':
+ event.preventDefault();
+ this.props.dispatch(setUser(urlUser));
+ break;
+
+ case 'Enter':
+ event.preventDefault();
+ if (result === urlUser) {
+ // EDGE CASE: The user is set if the user changes, but it doesn't
+ // change if the result is already the one we are viewing.
+ // Therefor, we need to dispatch the SET_USER command manually.
+ this.props.dispatch(setUser(urlUser));
+ } else if (result) {
+ this.props.history.push(`/${result}`);
}
- default:
- throw new Error('This should never happen... pls?');
- }
+ break;
+
+ default:
+ // Do nothing
}
}