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

πŸ› <Listbox>: 4 bug fixes for scrolling & focus #81

Conversation

dmcnamara-eng
Copy link
Collaborator

@dmcnamara-eng dmcnamara-eng commented Sep 8, 2021

✨ What Changed & Why

Fixes for the following 4 <Listbox> bugs related to scrolling & focus:

  1. πŸ› Prevent arrow keys from scrolling the page 8f83502
  2. πŸ› Scroll selected option into view ebccd58
  3. πŸ› Scroll searched option into view 855f9e6
  4. πŸ› it should be possible to open a listbox without submitting the form d14513a

@alexlafroscia
Copy link
Collaborator

(It's not sufficient to preventDefault on these events as we handle them, because page scrolling occurs during the capturing phase of event propagation.)

This is a good catch; I was wondering about this!

Is it possible for us to listen for the events during the capture phase as well to call .preventDefault rather than needing to add these additional event listeners?

@dmcnamara-eng dmcnamara-eng force-pushed the bug/listbox-prevent-document-scroll-if-active branch from 05a672d to 0eca5fa Compare September 17, 2021 16:45
@dmcnamara-eng
Copy link
Collaborator Author

Is it possible for us to listen for the events during the capture phase as well to call .preventDefault rather than needing to add these additional event listeners?

0eca5fa has a potentially cleaner solution to this. We can preventDefault during the keydown event, which is where the browser listens for it.

@dmcnamara-eng dmcnamara-eng force-pushed the bug/listbox-prevent-document-scroll-if-active branch from 0eca5fa to 10483a6 Compare October 5, 2021 15:47
@dmcnamara-eng
Copy link
Collaborator Author

@alexlafroscia @GavinJoyce I reckon this is ready to merge. This fixes two important bugs when embedding the listbox in a (long) form.

@alexlafroscia
Copy link
Collaborator

Hey @dmcnamara-eng, sorry I can't push this through right now, I'm on my honeymoon and am not doing OSS while on vacation. I promise I'll check this out when I return next week! I've been a little neglectful of my OSS duties with the wedding but will be back with energy once I return home.

@dmcnamara-eng dmcnamara-eng force-pushed the bug/listbox-prevent-document-scroll-if-active branch 2 times, most recently from c0b328e to 34e7cc5 Compare October 7, 2021 15:47
addon/components/listbox.js Outdated Show resolved Hide resolved
addon/components/listbox.js Outdated Show resolved Hide resolved
addon/components/listbox.js Outdated Show resolved Hide resolved
@dmcnamara-eng dmcnamara-eng force-pushed the bug/listbox-prevent-document-scroll-if-active branch 2 times, most recently from d4cb709 to 6503d67 Compare October 22, 2021 16:37
@dmcnamara-eng
Copy link
Collaborator Author

dmcnamara-eng commented Oct 22, 2021

Welcome back and congratulations @alexlafroscia 🍯 🌚

I think that as long as the trigger button has role="button" on it, the form shouldn't be submitted... is that something you can confirm?

Yay! This is a cleaner fix of course. Actually this behaviour is determined by type=button, so that is fixed in f6687fb and 8976a1a reverts the event prevention. I've added a regression test for this is 8aad605

I think we have covered a lot here. I can squash the commits before merging?

Not sure why checks are failing? Checks are passing πŸŽ‰

@dmcnamara-eng dmcnamara-eng force-pushed the bug/listbox-prevent-document-scroll-if-active branch from 6503d67 to fb8dde1 Compare October 27, 2021 09:46
@dmcnamara-eng dmcnamara-eng changed the title πŸ› Listbox: Prevent page scroll if listbox component is active πŸ› Listbox: 4 bug fixes for scrolling & focus Oct 27, 2021
@dmcnamara-eng dmcnamara-eng force-pushed the bug/listbox-prevent-document-scroll-if-active branch from fb8dde1 to d14513a Compare November 5, 2021 17:41
@dmcnamara-eng dmcnamara-eng changed the title πŸ› Listbox: 4 bug fixes for scrolling & focus πŸ› <Listbox>: 4 bug fixes for scrolling & focus Nov 5, 2021
@dmcnamara-eng
Copy link
Collaborator Author

I've cleaned this PR up and commit history for the following 4 <Listbox> bugs related to scrolling & focus:

  1. πŸ› Prevent arrow keys from scrolling the page 8f83502
  2. πŸ› Scroll selected option into view ebccd58
  3. πŸ› Scroll searched option into view 855f9e6
  4. πŸ› it should be possible to open a listbox without submitting the form d14513a

We are using this branch in production and these fixes feel solid πŸ‘

Please πŸ‘€ @alexlafroscia πŸ’₯

Comment on lines 80 to 87
[
'ArrowUp',
'ArrowDown',
'ArrowLeft',
'ArrowRight',
'Home',
'End',
].indexOf(event.key) > -1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two tiny thoughts (neither of which are blockers here, by any means)

  1. We could move this array up to the module scope to avoid creating it on every keydown event from the user.
  2. We could make it a Set instead of an array, which might make the code read a little more easily
if (HANDLED_KEYDOWN_EVENTS.has(event.key)) {
  ...
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ‘ Agreed. Much cleaner and more performant. I've fixed that here: 6f34df6

addon/components/listbox.js Show resolved Hide resolved
@dmcnamara-eng dmcnamara-eng force-pushed the bug/listbox-prevent-document-scroll-if-active branch from e23360d to c0ebe7a Compare November 10, 2021 09:49
@alexlafroscia
Copy link
Collaborator

Thank you so much for all of your patience with me @dmcnamara-eng -- this looks great! Thank you for this PR πŸ™

@alexlafroscia alexlafroscia merged commit c3335bc into GavinJoyce:master Nov 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants