diff --git a/lib/components/Accordion/Accordion.stories.tsx b/lib/components/Accordion/Accordion.stories.tsx
index 71374f7..3793082 100644
--- a/lib/components/Accordion/Accordion.stories.tsx
+++ b/lib/components/Accordion/Accordion.stories.tsx
@@ -42,8 +42,6 @@ export const Default: Story = {
title: 'Title',
children: 'Content',
lang: 'en',
- expandMoreText: 'Show more',
- expandLessText: 'Show less',
},
};
@@ -59,10 +57,9 @@ export const TitleComponent: Story = {
},
args: {
title:
Title
,
+ titleText: 'Title',
children: 'Content',
lang: 'en',
- expandMoreText: 'Show more',
- expandLessText: 'Show less',
},
};
@@ -81,7 +78,5 @@ export const WithUnderline: Story = {
children: 'Content',
underline: true,
lang: 'en',
- expandMoreText: 'Show more',
- expandLessText: 'Show less',
},
};
diff --git a/lib/components/Accordion/Accordion.test.tsx b/lib/components/Accordion/Accordion.test.tsx
index c09a9f5..0025407 100644
--- a/lib/components/Accordion/Accordion.test.tsx
+++ b/lib/components/Accordion/Accordion.test.tsx
@@ -6,19 +6,17 @@ import { Accordion } from './Accordion';
describe('Accordion', () => {
const title = 'Accordion Title';
- const expandLessText = 'Expand Less';
- const expandMoreText = 'Expand More';
const lang = 'en';
test('renders accordion with open state by default', () => {
const { container } = render(
-
+
Default content
,
);
const accordionTitle = screen.getByText(title);
- const expandButton = screen.getByLabelText(expandLessText);
+ const expandButton = screen.getByRole('button');
const accordionContent = screen.queryByText('Default content');
expect(accordionTitle).toBeInTheDocument();
@@ -29,12 +27,12 @@ describe('Accordion', () => {
test('closes accordion when expand button is clicked', () => {
render(
-
+
Content to be gone
,
);
- const expandButton = screen.getByLabelText(expandLessText);
+ const expandButton = screen.getByRole('button');
fireEvent.click(expandButton);
const accordionContent = screen.queryByText('Content to be gone');
diff --git a/lib/components/Accordion/Accordion.tsx b/lib/components/Accordion/Accordion.tsx
index d28d60f..eeb0d7c 100644
--- a/lib/components/Accordion/Accordion.tsx
+++ b/lib/components/Accordion/Accordion.tsx
@@ -2,15 +2,23 @@ import React from 'react';
import { MdExpandLess, MdExpandMore } from 'react-icons/md';
import { cx } from '../../cva';
-interface AccordionProps {
+type TitleProps =
+ | {
+ title: React.ReactNode;
+ titleText: string;
+ }
+ | {
+ title: string;
+ titleText?: never;
+ };
+
+type AccordionProps = {
title: React.ReactNode | string;
children: React.ReactNode;
- expandLessText: string;
- expandMoreText: string;
lang: string;
underline?: boolean;
intialState?: boolean;
-}
+} & TitleProps;
const Caret = ({ isOpen }: { isOpen: boolean }) => (
@@ -18,15 +26,7 @@ const Caret = ({ isOpen }: { isOpen: boolean }) => (
);
-export const Accordion = ({
- title,
- children,
- expandLessText,
- expandMoreText,
- lang,
- underline,
- intialState = true,
-}: AccordionProps) => {
+export const Accordion = ({ title, titleText, children, lang, underline, intialState = true }: AccordionProps) => {
const [isOpen, setIsOpen] = React.useState(intialState);
const toggleOpen = () => setIsOpen(!isOpen);
const isTitleValidElement = React.isValidElement(title);
@@ -47,17 +47,13 @@ export const Accordion = ({
{isTitleValidElement ? (
{title}
-
) : (
-
+
renders accordion with open state by default 1`] = `
class="ds-group"
>