Skip to content

Commit

Permalink
[SR][SR Tree] Update tree to use innerText (#2090)
Browse files Browse the repository at this point in the history
## Summary:
Now that we're using `a11y.srOnly` styling for the hidden
aria descriptions, we don't need to use `textContent`, we
can just use `innerText`.

We also don't need the test for hidden content.

Issue: none

## Test plan:
`yarn jest packages/perseus-editor/src/widgets/interactive-graph-editor/components/interactive-graph-sr-tree.test.tsx`

Author: nishasy

Reviewers: benchristel

Required Reviewers:

Approved By: benchristel

Checks: ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x)

Pull Request URL: #2090
  • Loading branch information
nishasy authored Jan 10, 2025
1 parent 7859080 commit 5ca79ea
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 31 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilly-experts-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus-editor": patch
---

[SR][sr tree] Update tree to use innerText
Original file line number Diff line number Diff line change
Expand Up @@ -340,34 +340,6 @@ describe("fetchAriaLabels", () => {
]);
});

test("should include hidden descriptions", () => {
// Arrange
const {container} = render(
<div>
<div aria-describedby="description1 description2">label1</div>
<div id="description1">description1 content</div>
<div id="description2" style={{display: "hidden"}}>
description2 content
</div>
</div>,
);

// Act
const result = getAccessibilityAttributes(container);

// Assert
expect(result).toEqual([
{
roleOrTag: "div",
className: "",
attributes: [
{name: "description", value: "description1 content"},
{name: "description", value: "description2 content"},
],
},
]);
});

test("should not include descriptions that are not found", () => {
// Arrange
const {container} = render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ export function getAccessibilityAttributes(
const descriptions = ariaDescribedby.split(/ +/);
for (const description of descriptions) {
const descriptionString =
// Use textContent instead of innerText to get the text
// even if it is hidden.
document.getElementById(description)?.textContent;
document.getElementById(description)?.innerText;

if (descriptionString) {
elementAttributes.push({
Expand Down

0 comments on commit 5ca79ea

Please sign in to comment.