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 ListBox typeahead spacebar issue #869

Merged
merged 2 commits into from
Aug 1, 2020
Merged

Conversation

solimant
Copy link
Collaborator

Closes #851

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

  1. Go to storybook
  2. Go to ListBox > ListBox w/ many sections and selection
  3. Make sure the listbox is in focus
  4. Type in an item name including the space character; e.g. Section 8
  5. If the item is highlighted without being selected, tests 1/2 pass ✅
  6. Wait about a second or so (to clear the typeahead timeout), then press the Spacebar on your keyboard
  7. If the item is selected, tests 2/2 pass ✅
  8. Everything is fine, nothing is ruined

🧢 Your Project:

Adobe React-Spectrum
rsp

@@ -489,6 +493,34 @@ describe('ListBox', function () {
expect(document.activeElement).toBe(options[4]);
});

it('supports the space character in a search', function () {
Copy link
Member

Choose a reason for hiding this comment

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

if you use jest.useFakeTimers, you can step through time to verify that you can use space bar to select the option after the typeahead timeout has completed, i won't require that you write that test, just an interesting thing you can do

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, @snowystinger, good idea! I called it out in the test instructions, so I think I should include it as well as a test.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@@ -88,6 +99,8 @@ function getStringForKey(key: string) {
// See https://www.w3.org/TR/uievents-key/
if (key.length === 1 || !/^[A-Z]/i.test(key)) {
return key;
} else if (key === 'Spacebar') { // For IE 11
Copy link
Member

Choose a reason for hiding this comment

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

we don't care about IE 11 anymore if you want to remove this, no sense in dead code :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

bye_ie

Copy link
Member

@devongovett devongovett left a comment

Choose a reason for hiding this comment

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

🎉

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.

ListBox typeahead shouldn't select the focused item when pressing space
3 participants