Hulian UIv0.93.5413 components0 components
  • Start
  • Components
  • Blocks
  • Pages
  • Demos
  • Changelog
ChineseEnglish
  • ComponentsComponents
  • ThemeTheme

Buttons

  • Button
  • ShimmerButton
  • InteractiveHoverButton
  • RainbowButton
  • PulsatingButton
  • RippleButton
  • ButtonGroup
  • SocialButton

Basic Inputs

  • Input
  • Textarea
  • CellEditor
  • Select
  • Checkbox
  • CheckboxGroup
  • Radio
  • Switch
  • Toggle
  • Segmented
  • Slider
  • NumberField
  • ElasticSlider

Advanced Inputs

  • MathTextarea
  • QuestionEditor
  • QuestionAnswer
  • MathField
  • SecretField
  • PasswordGenerator
  • Combobox
  • RemoteSelect
  • Listbox
  • Mentions
  • InputOTP
  • Rating
  • Upload
  • RegionSelect
  • ImageCropper
  • ScopeMatrix
  • Transfer
  • Cascader
  • TreeSelect
  • RegionCascader
  • CountrySelect
  • MarkdownEditor
  • Novel editor
  • RichTextEditor
  • CodeEditor
  • IssueReporter
  • ColorPicker
  • ColorField
  • ColorSwatchPicker
  • Choicebox
  • EmojiPicker
  • VoiceRecord
  • IconPicker
  • InspectorPanel

Date and Time

  • Calendar
  • DatePicker
  • DateTimePicker
  • DateRangePicker
  • TimePicker
  • TimeField

Form Frameworks

  • Form
  • ModalForm / DrawerForm
  • ProForm
  • StepsForm
  • LoginForm
  • AuthPanel
  • ClickCaptcha
  • Label
  • Field
  • SearchForm

QuestionEditor

question-editor

Structured editor for one math question: seven types, figures, options, blanks, rubric, and a live QuestionCard preview.

Usage

Basic usage

Single choice: add, remove, and reorder options, and the correct answer follows the content; the preview on the right is QuestionCard.

Switching the type clears options and answer

Preview (same typesetting as the question display)

In △ABC\triangle ABC△ABC, ∠C=90∘\angle C=90^{\circ}∠C=90∘ and sin⁡A=35\sin A=\frac{3}{5}sinA=53​. The value of cos⁡A\cos AcosA is ( )

Red source in the preview means KaTeX cannot parse that formula. Check the command spelling.

For fill-in-the-blank, mark each blank with ____ in the stem

A

45\frac{4}{5}54​

B

34\frac{3}{4}43​

C

43\frac{4}{3}34​

D

54\frac{5}{4}45​

2 to 8 options, lettered in order

Pick one

Preview (same typesetting as the question display)

From cos⁡A=1−sin⁡2A\cos A=\sqrt{1-\sin^{2}A}cosA=1−sin2A​ we get cos⁡A=45\cos A=\frac{4}{5}cosA=54​.

Red source in the preview means KaTeX cannot parse that formula. Check the command spelling.

1 star easiest, 5 stars hardest

Preview (the same card used for display)

Single choice

In △ABC\triangle ABC△ABC, ∠C=90∘\angle C=90^{\circ}∠C=90∘ and sin⁡A=35\sin A=\frac{3}{5}sinA=53​. The value of cos⁡A\cos AcosA is ( )

  • A.45\frac{4}{5}54​
  • B.34\frac{3}{4}43​
  • C.43\frac{4}{3}34​
  • D.54\frac{5}{4}45​

AnswerA

ExplanationFrom cos⁡A=1−sin⁡2A\cos A=\sqrt{1-\sin^{2}A}cosA=1−sin2A​ we get cos⁡A=45\cos A=\frac{4}{5}cosA=54​.

tsx
<QuestionEditor value={question} onChange={setQuestion} />

Fill in the blanks

The number of blanks follows ____ in the stem, with a one-click align when they differ; a blank may accept several equivalent forms.

Switching the type clears options and answer

Preview (same typesetting as the question display)

