Skip to content

Fix indicateDefaultOption erroring when no options are visible - #61

Merged
jfuchs merged 1 commit into
mainfrom
fix-option-not-found
Jul 20, 2022
Merged

Fix indicateDefaultOption erroring when no options are visible#61
jfuchs merged 1 commit into
mainfrom
fix-option-not-found

Conversation

@iansan5653

@iansan5653 iansan5653 commented Jul 20, 2022

Copy link
Copy Markdown
Member

When the list is hidden (ie, display:none), indicateDefaultOption is throwing an error:

Cannot read properties of undefined (reading 'setAttribute')

The expected behavior is to do nothing in this case, as it's common to call stop() after hiding the list. When start() is called again, the default option will then be indicated.

This fixes the bug by using optional chaining to only call setAttribute if the element is found. Also added a test for this case.

@iansan5653
iansan5653 requested review from a team and jfuchs July 20, 2022 20:19
Comment thread test/test.js
Comment on lines +292 to +297
it('does not error when no options are visible', () => {
assert.doesNotThrow(() => {
document.getElementById('list-id').style.display = 'none'
combobox.clearSelection()
})
})

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirmed - the test does fail without this fix

@jfuchs
jfuchs merged commit 6c2ff80 into main Jul 20, 2022
@jfuchs
jfuchs deleted the fix-option-not-found branch July 20, 2022 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants