Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit a2d64f5

Browse files
committed
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.
1 parent f431e62 commit a2d64f5

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/components/views/rooms/Autocomplete.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ export default class Autocomplete extends React.Component {
6464
onUpArrow(): boolean {
6565
let completionCount = this.countCompletions(),
6666
selectionOffset = (completionCount + this.state.selectionOffset - 1) % completionCount;
67+
if (!completionCount) {
68+
return false;
69+
}
6770
this.setSelection(selectionOffset);
6871
return true;
6972
}
@@ -72,6 +75,9 @@ export default class Autocomplete extends React.Component {
7275
onDownArrow(): boolean {
7376
let completionCount = this.countCompletions(),
7477
selectionOffset = (this.state.selectionOffset + 1) % completionCount;
78+
if (!completionCount) {
79+
return false;
80+
}
7581
this.setSelection(selectionOffset);
7682
return true;
7783
}

src/components/views/rooms/MessageComposerInput.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -503,18 +503,14 @@ export default class MessageComposerInput extends React.Component {
503503
}
504504

505505
onUpArrow(e) {
506-
if(this.props.onUpArrow) {
507-
if(this.props.onUpArrow()) {
508-
e.preventDefault();
509-
}
506+
if (this.props.onUpArrow && this.props.onUpArrow()) {
507+
e.preventDefault();
510508
}
511509
}
512510

513511
onDownArrow(e) {
514-
if(this.props.onDownArrow) {
515-
if(this.props.onDownArrow()) {
516-
e.preventDefault();
517-
}
512+
if (this.props.onDownArrow && this.props.onDownArrow()) {
513+
e.preventDefault();
518514
}
519515
}
520516

0 commit comments

Comments
 (0)