Write 38\frac{3}{8}83​ as a decimal: , and as a percentage: .

Red source in the preview means KaTeX cannot parse that formula. Check the command spelling.

For fill-in-the-blank, mark each blank with ____ in the stem

Blank 1

Wrap formulas in $…$, e.g. $x^{2}$

Blank 2

Wrap formulas in $…$, e.g. $x^{2}$

Blank 2 form 2

Wrap formulas in $…$, e.g. $x^{2}$

One row per blank, in stem order; a blank may accept several equivalent forms

Wrap formulas in $…$, e.g. $x^{2}$

1 star easiest, 5 stars hardest

Preview (the same card used for display)

Fill in the blank

Write 38\frac{3}{8}83​ as a decimal: , and as a percentage: .

AnswerBlank 1: 0.375; Blank 2: 37.5% / 37.5%5\%5%

tsx
<QuestionEditor value={question} onChange={setQuestion} />

Rubric

Calculation and extended-response questions can switch to a rubric; the rubric total sits next to the question score.

Switching the type clears options and answer

Preview (same typesetting as the question display)

Evaluate 12+13\frac{1}{2}+\frac{1}{3}21​+31​

Red source in the preview means KaTeX cannot parse that formula. Check the command spelling.

For fill-in-the-blank, mark each blank with ____ in the stem

Preview (same typesetting as the question display)

56\frac{5}{6}65​

Red source in the preview means KaTeX cannot parse that formula. Check the command spelling.

Optional; show the key steps

Wrap formulas in $…$, e.g. $x^{2}$

Wrap formulas in $…$, e.g. $x^{2}$

Rubric total 8, question score 8

Score point by point; the total should equal the question score

Wrap formulas in $…$, e.g. $x^{2}$

1 star easiest, 5 stars hardest

Preview (the same card used for display)

Calculation

Evaluate 12+13\frac{1}{2}+\frac{1}{3}21​+31​

Answer56\frac{5}{6}65​ Rubric: · Common denominator (3 pts) · Sum (5 pts)

tsx
<QuestionEditor value={question} onChange={setQuestion} />

Figures

![](key) in the stem is resolved by resolveFigure; the Insert image button appears only with onUploadFigure.

Switching the type clears options and answer

Preview (same typesetting as the question display)

As shown, in △ABC\triangle ABC△ABC with AB=ACAB=ACAB=AC, the relation between ∠B\angle B∠B and ∠C\angle C∠C is ( )

Red source in the preview means KaTeX cannot parse that formula. Check the command spelling.

For fill-in-the-blank, mark each blank with ____ in the stem

A

Wrap formulas in $…$, e.g. $x^{2}$

B

Wrap formulas in $…$, e.g. $x^{2}$

2 to 8 options, lettered in order

Pick one

Wrap formulas in $…$, e.g. $x^{2}$

1 star easiest, 5 stars hardest

Preview (the same card used for display)

Single choice

As shown, in △ABC\triangle ABC△ABC with AB=ACAB=ACAB=AC, the relation between ∠B\angle B∠B and ∠C\angle C∠C is ( )

Figure 1Figure 2
  • A.Equal
  • B.Supplementary

AnswerA

tsx
<QuestionEditor
  value={question}
  onChange={setQuestion}
  resolveFigure={(key) => fileUrl(key)}
  onUploadFigure={async (file) => (await upload(file)).key}
/>

Review bar and private fields

issues are listed at the top with a Resolved button each; extra holds the consumer's own fields.

Needs review
  • An option may be missing
  • Answer in doubt

Switching the type clears options and answer

Preview (same typesetting as the question display)

In △ABC\triangle ABC△ABC, ∠C=90∘\angle C=90^{\circ}∠C=90∘ and sin⁡A=35\sin A=\frac{3}{5}sinA=53​. The value of cos⁡A\cos AcosA is ( )

Red source in the preview means KaTeX cannot parse that formula. Check the command spelling.

For fill-in-the-blank, mark each blank with ____ in the stem

A

45\frac{4}{5}54​

B

34\frac{3}{4}43​

C

43\frac{4}{3}34​

D

54\frac{5}{4}45​

2 to 8 options, lettered in order

Pick one

Preview (same typesetting as the question display)

From cos⁡A=1−sin⁡2A\cos A=\sqrt{1-\sin^{2}A}cosA=1−sin2A​ we get cos⁡A=45\cos A=\frac{4}{5}cosA=54​.

Red source in the preview means KaTeX cannot parse that formula. Check the command spelling.

1 star easiest, 5 stars hardest

Preview (the same card used for display)

Single choice

In △ABC\triangle ABC△ABC, ∠C=90∘\angle C=90^{\circ}∠C=90∘ and sin⁡A=35\sin A=\frac{3}{5}sinA=53​. The value of cos⁡A\cos AcosA is ( )

  • A.45\frac{4}{5}54​
  • B.34\frac{3}{4}43​
  • C.43\frac{4}{3}34​
  • D.54\frac{5}{4}45​

AnswerA

ExplanationFrom cos⁡A=1−sin⁡2A\cos A=\sqrt{1-\sin^{2}A}cosA=1−sin2A​ we get cos⁡A=45\cos A=\frac{4}{5}cosA=54​.

tsx
<QuestionEditor
  value={question}
  onChange={setQuestion}
  issues={[{ label: "An option may be missing" }]}
  onResolveIssue={(label) => resolve(label)}
  extra={<PrivateFields />}
/>

Hiding score and estimated time

When a score belongs to the paper-question pair rather than the question itself, hide the input with hiddenFields: the editor writes nothing to a hidden field, switching type no longer recomputes the score, and the metrics row shrinks to the columns it still has.

Switching the type clears options and answer

Preview (same typesetting as the question display)

In △ABC\triangle ABC△ABC, ∠C=90∘\angle C=90^{\circ}∠C=90∘ and sin⁡A=35\sin A=\frac{3}{5}sinA=53​. The value of cos⁡A\cos AcosA is ( )

Red source in the preview means KaTeX cannot parse that formula. Check the command spelling.

For fill-in-the-blank, mark each blank with ____ in the stem

A

45\frac{4}{5}54​

B

34\frac{3}{4}43​

C

43\frac{4}{3}34​

D

54\frac{5}{4}45​

2 to 8 options, lettered in order

Pick one

Preview (same typesetting as the question display)

From cos⁡A=1−sin⁡2A\cos A=\sqrt{1-\sin^{2}A}cosA=1−sin2A​ we get cos⁡A=45\cos A=\frac{4}{5}cosA=54​.

Red source in the preview means KaTeX cannot parse that formula. Check the command spelling.

1 star easiest, 5 stars hardest

Preview (the same card used for display)

Single choice

In △ABC\triangle ABC△ABC, ∠C=90∘\angle C=90^{\circ}∠C=90∘ and sin⁡A=35\sin A=\frac{3}{5}sinA=53​. The value of cos⁡A\cos AcosA is ( )

  • A.45\frac{4}{5}54​
  • B.34\frac{3}{4}43​
  • C.43\frac{4}{3}34​
  • D.54\frac{5}{4}45​

AnswerA

ExplanationFrom cos⁡A=1−sin⁡2A\cos A=\sqrt{1-\sin^{2}A}cosA=1−sin2A​ we get cos⁡A=45\cos A=\frac{4}{5}cosA=54​.

tsx
<QuestionEditor
  value={question}
  onChange={setQuestion}
  hiddenFields={["score", "estimatedMinutes"]}
/>

Validate everything on submit

By default only edited fields turn red; showAllIssues attaches every validateQuestion issue at once.

Switching the type clears options and answer

Wrap formulas in $…$, e.g. $x^{2}$

For fill-in-the-blank, mark each blank with ____ in the stem

Stem is required
A

Wrap formulas in $…$, e.g. $x^{2}$

B

Wrap formulas in $…$, e.g. $x^{2}$

2 to 8 options, lettered in order

Option A is empty

Pick at least two

Multiple choice needs at least two answers

Wrap formulas in $…$, e.g. $x^{2}$

1 star easiest, 5 stars hardest

Preview (the same card used for display)

Preview appears once the stem has text

tsx
<QuestionEditor value={question} onChange={setQuestion} showAllIssues />

Read only

disabled: the read-only state after review.

Switching the type clears options and answer

Preview (same typesetting as the question display)

In △ABC\triangle ABC△ABC, ∠C=90∘\angle C=90^{\circ}∠C=90∘ and sin⁡A=35\sin A=\frac{3}{5}sinA=53​. The value of cos⁡A\cos AcosA is ( )

Red source in the preview means KaTeX cannot parse that formula. Check the command spelling.

For fill-in-the-blank, mark each blank with ____ in the stem

A

45\frac{4}{5}54​

B

34\frac{3}{4}43​

C

43\frac{4}{3}34​

D

54\frac{5}{4}45​

2 to 8 options, lettered in order

Pick one

Preview (same typesetting as the question display)

From cos⁡A=1−sin⁡2A\cos A=\sqrt{1-\sin^{2}A}cosA=1−sin2A​ we get cos⁡A=45\cos A=\frac{4}{5}cosA=54​.

Red source in the preview means KaTeX cannot parse that formula. Check the command spelling.

1 star easiest, 5 stars hardest

Preview (the same card used for display)

Single choice

In △ABC\triangle ABC△ABC, ∠C=90∘\angle C=90^{\circ}∠C=90∘ and sin⁡A=35\sin A=\frac{3}{5}sinA=53​. The value of cos⁡A\cos AcosA is ( )

  • A.45\frac{4}{5}54​
  • B.34\frac{3}{4}43​
  • C.43\frac{4}{3}34​
  • D.54\frac{5}{4}45​

AnswerA

ExplanationFrom cos⁡A=1−sin⁡2A\cos A=\sqrt{1-\sin^{2}A}cosA=1−sin2A​ we get cos⁡A=45\cos A=\frac{4}{5}cosA=54​.

tsx
<QuestionEditor value={question} onChange={setQuestion} disabled />

When to use

Question-bank entry pages and the calibration page after AI or Word import: anywhere "edit one question" happens, instead of a 1200-line form per page. It owns the question itself (the Question canonical shape). Subject, textbook section, knowledge points, general-scope notes, and upload endpoints are consumer-private: put them in the extra slot and upload through onUploadFigure.

Display only: QuestionCard. Student answering: QuestionAnswer. A single formula-capable input: MathTextarea (what this component is built from).

Import

ts
import { QuestionEditor, emptyQuestion, validateQuestion, toWireAnswer, fromWire } from "@hulianui/ui/math"

It lives in @hulianui/ui/math rather than the root package: the stem, options, and preview are all Formula, so KaTeX comes along; consumers that never typeset math should not pay for it.

Props

NameTypeDefaultDescription
valueQuestion-Controlled value in the canonical shape (Question from @hulianui/ui/math). Blank answers are always arrays inside the editor (one entry even for a single blank); flatten on the way out with toWireAnswer
onChange(next: Question) => void-Called with the whole canonical shape on every edit
disabledbooleanfalseRead-only
resolveFigure(key: string) => string-Maps ![](key) in the stem to a displayable URL. The thumbnail strip, the lightbox, and the stem preview all use it; when the stem has figures and it is missing, thumbnails show only the key and a dev warning fires
onUploadFigure(file: File) => Promise<string>-Uploads one figure and resolves to its storage key. The Insert image button appears only when provided; on success ![](key) is appended to the stem, on failure the reason shows in the strip
figureFilter(key: string) => boolean-Which keys count as figures (they enter the thumbnail strip, can be added or removed, and are written back at the end of the stem). Omitted = all of them. References it rejects stay exactly where they are in the stem body; the editor never moves them and never touches their alt text
extraReactNode-Consumer-private fields, rendered after the type and before the stem
issues{ label, tone? }[]-Review bar listed at the top, one Resolved button per item
onResolveIssue(label: string) => void-Called from the Resolved button; the button is omitted when this is missing
defaultScoreByTypePartial<Record<QuestionType, number>>-Overrides the per-type default score. On a type switch the score changes only if it still equals the old type's default
templatesreadonly FormulaTemplateGroup[]-Passed to every MathTextarea
visualEditorComponentType<MathFieldLikeProps>-Passed to every MathTextarea (MathField satisfies the contract)
macrosRecord<string, string>-KaTeX macros passed to every MathTextarea and to the stem preview (the QuestionCard preview on the right does not take macros)
hiddenFieldsreadonly ("difficulty" | "score" | "estimatedMinutes")[]-Which fields of the metrics row are not rendered. Products where a score belongs to the paper-question pair rather than the question use it to drop the score input; the editor never writes a hidden field (switching type no longer recomputes score) and its value passes through Question untouched. With all three hidden the row disappears
previewbooleantrueLive QuestionCard preview on the right (below on narrow screens), with answer and explanation
showAllIssuesbooleanfalseShow every validateQuestion issue at once. By default only fields the user has edited show issues; set it after the user presses submit
classNamestring-Root node (a two-column grid)

Events

NameArgumentsDescription
onChange(next: Question)Any field changed. A type switch resets options and answer together and remaps score through the default table
onUploadFigure(file: File)The user picked an image. The resolved key is written into the latest stem (text typed during the upload is kept)
onResolveIssue(label: string)Resolved pressed on the review bar

Slots

NameDescription
extraPrivate-field area after the type and before the stem, for subject / section / knowledge-point fields that are not part of "one question"

Localization

All copy comes from the components.questionEditor locale (QuestionEditorLocale, source of truth in question-editor.locale.ts; zhCN and enUS are wired). Type names and the True / False labels come from components.question (shared with QuestionCard). The validateQuestion code table is validation, keyed by QuestionValidationCode.

Companion pure functions

All exported from @hulianui/ui/math:

  • questionFormulaIssues(q) returns { field, key?, issue }[]: runs validateFormulaSyntax field by field (stem, each option, each form of each blank, reference answer and rubric points, explanation). Every input already shows the same issue inline; this one is for the submit button. Compose the message from the mathTextarea locale: position(line, column) + syntax[code].
  • shapeIsDirty(q) returns boolean: whether switching type would lose content (an option has text, or the answer differs from the type's empty shape). Reuse it for a "clear form" confirmation.
  • switchType(q, type, defaults?) returns Question: resets options and answer together and remaps the score.
  • optionCaption(key, text) returns string: the label on the correct-answer control (A plus the first 20 characters of the option as plain text).
  • stemBody(stem, accept?) / joinStemFigures(body, keys): split and join the stem body and the figure block with the editor's own rule. accept is the same predicate as figureFilter; omitted, every reference counts as a figure.

Pitfalls

  • value must be canonical. Legacy variants such as answer: "A,C", options: ["A. x"], or answer: "true" go through fromWire first; fed directly they render as "no answer selected" and validateQuestion reports answer_out_of_range.
  • Flatten blank answers on the way out. Inside the editor a single blank is ["90"]; if the backend wants a plain string for single blanks, call toWireAnswer(question) before submitting.
  • Switching type clears options and answer (with a confirmation when there is content). Keeping the old shape would produce values such as a true-false question with options, which the backend rejects.
  • Figures live in the stem, not in another field. The input hides ![](key) but value.stem contains it; if figures lived elsewhere, paper preview, the student view, and export would get none of them. Without resolveFigure the preview drops figures and thumbnails show only the key.
  • Not every ![](...) should count as a figure; carve inline formula images out with figureFilter. By default every image reference in the stem is treated as a figure and the whole set is moved to the end of the stem. That is wrong for the inline formula images a Word import pipeline produces: x![7x+5<5x+1](import/formula/....png) has the solution set ______. turns into "x has the solution set ______." plus a trailing image after a single edit, and the sentence no longer reads. Split them by key prefix:

```tsx
<QuestionEditor figureFilter={(key) => !key.startsWith("import/formula/")} ... />
```

Rejected references stay verbatim in the stem body (the ![...](...) text is visible in the input), the strip does not list them, they cannot be deleted there, and neither their position nor their alt text changes.

  • The stem preview needs resolveFigure to show figures. With it, the preview under the input renders through the same path as the display end (figures drawn, alt taken from the reference itself); without it the preview falls back to plain <Formula>, which does not understand markdown image syntax and prints ![](key) verbatim. When the body has neither formulas nor figures the preview box is hidden entirely - it would be character-for-character the input.
  • Upload appears only with onUploadFigure. Enforce type and size limits inside the callback; reject with throw new Error("Max 5MB per image") and the message shows verbatim in the strip.
  • Validation shows only edited fields by default. Set showAllIssues to flag everything at submit time; do not draw errors again outside.
  • When score or timing is not part of your question model, hide it with hiddenFields instead of zeroing the default score (#358). A defaultScoreByType full of zeros only stops the editor from inventing a score; the input is still there and teachers still fill it in - and what they type either contradicts the product ("this question is worth 3 points" inside a question bank) or gets dropped silently on submit. Once hidden, the editor writes nothing to that field: switching type no longer recomputes score either, because writing a field the user cannot see is a silent data change. The value itself still passes through untouched, and validateQuestion is unchanged - an issue on a hidden field simply has nowhere to show. Only the three fields of the metrics row can be hidden; stem, options, answer and explanation cannot.
  • No submit button. Submitting, required private fields (such as subject), and an upper bound for estimatedMinutes belong to the page.
  • JSX attribute strings do not process \\. Put formulas with backslashes in TS strings (stem: "$\\frac{1}{2}$"), not in JSX attributes.

Related

  • QuestionCard: the preview is this component (showAnswer + resolveFigure)
  • MathTextarea: every formula-capable input
  • Formula: the question-domain pure functions in @hulianui/ui/math (validateQuestion / defaultShape / toWireAnswer / fromWire / splitStemFigures)
  • Field: how errors are attached

Playground

Switching the type clears options and answer

Preview (same typesetting as the question display)

In △ABC\triangle ABC△ABC, ∠C=90∘\angle C=90^{\circ}∠C=90∘ and sin⁡A=35\sin A=\frac{3}{5}sinA=53​. The value of cos⁡A\cos AcosA is ( )

Red source in the preview means KaTeX cannot parse that formula. Check the command spelling.

For fill-in-the-blank, mark each blank with ____ in the stem

A

45\frac{4}{5}54​

B

34\frac{3}{4}43​

C

43\frac{4}{3}34​

D

54\frac{5}{4}45​

2 to 8 options, lettered in order

Pick one

Preview (same typesetting as the question display)

From cos⁡A=1−sin⁡2A\cos A=\sqrt{1-\sin^{2}A}cosA=1−sin2A​ we get cos⁡A=45\cos A=\frac{4}{5}cosA=54​.

Red source in the preview means KaTeX cannot parse that formula. Check the command spelling.

1 star easiest, 5 stars hardest

Preview (the same card used for display)

Single choice

In △ABC\triangle ABC△ABC, ∠C=90∘\angle C=90^{\circ}∠C=90∘ and sin⁡A=35\sin A=\frac{3}{5}sinA=53​. The value of cos⁡A\cos AcosA is ( )

  • A.45\frac{4}{5}54​
  • B.34\frac{3}{4}43​
  • C.43\frac{4}{3}34​
  • D.54\frac{5}{4}45​

AnswerA

ExplanationFrom cos⁡A=1−sin⁡2A\cos A=\sqrt{1-\sin^{2}A}cosA=1−sin2A​ we get cos⁡A=45\cos A=\frac{4}{5}cosA=54​.

<QuestionEditor value={question} onChange={setQuestion} />
PreviousMathTextareaFormsNextQuestionAnswer

On this page

  • Usage
  • Documentation
    • When to use
    • Import
    • Props
    • Events
    • Slots
    • Localization
    • Companion pure functions
    • Pitfalls
    • Related
  • Playground