diff --git a/src/components/Accordion/Accordion.stories.mdx b/src/components/Accordion/Accordion.stories.mdx index e722e5c70..1e3180ac1 100644 --- a/src/components/Accordion/Accordion.stories.mdx +++ b/src/components/Accordion/Accordion.stories.mdx @@ -190,3 +190,55 @@ The expanded accordion section can be controlled by external state. {Template.bind({})} + +### Custom headings + +The `title` prop can be a `ReactNode`, allowing a higher degree of customisation of the section titles. + + + Advanced topics optional, + content: ( + <> +

Charm bundles

+

Machine authentication

+

Migrating models

+

Using storage

+

Working with actions

+

Working with resources

+

Cloud image metadata

+

Tools

+ + ), + }, + { + title: <>Networking optional, + content: ( + <> +

Working offline

+

Fan container networking

+

Network spaces

+ + ), + }, + { + title: <>Miscellaneous optional, + content: ( + <> +

Juju GUI

+

CentOS support

+

Collecting Juju metrics

+ + ), + }, + ], + titleElement: "h3", + }} + > + {Template.bind({})} +
+
diff --git a/src/components/Accordion/AccordionSection/AccordionSection.test.tsx b/src/components/Accordion/AccordionSection/AccordionSection.test.tsx index d30a4de6c..205804dae 100644 --- a/src/components/Accordion/AccordionSection/AccordionSection.test.tsx +++ b/src/components/Accordion/AccordionSection/AccordionSection.test.tsx @@ -87,4 +87,23 @@ describe("AccordionSection ", () => { expect(onTitleClick).toHaveBeenCalledWith(true, "first-key"); }); + + it("renders custom headings for titles", () => { + render( + Test} + expanded="abcd-1234" + setExpanded={jest.fn()} + title={ + <> + Test section + optional + + } + /> + ); + const title = screen.getByRole("tab"); + expect(title.children).toHaveLength(2); + expect(title).toHaveTextContent("Test section optional"); + }); }); diff --git a/src/components/Accordion/AccordionSection/AccordionSection.tsx b/src/components/Accordion/AccordionSection/AccordionSection.tsx index fcf4b234c..506cd1823 100644 --- a/src/components/Accordion/AccordionSection/AccordionSection.tsx +++ b/src/components/Accordion/AccordionSection/AccordionSection.tsx @@ -24,11 +24,11 @@ export type Props = { * An optional key to be used to track which section is selected. */ sectionKey?: string; - setExpanded?: (key: string | null, title: string | null) => void; + setExpanded?: (key: string | null, title: ReactNode | null) => void; /** * The title of the section. */ - title?: string; + title?: ReactNode; /** * Optional string describing heading element that should be used for the section titles. */