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: add combo box component #399

Merged
merged 33 commits into from
Oct 19, 2020
Merged

Conversation

jim
Copy link
Contributor

@jim jim commented Aug 13, 2020

Add Combo Box

This PR is a first pass at adding the combo box component. We are merging to a feature branch for now since we anticipate refactoring the component.

The initial implement uses a prop for handling the options list and setFieldValue to control the input value.

There are significant tests added, which will help be a guard us as future refactors are made.

Related Issues or PRs

related to #170

How To Test

  1. Open storybook and verify that the behavior matches what is shown in the USWDS version.

@jim jim requested review from suzubara and haworku August 13, 2020 15:28
yarn.lock Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
@jim
Copy link
Contributor Author

jim commented Aug 17, 2020

There is a bug where the option list displays as empty if there is already a value selected. I think it stems from the filtering logic.

Copy link
Contributor

@haworku haworku left a comment

Choose a reason for hiding this comment

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

Its great to see progress on this!

One overarching comment -I think now we need to see if we can simplify the component state more. Can we track less things in the state, have less cases where we need to manually call things in a certain order (update the selected value, update the focus, update the focus mode, update whats open)?

Update: @jim and I paired on this and started looking at if its possible to separate out behaviors the input takes from the dropdown list (instead of having ComboBox manage the state for everything, delegate some of that to nested components).

onBlur={handleInputBlur}
onClick={handleInputClick}
onKeyDown={handleInputKeyDown}
onChange={(e): void => setInputValue(e.target.value)}
Copy link
Contributor

@haworku haworku Aug 17, 2020

Choose a reason for hiding this comment

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

I think we want to allow the consumer to still be able to call their own onChange passed in from the selectProps.onChange. I can't tell would that still happen the way things are written now? Lets write a test case to make sure.

return {
...state,
inputValue: '',
selectedOption: undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

Also need to reset filteredOptions on this action to props.action

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a test stub to cover this case.

} = props

let defaultLabel = ''
if (defaultValue) {
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 a bit confusing because the defaultValue is usually the display text.

Right now its written as if that string will be the option id. Maybe we should change to selectedOption and just pass the whole option object in? Or else rename this defaultValue to something like defaultOptionId

@jim jim self-assigned this Aug 24, 2020
@haworku
Copy link
Contributor

haworku commented Sep 17, 2020

@jim Checking in! Thanks for your work so far on this. What is the outstanding work here? Would love to get this merged and can help make sure that happens.

@jim
Copy link
Contributor Author

jim commented Sep 21, 2020

@haworku There are some missing tests to implement, and probably a few to write.

The biggest TODO, though, is to make a decision about how to proceed in terms of what props are required to use the ComboBox. Right now, we expect a setFieldValue function to be passed in, which is out of alignment with the rest of the components in this library (which only need to pass onChange).

@haworku haworku changed the base branch from main to feat-combobox October 19, 2020 16:22
@haworku haworku marked this pull request as ready for review October 19, 2020 16:27
@haworku haworku merged commit 81bba2d into feat-combobox Oct 19, 2020
@haworku haworku deleted the jb-feat-add-combo-box-170 branch October 19, 2020 19:51
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.

New component: Combo box
3 participants