Skip to content

Commit

Permalink
fix(accordion): remove dividers from hidden accordion items (#2219)
Browse files Browse the repository at this point in the history
* fix: remove dividers from hidden accordion items

* Create slimy-panthers-swim.md
  • Loading branch information
ryo-manba authored Mar 7, 2024
1 parent 798e84e commit 2c3be59
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
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

0 comments on commit 2c3be59

Please sign in to comment.