creativecommons / creativecommons/cc-resource-archive

[Bug] Uncaught TypeError in vocabulary.js due to Missing menuButton and menuPanel Elements .

Open
#345 2 comments 0 reactions 0 assignees View on GitHub
💻 aspect: code 🚧 status: blocked 🛠 goal: fix 🟩 priority: low
Dominant language
Dockerfile
Stars
66
Forks
137
PR merge metrics
No merged PRs in 30d

Description

## Description
I've noticed an issue in `vocabulary.js` where the code attempts to add an event listener to `menuButton` and toggle a class on `menuPanel,` but these elements are not present in the HTML file. This results in an `Uncaught TypeError` due to trying to call `addEventListener` on `null`.

## Reproduction

1. Open the webpage.
2. Right-click and select Inspect (or press Ctrl+Shift+I / Cmd+Option+I on Mac).
3. Open the console.
4. See error.

## Expectation

The application should handle the absence of the `menuButton` and `menuPanel `elements gracefully without throwing an error.

## Screenshots

Screenshot 2024-11-01 at 12 22 37 AM

## Suggested Fix:

Adding checks to see if `menuButton `and `menuPanel` exist before using them.
## Environment
- OS: (macOS)
- Browser: (Chrome)

## Additional context
If the `menuButton` and `menuPanel` elements aren't needed because the menu functionality is not being used, the best approach might be to:

- **Remove the Code:** If the menu functionality is entirely unnecessary, the cleanest solution is to remove the related code. This avoids unnecessary checks and potential errors.
- **Use Conditional Code:** If the menu might be added in the future or conditionally in specific layouts, you can leave the code with null checks to ensure it only runs when the elements are present.

## Resolution

- [x] I would be interested in resolving this bug.

Contributor guide

Open the contributing guide

Research direction

Start in vocabulary.js and inspect how menuButton and menuPanel are queried and used, then compare those references with the HTML elements present on the webpage. Reproduce the issue in Chrome and confirm the page loads without an uncaught TypeError when those elements are absent; the intended handling should follow the project’s decision on whether the menu is needed.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.