This commit is contained in:
Andrew Leach 2024-02-22 15:30:36 +00:00
Родитель c28985b6c7
Коммит 3995d9d201
2 изменённых файлов: 7 добавлений и 7 удалений

Просмотреть файл

@ -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
@ -81,7 +81,7 @@ 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')
@ -89,7 +89,7 @@ export default class Combobox {
}
focusDefaultOptionIfNeeded(): void {
if (this.firstOptionSelectionMode === 'focused') {
if (this.firstOptionSelectionMode === 'selected') {
this.navigate(1)
}
}

Просмотреть файл

@ -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
@ -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()
})
@ -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
@ -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()
})