Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix spaceSelectsMatch causing error (fixes #495) #529

Merged

Conversation

bobwhitelock
Copy link
Contributor

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.

Before this change with spaceSelectsMatch enabled:
error_before_change

After this change with spaceSelectsMatch enabled:
no_error_after_change

bobwhitelock added a commit to bobwhitelock/todotxt-ui that referenced this pull request Jul 28, 2020
An error on autocomplete can still occur when `spaceSelectsMatch` is
enabled, but this doesn't actually appear to break anything; therefore
enabling this option now.

zurb/tribute#529 should fix this error.
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.
@bobwhitelock bobwhitelock force-pushed the fix-spaceSelectsMatch-causing-error branch from b523c1f to 3d0e9f7 Compare September 16, 2021 21:28
@bobwhitelock
Copy link
Contributor Author

Just ran into the same error on another project - I've rebased on the latest master, any chance this can be merged? Or anything I can do to improve this fix?

@mrsweaters mrsweaters merged commit 046ae53 into zurb:master Sep 24, 2021
@mrsweaters
Copy link
Collaborator

Merged! Thank you.

@bobwhitelock bobwhitelock deleted the fix-spaceSelectsMatch-causing-error branch September 24, 2021 22:51
@bobwhitelock
Copy link
Contributor Author

Thank you! 🎉

tiagomagnusss pushed a commit to promoteinternational/tribute that referenced this pull request Nov 17, 2021
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)
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.

2 participants