-
Notifications
You must be signed in to change notification settings - Fork 348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix line segment tab order #1240
Conversation
GeraldRequired Reviewers
Don't want to be involved in this pull request? Comment |
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (f39b853) and published it to npm. You Example: yarn add @khanacademy/perseus@PR1240 If you are working in Khan Academy's webapp, you can run: ./dev/tools/bump_perseus_version.sh -t PR1240 |
Size Change: +893 B (0%) Total Size: 835 kB
ℹ️ View Unchanged
|
@@ -769,7 +769,6 @@ export const polygonQuestionDefaultCorrect: PerseusRenderer = { | |||
[2.5, 4], | |||
[1.5, 2], | |||
], | |||
match: "congruent", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The removal of this line is kind of a long story.
- I changed the RTL tests for interative graph to use
tab
to select the first movable element - This meant that the test for polygon was selecting the entire polygon instead of the first point
- The polygon question was graded based on congruence
- That meant that moving the entire polygon, without changing its shape, resulted in a correct answer
- That caused the test for answering incorrectly to fail.
To test that incorrect answers are graded correctly, we make the grading more strict. When match
is not present, the points must be exactly where the content author put them for the question to be marked correct.
packages/perseus/src/widgets/interactive-graphs/graphs/components/movable-point-view.tsx
Outdated
Show resolved
Hide resolved
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1240 +/- ##
==========================================
+ Coverage 68.73% 70.13% +1.40%
==========================================
Files 471 476 +5
Lines 101003 101174 +171
Branches 7171 10882 +3711
==========================================
+ Hits 69423 70959 +1536
+ Misses 31394 30215 -1179
+ Partials 186 0 -186
... and 145 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
b71bb8b
to
faf351e
Compare
const ref = React.useRef<SVGPolygonElement>(null); | ||
const dragReferencePoint = points[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a sneaky bugfix.
The bug was that sometimes, selecting an entire polygon and pressing an arrow key would not move the polygon. Our tests for the polygon graph happened to catch it (recall that since we're now using tab
to select the first movable element in our tests, we're now selecting the entire polygon in the tests instead of selecting the first point)
The bug happened because the midpoint
of the polygon was, in general, not on a snap step. This meant that trying to move the polygon sometimes caused it to snap back to its original location, effectively canceling the move.
Since the points of a polygon are always on a snap step, using the first point as the reference point fixes this.
@benchristel Do you have a video of the new tabbing experience? |
@nishasy I've attached a video to the PR description. |
@@ -0,0 +1,130 @@ | |||
import {color as WBColor} from "@khanacademy/wonder-blocks-tokens"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For posterity, could you add a small docblock at the top of this file explaning what MovablePointView is and where/how it's used?
start: false, | ||
end: true, | ||
}} | ||
/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is beautiful ✨
}; | ||
}; | ||
|
||
export const MovableLine = (props: MovableLineProps) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think MovableLine
needs to be exported anymore?
useControlPoint(end, color, (p) => props.onMovePoint(1, p)); | ||
|
||
return ( | ||
<> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beautiful! For posterity, could you add a comment here explaining that the focusHandles/visiblePoints are done this way because of the weirdness with SVGs and z-index/tabindex?
062dea9
to
b793fee
Compare
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @khanacademy/math-input@19.0.0 ### Major Changes - [#1235](#1235) [`87169b22b`](87169b2) Thanks [@jeresig](https://github.com/jeresig)! - Update mathjax-renderer usage, locale is now required for createMathField. ## @khanacademy/perseus@22.4.1 ### Patch Changes - [#1240](#1240) [`4a59b85ab`](4a59b85) Thanks [@benchristel](https://github.com/benchristel)! - Change the tab order for movable line segments in interactive graphs. Previously, the order was `(whole segment, first point, second point)`. Now it's `(first point, whole segment, second point)`, which aligns better with the visual layout of the graph. - [#1240](#1240) [`4a59b85ab`](4a59b85) Thanks [@benchristel](https://github.com/benchristel)! - Adjust spacing in locked point and locked line settings - [#1235](#1235) [`87169b22b`](87169b2) Thanks [@jeresig](https://github.com/jeresig)! - Update mathjax-renderer usage, locale is now required for createMathField. - Updated dependencies \[[`87169b22b`](87169b2)]: - @khanacademy/math-input@19.0.0 ## @khanacademy/perseus-editor@6.2.2 ### Patch Changes - [#1247](#1247) [`99f32f531`](99f32f5) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Only show a11y banner for ruler and protractor when either or both is enabled - [#1240](#1240) [`4a59b85ab`](4a59b85) Thanks [@benchristel](https://github.com/benchristel)! - Adjust spacing in locked point and locked line settings - [#1235](#1235) [`87169b22b`](87169b2) Thanks [@jeresig](https://github.com/jeresig)! - Update mathjax-renderer usage, locale is now required for createMathField. - Updated dependencies \[[`4a59b85ab`](4a59b85), [`4a59b85ab`](4a59b85), [`87169b22b`](87169b2)]: - @khanacademy/perseus@22.4.1 - @khanacademy/math-input@19.0.0 ## @khanacademy/perseus-dev-ui@1.5.6 ### Patch Changes - Updated dependencies \[[`87169b22b`](87169b2)]: - @khanacademy/math-input@19.0.0
My last PR (#1240) left a rename half-finished. This PR finishes it. Issue: none Test plan: `yarn test`
## Summary: My last PR (#1240) left a rename half-finished. This PR finishes it. Issue: none Test plan: `yarn test` Author: benchristel Reviewers: benchristel, jeremywiebe, mark-fitzgerald, nishasy, SonicScrewdriver, handeyeco, Myranae Required Reviewers: Approved By: jeremywiebe Checks: ✅ codecov/project, ✅ codecov/patch, ✅ Upload Coverage, ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Jest Coverage (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ gerald Pull Request URL: #1250
During playtesting, Sarah B pointed out that the tab order for segment graphs
was not very intuitive. Tabbing to a segment first selected the whole segment.
Tabbing further selected each endpoint.
This PR updates the tab order so the first endpoint is selected first, then the
segment, then the second endpoint.
There are some interesting constraints on the implementation of this feature:
z-index. We want the line of a movable segment to render behind the points.
That means the line element must be first.
order. Setting
tabindex
> 0 is not what we want, since it would bump themovable points to the very front of the tab order for the entire page.
The solution is as follows:
<g>
elements to stand in for the points,since we cannot reorder the points relative to the line.
useMovable
to those elements, so focusing them lets you move thepoints with arrow keys.
<g>
.I split the StyledMovablePoint component into two: there is now a MovablePointView
component that is purely presentational, and has no state or
useMovable
. Thiscomponent has two modes for managing focus. You can either set a
tabindex
and letthe component itself be focusable, or you can pass a boolean that tells the component
whether it should have a focus ring.
Issue: LEMS-1936
Test plan:
View a Mafs segment graph in the dev ui (
yarn dev
). Tabbing between UIelements should feel intuitive.
Screen.Recording.2024-05-06.at.10.44.28.AM.mov