va-accordion: add custom event to expand/collapse all button #1445
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Chromatic
https://2380-accordion-toggle-event--65a6e2ed2314f7b8f98609d8.chromatic.com
Description
This will add a custom event
accordionExpandCollapseAll
that will fire when the expand/collapse button is clicked. This is so teams can keep track of the all accordion open/closed states when navigating between pages.I attempted to solve this by firing the existing
accordionItemToggled
custom event when expand/collapse is clicked usingMutationObserver
. This way teams wouldn't have to do any changes to their current open/close state tracking logic and future teams wouldn't have to deal with multiple events.Unfortunately, this creates a race condition because the parent
va-accordion
component is listening for that event too and doing some logic which is creating a loop.Looking at the existing example from the forms-library, specifically here in the handleToggleChapter callback, I don't think it will be too much effort to modify the callback to include the expand/collapse all event and it might be wiser to keep these two events separate anyway.
Closes department-of-veterans-affairs/vets-design-system-documentation#2380
QA Checklist
Screenshots
Acceptance criteria
Definition of done