Skip to content

Commit 72b46a9

Browse files
committed
fix(accordion): add accordionItemComponent prop to support multiple
1 parent 1819eda commit 72b46a9

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

packages/kit-headless/src/components/accordion/accordion-inline.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, JSXNode, PropsOf, QRL, Signal } from '@builder.io/qwik';
2-
import { HAccordionItem } from './accordion-item';
32
import { HAccordionRootImpl } from './accordion-root';
3+
import { Accordion } from '@qwik-ui/headless';
44

55
export type AccordionRootProps = PropsOf<'div'> & {
66
/** If true, multiple items can be open at the same time. */
@@ -34,17 +34,20 @@ export type AccordionRootProps = PropsOf<'div'> & {
3434

3535
/** If true, the accordion is animated. */
3636
animated?: boolean;
37+
38+
accordionItemComponent: typeof Accordion.Item;
3739
};
3840

3941
export const HAccordionRoot: Component<AccordionRootProps> = (
4042
props: AccordionRootProps,
4143
) => {
42-
const { children: accordionChildren, ...rest } = props;
44+
const { children: accordionChildren, accordionItemComponent, ...rest } = props;
4345

4446
let currItemIndex = 0;
4547
let initialIndex = null;
4648
const itemsMap = new Map();
4749

50+
const InternalItemComponent = accordionItemComponent || Accordion.Item;
4851
const childrenToProcess = (
4952
Array.isArray(accordionChildren) ? [...accordionChildren] : [accordionChildren]
5053
) as Array<JSXNode>;
@@ -62,7 +65,7 @@ export const HAccordionRoot: Component<AccordionRootProps> = (
6265
}
6366

6467
switch (child.type) {
65-
case HAccordionItem: {
68+
case InternalItemComponent: {
6669
child.props._index = currItemIndex;
6770
if (props.value !== undefined && props.value === child.props.value) {
6871
initialIndex = currItemIndex;

packages/kit-styled/src/components/accordion/accordion.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import { cn } from '@qwik-ui/utils';
55

66
import { LuChevronDown } from '@qwikest/icons/lucide';
77

8-
const Root = component$<PropsOf<typeof HeadlessAccordion.Root>>((props) => (
9-
<HeadlessAccordion.Root animated {...props}>
10-
<Slot />
8+
const Root = (props: PropsOf<typeof HeadlessAccordion.Root>) => (
9+
<HeadlessAccordion.Root {...props} accordionItemComponent={Item} animated>
10+
{props.children}
1111
</HeadlessAccordion.Root>
12-
));
12+
);
1313

1414
const Item = component$<PropsOf<typeof HeadlessAccordion.Item>>((props) => {
1515
return (

0 commit comments

Comments
 (0)