Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/slimy-panthers-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nextui-org/accordion": patch
---

fixed remove dividers from hidden accordion items (#2210)
19 changes: 19 additions & 0 deletions packages/components/accordion/__tests__/accordion.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,25 @@ describe("Accordion", () => {
expect(wrapper.getAllByRole("button")[0]).toBeDisabled();
});

it("should hide the accordion item when the hidden prop is set", () => {
const wrapper = render(
<Accordion>
<AccordionItem key="1" title="Accordion Item 1">
Accordion Item 1 description
</AccordionItem>
<AccordionItem key="2" hidden title="Accordion Item 2">
Accordion Item 2 description
</AccordionItem>
<AccordionItem key="3" title="Accordion Item 3">
Accordion Item 3 description
</AccordionItem>
</Accordion>,
);

expect(wrapper.getAllByRole("button")).toHaveLength(2);
expect(wrapper.getAllByRole("separator")).toHaveLength(1);
});

it("should expand the accordion item when clicked", async () => {
const wrapper = render(
<Accordion disableAnimation>
Expand Down
5 changes: 4 additions & 1 deletion packages/components/accordion/src/accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ const AccordionGroup = forwardRef<"div", AccordionProps>((props, ref) => {
{...item.props}
classNames={classNames}
/>
{!isSplitted && showDivider && index < state.collection.size - 1 && <Divider />}
{!item.props.hidden &&
!isSplitted &&
showDivider &&
index < state.collection.size - 1 && <Divider />}
</Fragment>
);
});
Expand Down