Skip to content

Commit

Permalink
Update accordion section to use passed in ID for header (not just uni…
Browse files Browse the repository at this point in the history
…que ID)
  • Loading branch information
nishasy committed Nov 15, 2023
1 parent 5f53d51 commit 8f11dae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,11 @@ describe("Accordion", () => {
// Arrange
render(
<Accordion>
<AccordionSection header="Section 1" testId="section-1">
<AccordionSection
id="accordion-section-id-for-test"
header="Section 1"
testId="section-1"
>
Section 1 content
</AccordionSection>
<AccordionSection header="Section 2">
Expand All @@ -492,9 +496,10 @@ describe("Accordion", () => {
);

// Assert
// Not testing the actual value of the aria-labelledby attribute
// because it comes from the unique ID generator.
expect(section1ContentPanel).toHaveAttribute("aria-labelledby");
expect(section1ContentPanel).toHaveAttribute(
"aria-labelledby",
"accordion-section-id-for-test-header",
);
});

describe("keyboard navigation", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ const AccordionSection = React.forwardRef(function AccordionSection(
const sectionId = id ?? ids.get("accordion-section");
// We need an ID for the header so that the content section's
// aria-labelledby attribute can point to it.
const headerId = ids.get("accordion-section-header");
const headerId = id ? `${id}-header` : ids.get("accordion-section-header");
// We need an ID for the content section so that the opener's
// aria-controls attribute can point to it.
const sectionContentUniqueId = ids.get("accordion-section-content");
Expand Down

0 comments on commit 8f11dae

Please sign in to comment.