Skip to content

Commit

Permalink
fix(UsaComboBox): space selects the current highlighted option
Browse files Browse the repository at this point in the history
Bring inline with USWDS 3.5.0 changes: https://github.com/uswds/uswds/releases/tag/v3.5.0
  • Loading branch information
patrickcate committed Oct 10, 2023
1 parent 6f07c3d commit 246ed7b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/components/UsaComboBox/UsaComboBox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,11 @@ describe('UsaComboBox', () => {
'.usa-combo-box__list > li.usa-combo-box__list-option:nth-child(64)'
).trigger('mouseover')

// Select option by pressing spacebar.
cy.get('.usa-combo-box__list > li.usa-combo-box__list-option:nth-child(64)')
.should('have.class', 'usa-combo-box__list-option--focused')
.and('have.focus')

// Select option by pressing tab.
cy.realPress('Tab')
.type(' ')

cy.get('.usa-combo-box__list > li.usa-combo-box__list-option:nth-child(64)')
.should('not.have.focus')
Expand Down
4 changes: 2 additions & 2 deletions src/components/UsaComboBox/UsaComboBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const {
handleFilterOnInput,
handleHoverOnListOption,
handleListToggle,
handleTabOnListOption,
handleSpaceOnListOption,
handleUpOnListOption,
highlightedOption,
inputElement,
Expand Down Expand Up @@ -248,7 +248,7 @@ const classes = computed(() => [
@keydown.prevent.up="handleUpOnListOption(index)"
@keydown.prevent.down="handleDownOnListOption(index)"
@keydown.prevent.enter="handleEnterOnListOption(option.value)"
@keydown.prevent.tab.exact="handleTabOnListOption(option.value)"
@keydown.prevent.space="handleSpaceOnListOption(option.value)"
@mouseover="handleHoverOnListOption(option.value)"
>{{ option.label }}</li
>
Expand Down
4 changes: 2 additions & 2 deletions src/composables/useComboBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export default (_id, _selectedOption, _options, _disabled, _readonly, emit) => {
}
}

const handleTabOnListOption = value => {
const handleSpaceOnListOption = value => {
selectOption(value)
closeList()
focusInput()
Expand Down Expand Up @@ -452,7 +452,7 @@ export default (_id, _selectedOption, _options, _disabled, _readonly, emit) => {
handleFilterOnInput,
handleHoverOnListOption,
handleListToggle,
handleTabOnListOption,
handleSpaceOnListOption,
handleUpOnListOption,
highlightedOption: readonly(highlightedOption),
inputElement,
Expand Down

0 comments on commit 246ed7b

Please sign in to comment.