Skip to content

Comments

Fix array index out of bounds on enter key event#773

Open
dreamofabear wants to merge 1 commit intozurb:masterfrom
dreamofabear:patch-1
Open

Fix array index out of bounds on enter key event#773
dreamofabear wants to merge 1 commit intozurb:masterfrom
dreamofabear:patch-1

Conversation

@dreamofabear
Copy link

On keyboard enter, don't select when filteredItems is empty.

If filteredItems is empty array here:

if (this.tribute.isActive && this.tribute.current.filteredItems) {
e.preventDefault();
e.stopPropagation();
setTimeout(() => {
this.tribute.selectItemAtIndex(this.tribute.menuSelected, e);

Then item will be undefined here:

tribute/src/Tribute.js

Lines 473 to 479 in 252ec34

selectItemAtIndex(index, originalEvent) {
index = parseInt(index);
if (typeof index !== "number" || isNaN(index)) return;
let item = this.current.filteredItems[index];
let content = this.current.collection.selectTemplate(item);
if (content !== null) this.replaceText(content, originalEvent, item);
}

I noticed this when hitting the enter key on strings that don't match any values but coincidentally contain my trigger character, e.g. : in hyperlinks.

SrPatinhas added a commit to SrPatinhas/tribute that referenced this pull request Oct 6, 2023
tohosaku pushed a commit to redmine-ui/tribute that referenced this pull request Nov 2, 2024
On enter, don't select when filteredItems is empty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant