Skip to content

Commit

Permalink
Accordion Item ID fix (#2279)
Browse files Browse the repository at this point in the history
  • Loading branch information
endigo9740 authored Dec 3, 2023
1 parent 3801453 commit 30d295e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/giant-kings-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@skeletonlabs/skeleton": patch
---

bugfix: Accordion Item `on:toggle` event now provides `id` and `panelId` values
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// Event Dispatcher
type AccordionItemEvent = {
toggle: { event?: Event; id: string; open: boolean; autocollapse: boolean };
toggle: { event?: Event; id: string; panelId: string; open: boolean; autocollapse: boolean };
};
const dispatch = createEventDispatcher<AccordionItemEvent>();
Expand Down Expand Up @@ -108,8 +108,14 @@
function onToggle(event?: SvelteEvent<MouseEvent, HTMLButtonElement>): void {
const currentOpenState = autocollapse ? $active === id : open;
/** @event {{ event: Event, id: string, open: boolean, autocollapse: boolean }} toggle - Fires when an accordion item is toggled. */
dispatch('toggle', { event, id: `accordion-control-${id}`, open: currentOpenState, autocollapse });
/** @event {{ event: Event, id: string, panelId: string, open: boolean, autocollapse: boolean }} toggle - Fires when an accordion item is toggled. */
dispatch('toggle', {
event,
id,
panelId: `accordion-panel-${id}`,
open: currentOpenState,
autocollapse
});
}
// If auto-collapse mode enabled and item is set open, set as this item active
Expand All @@ -133,7 +139,7 @@
<button
type="button"
class="accordion-control {classesControl}"
id="accordion-control-{id}"
{id}
on:click={setActive}
on:click
on:keydown
Expand Down Expand Up @@ -172,7 +178,7 @@
out:dynamicTransition|local={{ transition: transitionOut, params: transitionOutParams, enabled: transitions }}
role="region"
aria-hidden={!openState}
aria-labelledby="accordion-control-{id}"
aria-labelledby={id}
>
<slot name="content">(content)</slot>
</div>
Expand Down

0 comments on commit 30d295e

Please sign in to comment.