diff --git a/package.json b/package.json index f661d8bd..f076c517 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ably/ui", - "version": "15.3.5", + "version": "15.3.6", "description": "Home of the Ably design system library ([design.ably.com](https://design.ably.com)). It provides a showcase, development/test environment and a publishing pipeline for different distributables.", "repository": { "type": "git", diff --git a/src/core/Accordion.tsx b/src/core/Accordion.tsx index 150ebef2..efd73888 100644 --- a/src/core/Accordion.tsx +++ b/src/core/Accordion.tsx @@ -1,4 +1,4 @@ -import React, { ReactNode, useMemo, useState } from "react"; +import React, { ReactNode, useMemo, useState, forwardRef } from "react"; import { AccordionContent, AccordionItem, @@ -138,68 +138,75 @@ const AccordionRow = ({ ); }; -const Accordion = ({ - data, - theme = "transparent", - icons = { - closed: { name: "icon-gui-plus-outline" }, - open: { name: "icon-gui-minus-outline" }, - }, - options, - ...props -}: AccordionProps) => { - const openIndexes = useMemo(() => { - const indexValues = data.map((_, i) => `accordion-item-${i}`); - return options?.fullyOpen - ? indexValues - : indexValues.filter((_, index) => - options?.defaultOpenIndexes?.includes(index), - ); - }, [options?.defaultOpenIndexes, options?.fullyOpen, data.length]); +const Accordion = forwardRef( + ( + { + data, + theme = "transparent", + icons = { + closed: { name: "icon-gui-plus-outline" }, + open: { name: "icon-gui-minus-outline" }, + }, + options, + ...props + }, + ref, + ) => { + const openIndexes = useMemo(() => { + const indexValues = data.map((_, i) => `accordion-item-${i}`); + return options?.fullyOpen + ? indexValues + : indexValues.filter((_, index) => + options?.defaultOpenIndexes?.includes(index), + ); + }, [options?.defaultOpenIndexes, options?.fullyOpen, data.length]); - const [openRowValues, setOpenRowValues] = useState( - openIndexes, - ); - const innerAccordion = data.map((item, index) => ( - { - item.onClick?.(index); - }} - openRowValues={openRowValues} - > - {item.content} - - )); + const [openRowValues, setOpenRowValues] = useState( + openIndexes, + ); + const innerAccordion = data.map((item, index) => ( + { + item.onClick?.(index); + }} + openRowValues={openRowValues} + > + {item.content} + + )); - return ( -
- {options?.autoClose ? ( - setOpenRowValues(values)} - > - {innerAccordion} - - ) : ( - setOpenRowValues(values)} - > - {innerAccordion} - - )} -
- ); -}; + return ( +
+ {options?.autoClose ? ( + setOpenRowValues(values)} + > + {innerAccordion} + + ) : ( + setOpenRowValues(values)} + > + {innerAccordion} + + )} +
+ ); + }, +); + +Accordion.displayName = "Accordion"; export default Accordion;