Skip to content

Commit

Permalink
Fix spaceSelectsMatch causing error (fixes #495) (#529)
Browse files Browse the repository at this point in the history
With `spaceSelectsMatch` enabled, an error `Uncaught TypeError: Cannot
read property '0' of undefined` is sometimes given when attempting to
autocomplete with any of space, tab, or enter.

The cause appears to be that with this option enabled, sometimes this
code path intended to handle KeyboardEvents will be entered again after
handling a KeyboardEvent with another type of event (CustomEvent); this
then later causes this error as `this.current.filteredItems` is now
`undefined`, as the original KeyboardEvent has already been handled.

Checking whether the event looks like a KeyboardEvent, and returning
early if it doesn't, appears to resolve this.
  • Loading branch information
bobwhitelock authored Sep 24, 2021
1 parent 5d63790 commit 046ae53
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/TributeEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class TributeEvents {
}
instance.updateSelection(this);

if (event.keyCode === 27) return;
if (!event.keyCode || event.keyCode === 27) return;

if (!instance.tribute.allowSpaces && instance.tribute.hasTrailingSpace) {
instance.tribute.hasTrailingSpace = false;
Expand Down

0 comments on commit 046ae53

Please sign in to comment.