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

How to best initialize an open state based on params attribute #2

Open
sethaddison opened this issue Sep 1, 2023 · 0 comments
Open

Comments

@sethaddison
Copy link

sethaddison commented Sep 1, 2023

I'm using an accordion to clean up a large sidebar navigation menu. If a given nav item is selected, it's parent accordion item should be toggled open on page load. I'm currently doing this with a child controller here: import AccordionController from "@kanety/stimulus-accordion"; export default class extends AccordionController { static values = { guide: Number, }; connect() { const el = document.querySelector( `[data-accordion-id=content${this.guideValue}]` ); el.classList.add("st-accordion__content--visible"); } }

This works, but it's not perfect because the initial element will still contain "st-accordion__content--visible" even after another element is toggled. Can you recommend a cleaner approach to this? I think you are using binding observers, which I am not familiar with.

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

No branches or pull requests

1 participant