Skip to content

Commit

Permalink
feat: Support id for Accordion (#2101)
Browse files Browse the repository at this point in the history
* feat: Support id for Accordion
  • Loading branch information
denysoblohin-okta committed Jan 29, 2024
1 parent 5c278ed commit 3ecb265
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions packages/odyssey-react-mui/src/Accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ import {
} from "@mui/material";
import { ChevronDownIcon } from "./icons.generated";
import { Support } from "./Typography";
import { useUniqueId } from "./useUniqueId";

export type AccordionProps = {
/**
* The content of the Accordion itself
*/
children: ReactNode;
/**
* Defines IDs for the header and the content of the Accordion
*/
id?: string;
/**
* The label text for the AccordionSummary
*/
Expand Down Expand Up @@ -66,12 +71,16 @@ const Accordion = ({
children,
label,
hasShadow = true,
id: idOverride,
isDefaultExpanded,
isDisabled,
isExpanded,
onChange,
translate,
}: AccordionProps) => {
const id = useUniqueId(idOverride);
const headerId = `${id}-header`;
const contentId = `${id}-content`;
return (
<MuiAccordion
defaultExpanded={isDefaultExpanded}
Expand All @@ -81,12 +90,18 @@ const Accordion = ({
onChange={onChange}
className={hasShadow ? `hasShadow` : undefined}
>
<MuiAccordionSummary expandIcon={<ChevronDownIcon />}>
<MuiAccordionSummary
aria-controls={contentId}
expandIcon={<ChevronDownIcon />}
id={headerId}
>
<Support component="div" translate={translate}>
{label}
</Support>
</MuiAccordionSummary>
<MuiAccordionDetails>{children}</MuiAccordionDetails>
<MuiAccordionDetails aria-labelledby={headerId}>
{children}
</MuiAccordionDetails>
</MuiAccordion>
);
};
Expand Down

0 comments on commit 3ecb265

Please sign in to comment.