[Feature Request] Accordion component is too opinionated #4666
Replies: 7 comments 1 reply
-
ENG-389 [Feature Request] Accordion component is too opinionated |
Beta Was this translation helpful? Give feedback.
-
Hey, thanks for flagging this issue. I managed to avoid this annoying constraint with a little hack. {Object.entries(config).map(([key, config]) => typeof config == "number" ?
<WeaponAccordion weapon={key} recoil={config}/> : <OperatorAccordion operator={key} recoil={config}/>)} I wrote <Accordion selectionMode="multiple" className={"w-fit"}>
{Object.entries(config).map(([key, config]) => {
if (typeof config == "number") {
return WeaponAccordion({weapon: key, recoil: config})
} else {
return OperatorAccordion({operator: key, recoil: config})
}
})}
</Accordion> This worked, since the 2nd code doesnt create an interim component, just returns the |
Beta Was this translation helpful? Give feedback.
-
Minor issue is that from my findings, it will break HMR so you will manually have to restart. |
Beta Was this translation helpful? Give feedback.
-
it would be great if the |
Beta Was this translation helpful? Give feedback.
-
EDIT: This commented problem is no longer valid. I've managed to build an AccordionTree component and opened a pull request to add as an additional component, as I think it would be a useful feature for other users. https://github.com/nextui-org/nextui/pull/3778 ---> IGNORE BELOW
|
Beta Was this translation helpful? Give feedback.
-
I believe I'm hitting this issue, too. When I attempt to use my own accordion item component: <Accordion className="rotate-0">
<MyAccordionItem title="foo" />
</Accordion> I get this error at runtime:
For now I'm using a different version of @wowjeeez ' workaround - instead of rendering the component with JSX, it works to call it like a function: <Accordion className="rotate-0">
{MyAccordionItem({
title: "Overview",
moreProps: "here
})}
</Accordion> |
Beta Was this translation helpful? Give feedback.
-
gahh just hit this problem too. I need to create my own item component as it needs to fetch some data, and want it server side rendered. I can't call a function as that would need to be async, and can't then call that within JSX as a far as I can see? |
Beta Was this translation helpful? Give feedback.
-
Is your feature request related to a problem? Please describe.
The documentation states that the
children
prop for the Accordion component can be eitherReactNode
orReactNode[]
.However, in practice, only an array of
AccordionItem
can be used. TheAccordionItem
(accordion-item.tsx) used within the Accordion isn't exported. It can only be created by the Accordion component itself. The exportedAccordionItem
isn't a "true" React component; it's more of a configuration object.So, the first issue is the misleading documentation. I wasted quite a bit of time trying to create my own
AccordionItem
.The second problem is the component's opinionated structure. The entire title of the
AccordionItem
is a single button, which is already causing issues for users.Describe the solution you'd like
I would like the ability to use custom
AccordionItem
s in theAccordion
component. Right now, this isn't feasible without having to rewrite both components. Less opinionated implementation also would be nice. For example, Radix UI uses two different components — Accordion.Header and AccordionTrigger.Describe alternatives you've considered
A potential workaround is rewriting both the
Accordion
andAccordionItem
, reusing the internal components such as types and hooks.Screenshots or Videos
No response
Beta Was this translation helpful? Give feedback.
All reactions