Permalink
Browse files

fix: allow up/down normally for no completions

Autocomplete current eats up up/down key events by unconditionally returning
true for onUpArrow and onDownArrow. Instead, only do that if there are completions actually visible.
  • Loading branch information...
aviraldg committed Aug 3, 2016
1 parent f431e62 commit a2d64f51197109c3a85d18fbf81704147362b07e
Showing with 10 additions and 8 deletions.
  1. +6 −0 src/components/views/rooms/Autocomplete.js
  2. +4 −8 src/components/views/rooms/MessageComposerInput.js
@@ -64,6 +64,9 @@ export default class Autocomplete extends React.Component {
onUpArrow(): boolean {
let completionCount = this.countCompletions(),
selectionOffset = (completionCount + this.state.selectionOffset - 1) % completionCount;
if (!completionCount) {
return false;
}
this.setSelection(selectionOffset);
return true;
}
@@ -72,6 +75,9 @@ export default class Autocomplete extends React.Component {
onDownArrow(): boolean {
let completionCount = this.countCompletions(),
selectionOffset = (this.state.selectionOffset + 1) % completionCount;
if (!completionCount) {
return false;
}
this.setSelection(selectionOffset);
return true;
}
@@ -503,18 +503,14 @@ export default class MessageComposerInput extends React.Component {
}
onUpArrow(e) {
if(this.props.onUpArrow) {
if(this.props.onUpArrow()) {
e.preventDefault();
}
if (this.props.onUpArrow && this.props.onUpArrow()) {
e.preventDefault();
}
}
onDownArrow(e) {
if(this.props.onDownArrow) {
if(this.props.onDownArrow()) {
e.preventDefault();
}
if (this.props.onDownArrow && this.props.onDownArrow()) {
e.preventDefault();
}
}

0 comments on commit a2d64f5

Please sign in to comment.