Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/components/List/ListAccordionGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const ListAccordionGroup = ({
return (
<ListAccordionGroupContext.Provider
value={{
expandedId: expandedIdProp || expandedId, // component can be controlled or uncontrolled
expandedId: expandedIdProp ?? expandedId, // component can be controlled or uncontrolled
onAccordionPress: onAccordionPress || onAccordionPressDefault,
}}
>
Expand Down
16 changes: 16 additions & 0 deletions src/components/__tests__/ListAccordion.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,22 @@ describe('ListAccordion', () => {
await expect(render(<ListAccordionTest />)).resolves.toBeDefined();
});

it('expands the accordion with id={0} when it is the controlled expandedId', async () => {
await render(
<ListAccordionGroup expandedId={0} onAccordionPress={() => {}}>
<ListAccordion title="First accordion" id={0}>
<ListItem title="First accordion item" />
</ListAccordion>
<ListAccordion title="Second accordion" id={1}>
<ListItem title="Second accordion item" />
</ListAccordion>
</ListAccordionGroup>
);

expect(screen.getByText('First accordion item')).toBeOnTheScreen();
expect(screen.queryByText('Second accordion item')).not.toBeOnTheScreen();
});

it('should throw an error when id={""}', async () => {
const ListAccordionTest = () => (
<ListAccordionGroup>
Expand Down
Loading