-
Notifications
You must be signed in to change notification settings - Fork 350
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
feat(LEMS-2664): update use control point and movable point with optional props #1906
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7eb2761
update use control point and movable point with optional props
anakaren-rojas 83839b5
lint fix
anakaren-rojas 4b4236c
changeset
anakaren-rojas f01b2b4
add accessibility tests for movable point
anakaren-rojas 059baef
lint fix
anakaren-rojas 8bcc3b7
make sequenceNumber optional
anakaren-rojas 7c19062
remove unneeded undefined
anakaren-rojas 0ec45c5
reorder params
anakaren-rojas 8cf8bbd
Merge branch 'main' into LEMS-2664-update-shared-utils
anakaren-rojas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": patch | ||
--- | ||
|
||
update moveable point component and use control point method to have optional params |
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
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
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
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 |
---|---|---|
|
@@ -10,13 +10,20 @@ import {useDraggable} from "../use-draggable"; | |
import {MovablePointView} from "./movable-point-view"; | ||
|
||
import type {CSSCursor} from "./css-cursor"; | ||
import type {AriaLive} from "../../types"; | ||
import type {KeyboardMovementConstraint} from "../use-draggable"; | ||
import type {vec} from "mafs"; | ||
|
||
type Params = { | ||
point: vec.Vector2; | ||
ariaDescribedBy?: string; | ||
ariaLabel?: string; | ||
ariaLive?: AriaLive; | ||
color?: string | undefined; | ||
constrain?: KeyboardMovementConstraint; | ||
cursor?: CSSCursor | undefined; | ||
// The focusableHandle element is assigned to the forwarded ref. | ||
forwardedRef?: React.ForwardedRef<SVGGElement | null> | undefined; | ||
/** | ||
* Represents where this point stands in the overall point sequence. | ||
* This is used to provide screen readers with context about the point. | ||
|
@@ -25,14 +32,11 @@ type Params = { | |
* Note: This number is 1-indexed, and should restart from 1 for each | ||
* interactive figure on the graph. | ||
*/ | ||
sequenceNumber: number; | ||
constrain?: KeyboardMovementConstraint; | ||
sequenceNumber?: number; | ||
onMove?: ((newPoint: vec.Vector2) => unknown) | undefined; | ||
onClick?: (() => unknown) | undefined; | ||
onFocus?: ((event: React.FocusEvent) => unknown) | undefined; | ||
onBlur?: ((event: React.FocusEvent) => unknown) | undefined; | ||
// The focusableHandle element is assigned to the forwarded ref. | ||
forwardedRef?: React.ForwardedRef<SVGGElement | null> | undefined; | ||
}; | ||
|
||
type Return = { | ||
|
@@ -46,15 +50,18 @@ export function useControlPoint(params: Params): Return { | |
const {snapStep, disableKeyboardInteraction} = useGraphConfig(); | ||
const { | ||
point, | ||
sequenceNumber, | ||
ariaDescribedBy, | ||
ariaLabel, | ||
ariaLive = "polite", | ||
color, | ||
cursor, | ||
constrain = (p) => snap(snapStep, p), | ||
cursor, | ||
forwardedRef = noop, | ||
sequenceNumber = 1, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice |
||
onMove = noop, | ||
onClick = noop, | ||
onFocus = noop, | ||
onBlur = noop, | ||
forwardedRef = noop, | ||
} = params; | ||
|
||
const {strings, locale} = usePerseusI18n(); | ||
|
@@ -76,6 +83,15 @@ export function useControlPoint(params: Params): Return { | |
constrainKeyboardMovement: constrain, | ||
}); | ||
|
||
// if custom aria label is not provided, will use default of sequence number and point coordinates | ||
const pointAriaLabel = | ||
ariaLabel || | ||
strings.srPointAtCoordinates({ | ||
num: sequenceNumber, | ||
anakaren-rojas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
x: srFormatNumber(point[X], locale), | ||
y: srFormatNumber(point[Y], locale), | ||
}); | ||
|
||
useLayoutEffect(() => { | ||
setForwardedRef(forwardedRef, focusableHandleRef.current); | ||
}, [forwardedRef]); | ||
|
@@ -87,14 +103,9 @@ export function useControlPoint(params: Params): Return { | |
tabIndex={disableKeyboardInteraction ? -1 : 0} | ||
ref={focusableHandleRef} | ||
role="button" | ||
aria-label={strings.srPointAtCoordinates({ | ||
num: sequenceNumber, | ||
x: srFormatNumber(point[X], locale), | ||
y: srFormatNumber(point[Y], locale), | ||
})} | ||
// aria-live="assertive" causes the new location of the point to be | ||
// announced immediately on move. | ||
aria-live="assertive" | ||
aria-describedby={ariaDescribedBy} | ||
aria-label={pointAriaLabel} | ||
aria-live={ariaLive} | ||
onFocus={(event) => { | ||
onFocus(event); | ||
setFocused(true); | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Only removing point or moving out of bounds should be
assertive
per design doc