Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix indicateDefaultOption erroring when no options are visible #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2022

Conversation

iansan5653
Copy link
Member

@iansan5653 iansan5653 commented Jul 20, 2022

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 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
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