Skip to content

Commit 3b5dc97

Browse files
authored
Fix indicateDefaultOption erroring when no options are visible
1 parent 153b90b commit 3b5dc97

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default class Combobox {
7777
if (this.defaultFirstOption) {
7878
Array.from(this.list.querySelectorAll<HTMLElement>('[role="option"]:not([aria-disabled="true"])'))
7979
.filter(visible)[0]
80-
.setAttribute('data-combobox-option-default', 'true')
80+
?.setAttribute('data-combobox-option-default', 'true')
8181
}
8282
}
8383

test/test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,5 +288,12 @@ describe('combobox-nav', function () {
288288
combobox.clearSelection()
289289
assert.equal(document.querySelectorAll('[data-combobox-option-default]').length, 1)
290290
})
291+
292+
it('does not error when no options are visible', () => {
293+
assert.doesNotThrow(() => {
294+
document.getElementById('list-id').style.display = 'none'
295+
combobox.clearSelection()
296+
})
297+
})
291298
})
292299
})

0 commit comments

Comments
 (0)