Skip to content

Commit 5226f43

Browse files
[its-a-drag-to-tap-out] docs(changeset): Ensure that dragging a point also moves the focus for Interactive Graph (#2282)
## Summary: This PR is part of the Interactive Graph project. The purpose of the PR is to ensure that dragging a point with a touch event also moves the focus to that point. This is to ensure that the focus always remains on the last element interacted with, which avoids confusion when the user tries to delete points or move them with the keyboard. NOTE: I wasn't able to fix a bug related to the hover state sizing of the control points, as I simply cannot seem to find where this is occurring. As a result, touch-dragging a point without any delay can result in the point not getting "bigger". However, the focus outline, hairlines, and focus itself all move to the correct element. I've attached a video below to demonstrate this. ## Video: https://github.com/user-attachments/assets/59e26360-b54e-4340-b49b-c4f9c32c4baf Issue: LEMS-2475 ## Test plan: - Manual testing Author: SonicScrewdriver Reviewers: SonicScrewdriver, nishasy Required Reviewers: Approved By: nishasy Checks: ✅ 8 checks were successful Pull Request URL: #2282
1 parent 0438f63 commit 5226f43

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

.changeset/serious-days-swim.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@khanacademy/perseus": patch
3+
---
4+
5+
Ensure that dragging a point also moves the focus for Interactive Graph

packages/perseus/src/widgets/interactive-graphs/graphs/components/use-control-point.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export function useControlPoint(params: Params): Return {
6868

6969
const [focused, setFocused] = useState(false);
7070
const focusableHandleRef = useRef<SVGGElement>(null);
71+
7172
useDraggable({
7273
gestureTarget: focusableHandleRef,
7374
point,
@@ -92,10 +93,21 @@ export function useControlPoint(params: Params): Return {
9293
y: srFormatNumber(point[Y], locale),
9394
});
9495

96+
// Set the forwarded ref to the focusable handle element when it changes.
9597
useLayoutEffect(() => {
9698
setForwardedRef(forwardedRef, focusableHandleRef.current);
9799
}, [forwardedRef]);
98100

101+
// If the point is being dragged and is not focused, focus the focusable handle.
102+
useLayoutEffect(() => {
103+
if (dragging && !focused) {
104+
// If the point is being dragged, focus the focusable handle so that
105+
// users can continue to interact with the point using the keyboard or buttons.
106+
// This particular focus call ensures that the focus ring and hairlines are visible.
107+
focusableHandleRef.current?.focus();
108+
}
109+
}, [dragging, focused]);
110+
99111
const focusableHandle = (
100112
<g
101113
data-testid="movable-point__focusable-handle"

packages/perseus/src/widgets/interactive-graphs/reducer/interactive-graph-reducer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ function doMovePoint(
507507
return {
508508
...state,
509509
hasBeenInteractedWith: true,
510+
focusedPointIndex: action.index,
510511
coords: setAtIndex({
511512
array: state.coords,
512513
index: action.index,

0 commit comments

Comments
 (0)