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

feat: ComboBox component #694

Merged
merged 26 commits into from
Dec 18, 2020
Merged

feat: ComboBox component #694

merged 26 commits into from
Dec 18, 2020

Conversation

haworku
Copy link
Contributor

@haworku haworku commented Dec 7, 2020

Summary

USWDS component: https://designsystem.digital.gov/form-controls/03-combo-box/

Current Status:

  • ✅ basic functionality
    • Main component code is ComboBox.tsx and ComboBox.test.tsx.
    • Includes storybook examples (ComboBox.stories.tsx) and implementation in example app (/example files).
  • 🔎 5 tests are skipped with comments.
    • All represent valid minor bugs🐛, most relating to tab and hover behavior in the options dropdown.
    • Should we consider these blockers to merging this first pass?

Related Issues or PRs

closes #170

How To Test

  • Forms > ComboBox in storybook

Screenshots (optional)

Screen Shot 2020-12-07 at 12 19 31 PM

@haworku haworku added the type: feature New feature or request label Dec 7, 2020
@haworku haworku self-assigned this Dec 7, 2020
@haworku haworku requested a review from jim December 7, 2020 18:47
Copy link
Contributor

@suzubara suzubara left a comment

Choose a reason for hiding this comment

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

wow, this is an incredibly impressive PR and v1 of this component 👏 !! I think it is really solid and fine to follow up on the outstanding bugs as additional issues after merging. I left some comments, mostly noting differences between the tests and my UX manually testing in Chrome, and some questions.

The only thing I would consider a blocker is that I am seeing the selected value clear out whenever I blur, making it impossible to actually persist a value in the form (see gif). if we can fix that then I think this is good to go!

ComboBox bug

src/components/forms/ComboBox/ComboBox.test.tsx Outdated Show resolved Hide resolved

userEvent.click(getByTestId('combo-box-clear-button'))
fireEvent.blur(getByTestId('combo-box-clear-button'))
expect(getByTestId('combo-box-input')).toHaveFocus()
Copy link
Contributor

Choose a reason for hiding this comment

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

should the clear button be tabbable? I wasn't able to in chrome

Copy link
Contributor Author

@haworku haworku Dec 11, 2020

Choose a reason for hiding this comment

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

Yes. This is documented in a failing test.

Update: Fixed in fff5b90

key: 'ArrowDown',
})

expect(getByTestId('combo-box-option-yuzu')).toHaveFocus()
Copy link
Contributor

Choose a reason for hiding this comment

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

fwiw, in Chrome when I press the down arrow after the last option it does not change focus

Copy link
Contributor Author

@haworku haworku Dec 11, 2020

Choose a reason for hiding this comment

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

Yes. This is a failing test.

Update: Fixed in 0cba14f

})

expect(getByTestId('combo-box-option-apple')).toHaveFocus()
expect(getByTestId('combo-box-option-list')).toBeVisible()
Copy link
Contributor

Choose a reason for hiding this comment

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

this is not the behavior I'm seeing.. in Chrome when I have selected Apricot and the Apple option is focused and I press the up arrow, the menu closes

Copy link
Contributor Author

@haworku haworku Dec 11, 2020

Choose a reason for hiding this comment

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

🐛 This is a bug and this test should be failing. Changing fireEvent.focus to userEvent.hover(getByTestId('combo-box-option-apple')) makes it fail as it should. Great catch! 🌮

I'm gonna go through the tests and replace all instances of fireEvent.focus with userEvent.hover where relevant. In almost all cases that is the user behavior we are testing.

Update: fixed in 0cba14f

src/components/forms/ComboBox/ComboBox.test.tsx Outdated Show resolved Hide resolved
expect(getByTestId('combo-box-option-list')).toBeVisible()
})

it('hides options list when clicking away', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

should the options list be hidden if an option has focus and you click away? it hides when the input has focus and I click away but not if I've hovered over one of the options first

Copy link
Contributor Author

@haworku haworku Dec 11, 2020

Choose a reason for hiding this comment

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

🐛 It should be hidden in either case when you click away. That's a bug, will fix and write a test.

Update: fixed in 2bc43a2

userEvent.type(input, 'yu')
userEvent.click(getByTestId('combo-box-option-yuzu'))

expect(getByTestId('combo-box-input')).toHaveValue('Yuzu')
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be worth testing that the onChange handler was called with the value here

- does not change focus if last option focused, arrowDown pressed
- stays open when option selected, first option focused, arrowUp pressed
- replace fireEvent.focus w/ userEvents to ensure tests work as expected
@haworku
Copy link
Contributor Author

haworku commented Dec 14, 2020

The only thing I would consider a blocker is that I am seeing the selected value clear out whenever I blur, making it impossible to actually persist a value in the form (see gif). if we can fix that then I think this is good to go!

Fixed in e0ebc24 and e43493f. Thanks!!

-  tab once with selected option focuses the clear button
- tab twice with default value, and list open, focuses selected option
@haworku haworku requested a review from suzubara December 14, 2020 18:57
suzubara
suzubara previously approved these changes Dec 18, 2020
Copy link
Contributor

@suzubara suzubara left a comment

Choose a reason for hiding this comment

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

Verified that the fixes look great in Storybook! They don't seem to be reflected in the example app but that is an existing issue. This is awesome!! 🚢 🚀 🔥 🎉

(I took a look at the Happo diffs and they look fine, maybe will be resolved once this branch is updated from main or they could be a result of Happo updating their browsers)

@haworku haworku merged commit 824028a into main Dec 18, 2020
@haworku haworku deleted the feat-combobox branch December 18, 2020 22:02
This was referenced Dec 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New component: Combo box
3 participants