Skip to content

Commit

Permalink
Fix spaceSelectsMatch causing error (fixes zurb#495) (zurb#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.

(cherry picked from commit 046ae53)
  • Loading branch information
bobwhitelock authored and tiagomagnusss committed Nov 17, 2021
1 parent db04323 commit d9741e5
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 d9741e5

Please sign in to comment.