Skip to content

Commit

Permalink
Merge pull request #61 from github/fix-option-not-found
Browse files Browse the repository at this point in the history
Fix `indicateDefaultOption` erroring when no options are visible
  • Loading branch information
jfuchs authored Jul 20, 2022
2 parents e4390ae + 3b5dc97 commit 6c2ff80
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default class Combobox {
if (this.defaultFirstOption) {
Array.from(this.list.querySelectorAll<HTMLElement>('[role="option"]:not([aria-disabled="true"])'))
.filter(visible)[0]
.setAttribute('data-combobox-option-default', 'true')
?.setAttribute('data-combobox-option-default', 'true')
}
}

Expand Down
7 changes: 7 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,5 +288,12 @@ describe('combobox-nav', function () {
combobox.clearSelection()
assert.equal(document.querySelectorAll('[data-combobox-option-default]').length, 1)
})

it('does not error when no options are visible', () => {
assert.doesNotThrow(() => {
document.getElementById('list-id').style.display = 'none'
combobox.clearSelection()
})
})
})
})

0 comments on commit 6c2ff80

Please sign in to comment.