-
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
Add readOnly mode to interactive graphs to prevent keyboard interactions when question marked correct #1487
Changes from 6 commits
a4b90fe
2392dae
480bc97
a2edade
4cd2605
09c5df0
ff6d524
b2fafd4
f415144
5685692
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@khanacademy/perseus": minor | ||
--- | ||
|
||
Make graphs non-interactive via keyboard when their question has been answered correctly |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,17 @@ const mafsOptions = { | |
}, | ||
}; | ||
|
||
const polygonReadOnlyOptions = { | ||
apiOptions: { | ||
readOnly: true, | ||
flags: { | ||
mafs: { | ||
polygon: true, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
type StoryArgs = Record<any, any>; | ||
|
||
export const SideBySideFlipbook = (args: StoryArgs): React.ReactElement => ( | ||
|
@@ -71,6 +82,15 @@ export const PolygonWithMafs = (args: StoryArgs): React.ReactElement => ( | |
<RendererWithDebugUI {...mafsOptions} question={polygonQuestion} /> | ||
); | ||
|
||
export const PolygonWithMafsReadOnly = ( | ||
args: StoryArgs, | ||
): React.ReactElement => ( | ||
<RendererWithDebugUI | ||
{...polygonReadOnlyOptions} | ||
question={polygonQuestion} | ||
/> | ||
); | ||
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. Optional suggestion: I wonder if we could make this more skimmable and save some duplicated code by refactoring to something like this: export const PolygonWithMafsReadOnly = (
args: StoryArgs,
): React.ReactElement => (
<RendererWithDebugUI
apiOptions={{...enableMafs, readOnly: true}}
question={polygonQuestion}
/>
); where const enableMafs: ApiOptions = {
flags: {
mafs: {
segment: true,
polygon: true,
// ... other flags as needed ...
},
},
} The other stories could be refactored to use a similar pattern. That way, we wouldn't have to have the mafs flags defined in two places. 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. Love it! I tried to refactor the |
||
|
||
export const Ray = (args: StoryArgs): React.ReactElement => ( | ||
<RendererWithDebugUI question={rayQuestion} /> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,7 @@ function MovableCircle(props: { | |
onMove: (newCenter: vec.Vector2) => unknown; | ||
}) { | ||
const {center, radius, onMove} = props; | ||
const {snapStep, hintMode} = useGraphConfig(); | ||
const {snapStep, hintMode, readOnly} = useGraphConfig(); | ||
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. Since both <GraphConfigContext.Provider
value={{
// ...
disableKeyboardInteraction: hintMode || readOnly,
}}
> And then individual components would just look at 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. I was also considering this. Consolidating some of these modes didn't seem like it was the direction we were going, so I wasn't sure something like this would be the right option. I love this though, so definitely will update. Hint mode disables all interaction though, right? Since readOnly also disables mouse interaction (just not as a result of this setting though), why don't we call it 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. I don't recall exactly where the mouse interactions get disabled. If the code that disables them is reading from 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. I'll double check :) 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. 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. Updated! 😁 |
||
|
||
const draggableRef = useRef<SVGGElement>(null); | ||
|
||
|
@@ -63,7 +63,7 @@ function MovableCircle(props: { | |
return ( | ||
<g | ||
ref={draggableRef} | ||
tabIndex={hintMode ? -1 : 0} | ||
tabIndex={hintMode || readOnly ? -1 : 0} | ||
className={`movable-circle ${dragging ? "movable-circle--dragging" : ""}`} | ||
> | ||
<ellipse | ||
|
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.
Thanks for documenting this!