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
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
81bba2d
feat: add combo box component (#399)
jim Oct 19, 2020
c62e225
WIP
haworku Oct 19, 2020
ed46f20
Add notes
haworku Oct 21, 2020
45c888c
Get combobox working in example app, but buggy
haworku Oct 22, 2020
8936104
Move callback invocation out of the reducer.
Nov 5, 2020
84eb55b
Remove setFieldValue
Nov 5, 2020
474e8c6
Write all filtering, clear button tests. Passing when expected
haworku Dec 1, 2020
37f91b9
Write keyboard tests. Passing when expected
haworku Dec 3, 2020
e7a708a
Write a11y and mouse action tests. Passing expected.
haworku Dec 3, 2020
0508246
All tests passing. Failing tests skipped and bugs commented inline
haworku Dec 4, 2020
6629d21
Add noResults prop, cleanup
haworku Dec 4, 2020
65199e6
Tests passing. Fix major bugs with filtering, CLEAR, CLOSE_LIST
haworku Dec 4, 2020
d5bd173
Create useCombobox hook
haworku Dec 4, 2020
dcd420f
Cleanup
haworku Dec 7, 2020
190a65d
Merge remote-tracking branch 'origin/main' into feat-combobox
haworku Dec 7, 2020
98fc7f5
Merge branch 'main' into feat-combobox
haworku Dec 11, 2020
f6a08d3
Merge branch 'main' into feat-combobox
haworku Dec 11, 2020
2191d57
Update tests based on @suzubara code review. Failures represent bugs …
haworku Dec 11, 2020
e0ebc24
Fix bug: input content persists after blur
haworku Dec 11, 2020
2bc43a2
Fix bug: hides options list when clicking away and a specific option …
haworku Dec 14, 2020
0cba14f
Fix bug: arrow key behaviors within options list
haworku Dec 14, 2020
2df25be
Tests passing
haworku Dec 14, 2020
e43493f
Update handleInputBlur further
haworku Dec 14, 2020
fff5b90
Fix bug: tab key behaviors
haworku Dec 14, 2020
a776f5f
Include yarn.lock
haworku Dec 18, 2020
719e903
Merge branch 'main' into feat-combobox
haworku Dec 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix bug: hides options list when clicking away and a specific option …
…has focus
  • Loading branch information
haworku committed Dec 14, 2020
commit 2bc43a2bbc06095d74b152bf1de9669b6a221ccb
2 changes: 1 addition & 1 deletion src/components/forms/ComboBox/ComboBox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ describe('ComboBox component', () => {
fireEvent.click(getByTestId('combo-box-input'))
userEvent.hover(getByTestId('combo-box-option-blackberry'))

fireEvent.blur(getByTestId('combo-box-option-list'))
fireEvent.blur(getByTestId('combo-box-option-blackberry'))

expect(getByTestId('combo-box-input')).toHaveAttribute(
'aria-expanded',
Expand Down
19 changes: 16 additions & 3 deletions src/components/forms/ComboBox/ComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,14 @@ export const ComboBox = (props: ComboBoxProps): React.ReactElement => {
}

const handleInputBlur = (event: FocusEvent<HTMLInputElement>): void => {
const { target: elementLosingFocus, relatedTarget: newTarget } = event

if (state.selectedOption?.value) return
const target = event.relatedTarget

if (
!target ||
(target instanceof Node && !containerRef.current?.contains(event.target))
!newTarget ||
(newTarget instanceof Node &&
!containerRef.current?.contains(elementLosingFocus))
) {
dispatch({ type: ActionTypes.CLEAR })
}
Expand Down Expand Up @@ -175,6 +177,16 @@ export const ComboBox = (props: ComboBoxProps): React.ReactElement => {
}
}
}
const handleListItemBlur = (event: FocusEvent<HTMLLIElement>): void => {
const { relatedTarget: newTarget } = event

if (
!newTarget ||
(newTarget instanceof Node && !containerRef.current?.contains(newTarget))
) {
dispatch({ type: ActionTypes.CLOSE_LIST })
}
}

const handleListItemKeyDown = (event: KeyboardEvent): void => {
if (event.key === 'Escape') {
Expand Down Expand Up @@ -297,6 +309,7 @@ export const ComboBox = (props: ComboBoxProps): React.ReactElement => {
aria-posinset={index + 1}
id={listID + `--option-${index}`}
onKeyDown={handleListItemKeyDown}
onBlur={handleListItemBlur}
data-testid={`combo-box-option-${option.value}`}
onMouseMove={(): void =>
dispatch({ type: ActionTypes.FOCUS_OPTION, option: option })
Expand Down