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.
This commit is contained in:
parent
f431e62e6b
commit
a2d64f5119
2 changed files with 10 additions and 8 deletions
|
@ -64,6 +64,9 @@ export default class Autocomplete extends React.Component {
|
||||||
onUpArrow(): boolean {
|
onUpArrow(): boolean {
|
||||||
let completionCount = this.countCompletions(),
|
let completionCount = this.countCompletions(),
|
||||||
selectionOffset = (completionCount + this.state.selectionOffset - 1) % completionCount;
|
selectionOffset = (completionCount + this.state.selectionOffset - 1) % completionCount;
|
||||||
|
if (!completionCount) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
this.setSelection(selectionOffset);
|
this.setSelection(selectionOffset);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -72,6 +75,9 @@ export default class Autocomplete extends React.Component {
|
||||||
onDownArrow(): boolean {
|
onDownArrow(): boolean {
|
||||||
let completionCount = this.countCompletions(),
|
let completionCount = this.countCompletions(),
|
||||||
selectionOffset = (this.state.selectionOffset + 1) % completionCount;
|
selectionOffset = (this.state.selectionOffset + 1) % completionCount;
|
||||||
|
if (!completionCount) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
this.setSelection(selectionOffset);
|
this.setSelection(selectionOffset);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -503,18 +503,14 @@ export default class MessageComposerInput extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
onUpArrow(e) {
|
onUpArrow(e) {
|
||||||
if(this.props.onUpArrow) {
|
if (this.props.onUpArrow && this.props.onUpArrow()) {
|
||||||
if(this.props.onUpArrow()) {
|
e.preventDefault();
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onDownArrow(e) {
|
onDownArrow(e) {
|
||||||
if(this.props.onDownArrow) {
|
if (this.props.onDownArrow && this.props.onDownArrow()) {
|
||||||
if(this.props.onDownArrow()) {
|
e.preventDefault();
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue