Skip to content
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

[WIP] add TeX support to dropdown #1810

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/perseus/src/widgets/dropdown/dropdown.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from "react";

import {RendererWithDebugUI} from "../../../../../testing/renderer-with-debug-ui";

import {question1} from "./dropdown.testdata";
import {question1, question2} from "./dropdown.testdata";

export default {
title: "Perseus/Widgets/Dropdown",
Expand All @@ -13,3 +13,7 @@ type StoryArgs = Record<any, any>;
export const Question1 = (args: StoryArgs): React.ReactElement => {
return <RendererWithDebugUI question={question1} />;
};

export const Question2 = (args: StoryArgs): React.ReactElement => {
return <RendererWithDebugUI question={question2} />;
};
31 changes: 31 additions & 0 deletions packages/perseus/src/widgets/dropdown/dropdown.testdata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,34 @@ export const question1: PerseusRenderer = {
},
},
};

export const question2: PerseusRenderer = {
content: "If x equals 4, then [[☃ dropdown 1]] equals $10$.",
images: {},
widgets: {
"dropdown 1": {
type: "dropdown",
alignment: "default",
static: false,
graded: true,
options: {
static: false,
placeholder: "",
choices: [
{
content: "$5\\sqrt{x}$",
correct: true,
},
{
content: "$5x$",
correct: false,
},
],
},
version: {
major: 0,
minor: 0,
},
},
},
};
20 changes: 18 additions & 2 deletions packages/perseus/src/widgets/dropdown/dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as React from "react";
import ReactDOM from "react-dom";

import {ApiOptions} from "../../perseus-api";
import Renderer from "../../renderer";

import dropdownValidator from "./dropdown-validator";

Expand All @@ -12,6 +13,7 @@ import type {
PerseusDropdownRubric,
PerseusDropdownUserInput,
} from "../../validation.types";
import type {PerseusI18nContext} from "@khanacademy/perseus";

type Props = WidgetProps<RenderProps, PerseusDropdownRubric> & {
selected: number;
Expand All @@ -32,6 +34,8 @@ class Dropdown extends React.Component<Props> implements Widget {
apiOptions: ApiOptions.defaults,
};

declare context: React.ContextType<typeof PerseusI18nContext>;

focus: () => boolean = () => {
// TODO(LP-10797): This focus() call doesn't do anything because our
// root element is a <div> and that cannot be focused without a
Expand Down Expand Up @@ -62,13 +66,25 @@ class Dropdown extends React.Component<Props> implements Widget {
key="placeholder"
value="0"
disabled
label={this.props.placeholder}
label={
<Renderer
content={this.props.placeholder}
strings={this.context.strings}
inline
/>
}
/>,
...this.props.choices.map((choice, i) => (
<OptionItem
key={String(i + 1)}
value={String(i + 1)}
label={choice}
label={
<Renderer
content={choice}
strings={this.context.strings}
inline
/>
}
/>
)),
];
Expand Down
Loading