Skip to content

fix(choices): present grouped paper questions as single-select - #430

Open
PerryLink wants to merge 1 commit into
omdsh-dev:mainfrom
PerryLink:fix/choices-group-single-select-20261106
Open

PerryLink wants to merge 1 commit into
omdsh-dev:mainfrom
PerryLink:fix/choices-group-single-select-20261106

Conversation

@PerryLink

Copy link
Copy Markdown
Contributor

Problem

A choices list with group is a paper question: src/client/submission-registry.ts:74-87 registers it as a radio member and grades it from one answer (the GenuiChoices.answer type is number | string). The renderer, however, picks its control type from the authored mode (src/client/blocks/choices.tsx):

type={mode === 'single' ? 'radio' : 'checkbox'}

So mode: 'multi' + group renders checkbox rows whose second pick can never be recorded — the shared answer stores a single label — plus a "pick any that apply" hint and data-choice-mode="multi".

Repro (jsdom component test):

x renders single-select controls even when the spec carries mode: multi
  -> expected [ 'checkbox', 'checkbox' ] to deeply equal [ 'radio', 'radio' ]

Fix

Derive the presented mode from the same rule the registry uses: a grouped list is single-select. single = group !== undefined || mode === 'single' now drives the input type/name, the container role, the hint, the submitted mode and data-choice-mode. Lists without a group keep checkboxes and local multi-select unchanged.

I did not make this a validation error: rejecting the spec sends the whole fence back to a code block, while the node degrades safely to the single-select it is actually graded as. Supporting multi-select paper questions would be a feature change to the registry/grading contract, not a fix. (The only observable DOM change is that data-choice-mode now reflects the presented mode rather than the authored one; nothing in the repo consumes it.)

Tests

tests/genui-choices.spec.tsx:

  1. grouped mode: 'multi' renders radio/radio, role="radiogroup", and data-choice-mode="single" (red on base);
  2. the same holds in an export/panel context without block state (no answers provider) — the rule keys on group, not on the live registry (red on base);
  3. a local multi-select list without group still renders checkboxes (regression guard).

npx vitest run tests/genui-choices.spec.tsx -> 16 passed; full suite 2109 passed / 152 files; npx tsc -p tsconfig.json --noEmit clean.

A `choices` list with `group` is a paper question: submission-registry
registers it as a `radio` member and grades it from one `answer`. The
renderer picked its control type from the authored `mode` instead, so a
spec carrying `mode: 'multi'` rendered checkbox rows whose second pick
could never be recorded (the shared answer holds one label), together
with a "pick any that apply" hint and data-choice-mode="multi".

Derive the presented mode from the same rule the registry uses: `group`
forces single-select. Radio inputs, radiogroup role, single hint, the
submitted `mode` and the data attribute now all agree; lists without a
group keep their checkboxes and local multi-select.

Tests: 2 new red->green cases (live paper context and export/panel
context without block state) plus a regression guard for local
multi-select.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant