Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Leach committed Feb 22, 2024
1 parent c28985b commit 3995d9d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type ComboboxSettings = {
}

// Indicates the default behaviour for the first option when the list is shown.
export type FirstOptionSelectionMode = 'none' | 'selected' | 'focused'
export type FirstOptionSelectionMode = 'none' | 'active' | 'selected'

export default class Combobox {
isComposing: boolean
Expand Down Expand Up @@ -81,15 +81,15 @@ export default class Combobox {
}

indicateDefaultOption(): void {
if (this.firstOptionSelectionMode === 'selected') {
if (this.firstOptionSelectionMode === 'active') {
Array.from(this.list.querySelectorAll<HTMLElement>('[role="option"]:not([aria-disabled="true"])'))
.filter(visible)[0]
?.setAttribute('data-combobox-option-default', 'true')
}
}

focusDefaultOptionIfNeeded(): void {
if (this.firstOptionSelectionMode === 'focused') {
if (this.firstOptionSelectionMode === 'selected') {
this.navigate(1)
}
}
Expand Down
8 changes: 4 additions & 4 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ describe('combobox-nav', function () {
})
})

describe('with defaulting to first option', function () {
describe('with defaulting to the first option being active', function () {
let input
let list
let options
Expand All @@ -263,7 +263,7 @@ describe('combobox-nav', function () {
input = document.querySelector('input')
list = document.querySelector('ul')
options = document.querySelectorAll('[role=option]')
combobox = new Combobox(input, list, {firstOptionSelectionMode: 'selected'})
combobox = new Combobox(input, list, {firstOptionSelectionMode: 'active'})
combobox.start()
})

Expand Down Expand Up @@ -313,7 +313,7 @@ describe('combobox-nav', function () {
})
})

describe('with defaulting to focusing the first option', function () {
describe('with defaulting to the first option being selected', function () {
let input
let list
let combobox
Expand All @@ -332,7 +332,7 @@ describe('combobox-nav', function () {
`
input = document.querySelector('input')
list = document.querySelector('ul')
combobox = new Combobox(input, list, {firstOptionSelectionMode: 'focused'})
combobox = new Combobox(input, list, {firstOptionSelectionMode: 'selected'})
combobox.start()
})

Expand Down

0 comments on commit 3995d9d

Please sign in to comment.