-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Polygon graphs to have weighted lines only after focus from ke…
…yboard (#1455) ## Summary: Previously, Polygon had its shape weighted upon hover and after clicking in the shape. This is not how circle is currently working. To bring them into alignment, this changes Polygon to become weighted only when the shape is tabbed to by the keyboard or if the shape is moved via keyboard after the user clicks on it. ### Before https://github.com/user-attachments/assets/16f3aef8-3312-4e0c-8815-542ad6ea7c98 ### After https://github.com/user-attachments/assets/b6058ae6-b31e-4942-ae24-9ae2853bfcc3 Issue: LEMS-2200 ## Test plan: - Checkout the associated branch - Run `yarn dev` - On the gallery page, turn on the flag for polygon and circle - Confirm Polygon does not have weighted lines on hover or when dragging. After clicking the shape, confirm the shape becomes weighted when you move it with the arrow keys. Confirm the lines return to normal after clicking outside of the shape. - Confirm this functionality matches Circle graphs Author: Myranae Reviewers: benchristel, nishasy, mark-fitzgerald, nicolecomputer, SonicScrewdriver Required Reviewers: Approved By: benchristel Checks: ✅ codecov/project, ✅ codecov/patch, ✅ Upload Coverage (ubuntu-latest, 20.x), ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Jest Coverage (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ gerald Pull Request URL: #1455
- Loading branch information
Showing
4 changed files
with
108 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@khanacademy/perseus": minor | ||
--- | ||
|
||
Update Polygon graphs to have weighted lines only on keyboard focus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
packages/perseus/src/widgets/interactive-graphs/graphs/polygon.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import {render} from "@testing-library/react"; | ||
import {userEvent as userEventLib} from "@testing-library/user-event"; | ||
import {Mafs, Polygon} from "mafs"; | ||
import React from "react"; | ||
|
||
import {hasFocusVisible} from "./polygon"; | ||
|
||
import type {UserEvent} from "@testing-library/user-event"; | ||
|
||
describe("hasFocusVisible", () => { | ||
let userEvent: UserEvent; | ||
beforeEach(() => { | ||
userEvent = userEventLib.setup({ | ||
advanceTimers: jest.advanceTimersByTime, | ||
}); | ||
}); | ||
|
||
it("returns true when polygon is focused", async () => { | ||
const ref = React.createRef<SVGPolygonElement>(); | ||
render( | ||
<Mafs width={200} height={200}> | ||
<Polygon | ||
points={[ | ||
[0, 0], | ||
[0, 2], | ||
[2, 2], | ||
[2, 0], | ||
]} | ||
svgPolygonProps={{ | ||
ref, | ||
tabIndex: 0, | ||
}} | ||
/> | ||
</Mafs>, | ||
); | ||
const polygon = ref.current; | ||
if (polygon) { | ||
await userEvent.tab(); | ||
await userEvent.tab(); | ||
} | ||
|
||
expect(polygon).toBeInTheDocument(); | ||
expect(polygon).toHaveFocus(); | ||
expect(hasFocusVisible(polygon)).toBe(true); | ||
}); | ||
|
||
it("returns false when polygon is not focused", async () => { | ||
const ref = React.createRef<SVGPolygonElement>(); | ||
render( | ||
<Mafs width={200} height={200}> | ||
<Polygon | ||
points={[ | ||
[0, 0], | ||
[0, 2], | ||
[2, 2], | ||
[2, 0], | ||
]} | ||
svgPolygonProps={{ | ||
ref, | ||
tabIndex: 0, | ||
}} | ||
/> | ||
</Mafs>, | ||
); | ||
const polygon = ref.current; | ||
if (polygon) { | ||
await userEvent.tab(); | ||
} | ||
|
||
expect(polygon).toBeInTheDocument(); | ||
expect(polygon).not.toHaveFocus(); | ||
expect(hasFocusVisible(polygon)).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters