Skip to content

Commit

Permalink
fix(LEMS-2086): Add aria label to Popover Content (#2263)
Browse files Browse the repository at this point in the history
## Summary:
Aria-labels are not being added to the `View` component, causing accessibility issues. 
This PR adds aria-label to `View`

Issue: LEMS-2089

## Test plan:

Author: anakaren-rojas

Reviewers: catandthemachines, jeresig, anakaren-rojas, handeyeco

Required Reviewers:

Approved By: catandthemachines, jeresig, jeresig

Checks: ✅ Chromatic - Get results on regular PRs (ubuntu-latest, 20.x), ✅ Lint (ubuntu-latest, 20.x), ✅ Test (ubuntu-latest, 20.x, 2/2), ✅ Test (ubuntu-latest, 20.x, 1/2), ✅ Check build sizes (ubuntu-latest, 20.x), ✅ Chromatic - Build on regular PRs / chromatic (ubuntu-latest, 20.x), ⏭️  Chromatic - Skip on Release PR (changesets), ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Prime node_modules cache for primary configuration (ubuntu-latest, 20.x), ✅ gerald, ✅ Chromatic - Get results on regular PRs (ubuntu-latest, 20.x), ✅ codecov/project, ✅ Check build sizes (ubuntu-latest, 20.x), ✅ Test (ubuntu-latest, 20.x, 2/2), ✅ Lint (ubuntu-latest, 20.x), ✅ Test (ubuntu-latest, 20.x, 1/2), ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Chromatic - Build on regular PRs / chromatic (ubuntu-latest, 20.x), ✅ Prime node_modules cache for primary configuration (ubuntu-latest, 20.x), ⏭️  Chromatic - Skip on Release PR (changesets), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ gerald, ⏭️  dependabot

Pull Request URL: #2263
  • Loading branch information
anakaren-rojas authored Jul 1, 2024
1 parent 69c6b37 commit 78ee53c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/selfish-spiders-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/wonder-blocks-popover": patch
---

Adding aria label attr to View component
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,43 @@ describe("Popover", () => {
}),
).toBeInTheDocument();
});

it("should correctly describe the popover content core's aria label", async () => {
// Arrange
render(
<Popover
onClose={jest.fn()}
content={
<PopoverContentCore aria-label="Popover Content Core">
<button data-close-button onClick={close}>
Close Popover
</button>
</PopoverContentCore>
}
>
<Button>Open default popover</Button>
</Popover>,
);

// Act
// Open the popover
const openButton = await screen.findByRole("button", {
name: "Open default popover",
});

await userEvent.click(openButton);
const popover = await screen.findByRole("dialog");

// disabling this check because we need to access the popover content core
// in order to verify the aria-label is getting passed correctly
// eslint-disable-next-line testing-library/no-node-access
const popoverContentCore = popover.firstChild as HTMLElement;

// Assert
expect(popoverContentCore.getAttribute("aria-label")).toBe(
"Popover Content Core",
);
});
});

describe("keyboard navigation", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export default class PopoverContentCore extends React.Component<Props> {

render(): React.ReactNode {
const {
"aria-label": ariaLabel,
children,
closeButtonLight,
closeButtonLabel,
Expand All @@ -87,6 +88,7 @@ export default class PopoverContentCore extends React.Component<Props> {
color !== "white" && styles[color],
style,
]}
aria-label={ariaLabel}
>
{closeButtonVisible && (
<CloseButton
Expand Down

0 comments on commit 78ee53c

Please sign in to comment.