feat: set up accordion file structure, API, and a11y#6300
Conversation
|
📚 Branch Preview Links🔍 First Generation Visual Regression Test ResultsWhen a visual regression test fails (or has previously failed while working on this branch), its results can be found in the following URLs:
Deployed to Azure Blob Storage: If the changes are expected, update the |
432f56c to
057a70a
Compare
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
c6341e3 to
e63c363
Compare
96b68c9 to
e8dc485
Compare
| return; | ||
| } | ||
| this.open = !this.open; | ||
| const event = new Event(SWC_ACCORDION_ITEM_TOGGLE_EVENT, { |
There was a problem hiding this comment.
Do we need to emit dedicated open vs close events or at least use a CustomEvent so we can pass the actual open or close state to detail?
I think the system pattern is dedicated events, perhaps even swc-open, swc-after-open, swc-close, swc-after-close but I'm not entirely sure those are all necessary here.
There was a problem hiding this comment.
I guess the question is, do we need something like swc-open, swc-after-open, swc-close, swc-after-close? Do we need to differentiate between open and close? 🤔
It seems like we used those open/close events in overlay components in 1st-gen, but not in accordion. Are they needed in overlay because of the open/close animations and the time they take or because of something else, like how they can be triggered by hover/focus/other things rather than a click? And if we added some animation to the accordion panel would that change anything?
If we do need open/close events in 2nd-gen, then it seems like a CustomEvent would be a better way to go. If not, using Event and not passing any detail simplifies the implementation compared to its 1st-gen version.
There was a problem hiding this comment.
It feels like if we don't at least add detail to say the new/current state post-toggle, that we are putting the burden of "which is it?" on the consumer.
Sometimes folks try to force things like fetching data into an accordion which they'd only want to do on open, for example.
React's version does include some animation, and we would probably want to wait for any transition time to do the after-open just because a user might "cancel" the opening before that completes, so after-open becomes a bit more definitive signal.
You could pattern it after what I have in Tooltip, which also guards against duplicate events when there are more than one transitioning property. (And now makes me think since those are pretty generic maybe we should be sharing among any "visibility toggling" type of components)
| } | ||
| } | ||
|
|
||
| private syncActionsContainerVisibility(event: Event): void { |
There was a problem hiding this comment.
We have ObserveSlotPresence that is probably preferred here (see Badge base and the getter for hasIcon()). However, I'm not sure the check is necessary, depending on changes I suggested for modifying the layout away from a flex container in the style PR. Poooosssssssibly comment out and then check in styling if it's really needed?
There was a problem hiding this comment.
I see events added to the div later so maybe that's why, but see comment there :)
There was a problem hiding this comment.
Good point, using our pattern seems easier to reason about, going to remove syncActionsContainerVisibility in favor of ObserveSlotPresence. In that case, should we still worry about what styling is doing?
| @click=${this.stopActionsContainerPropagation} | ||
| @keydown=${this.stopActionsContainerPropagation} |
There was a problem hiding this comment.
Would you mind enlightening me on why this is needed?
There was a problem hiding this comment.
It's intended to prevent a click or keydown on the direct actions section from bubbling up to the accordion and unintentionally toggling the accordion item.
There was a problem hiding this comment.
Hmm, there is an additional check in Accordion.base to make sure the toggle event came from an accordion item. Plus, this div is outside the button, so I'm not sure how that bubble would occur? I'm probably missing some JS knowledge to understand!
I'm just pressing on this in hopes we can remove the need to check if this slot has content, and just allow either flex or grid behavior to eliminate holding space for it rather than toggle hidden.
5t3ph
left a comment
There was a problem hiding this comment.
Updates to handle events and simplify the handling for the actions area look good!
We can re-evaluate the need to check slot presence in the styling PR. We also might need to update event handling to be aware of transitions if those are added in styling.
f741213
into
swc-1854/accordion-migration
Description
Implements the 2nd-gen
<swc-accordion>and<swc-accordion-item>elements through phases 2–4 of the washing-machine workflow: scaffold, public API, and APG-aligned accessibility behavior.In this PR (part 1 of 2):
AccordionBase,AccordionItemBasebase classes with full public APIswc-accordion,swc-accordion-item)Chevron300Iconforxlitem sizingaccordion.cssDeferred to part 2, #6329:
accordion.test.tsplay test suite (ARIA contract, toggle, exclusive open, disabled, keyboard, heading level)sp-accordion/sp-accordion-itemdeprecation warnings and matching testsNot in this PR: S2 CSS (phase 5), full docs story matrix (phase 7), Playwright/aXe tests (phase 6), consumer migration guide.
Motivation and context
Establishes the 2nd-gen accordion contract before S2 styling. The cancellable
swc-accordion-item-toggleevent lets the host enforce exclusive-open without items knowingallow-multiple. HostdisabledusesparentDisabledstate so per-itemdisabledrestores correctly when the accordion re-enables. Theopensetter is guarded after first render so imperative assignment cannot bypass disabled state.Related issue(s)
Screenshots (if appropriate)
Author's checklist
Reviewer's checklist
patch,minor, ormajorfeaturesManual review test cases
Build and Storybook
yarn buildpasses with no accordion errorsallow-multiple,density,size,level,quiet,disabledall change elements or attributes in the DOM but may not visually have an effect in the UI.API and toggle
Because CSS is a placeholder, validate open/closed via DevTools (
openattribute,hiddenon panel).allow-multiple: multiple items can stay open simultaneouslylevelcontrol updates<h2>–<h6>in item shadow DOMdisabled: no items can toggle; per-itemdisabledpreserves correctly after host re-enabledisabled: header stays focusable;aria-disabled+ panelinert; no toggleitem.open = truewhile host or item is disabled does not expand the item (after first render)AccordionItem.focus()andclick()delegate to the header buttonKeyboard and a11y behavior
aria-expandedis"true"on open items,"false"on closed itemsaria-controlson the button matchesid="content"on the panelrole="region"andaria-labelledby="header"hiddenattributearia-disabled="true"(no nativedisabled) and panel isinertslot="actions"content does not propagate click/keydown to the toggle buttonDevice review
Accessibility testing checklist