Skip to content
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

Use optional chaining to add listeners to optional UI elements. #1

Merged
merged 1 commit into from
Jan 30, 2022

Conversation

mechie
Copy link
Contributor

@mechie mechie commented Jan 28, 2022

Because some UI elements are optional, code assuming they always exist was causing some of the JS to fail.

Notably, the mobile menu was inoperable unless the '...' sidebar was enabled, since trying to add a listener to the non-existent sidebar button would error out the JS function before it could add the listener for the mobile menu.

To reproduce the mentioned error, set enable_sidebar = false in your config.toml's [extra] and try serving or building--the mobile menu hamburger will do nothing, and opening the dev console will show a js error.

Because some UI elements are optional, code assuming they always exist
was causing some of the JS to fail.

Notably, the mobile menu was inoperable unless the '...' sidebar was
enabled, since trying to add a listener to the non-existent sidebar
button would error out the JS function before it could add the listener
for the mobile menu.

Same changes included in the minified js.
@tchartron
Copy link
Owner

Thanks for your contribution, no doubt it's better with optionnal chaining.

@tchartron tchartron merged commit 19ce007 into tchartron:main Jan 30, 2022
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