1. How swift-docc-render consumes this
The assessments section kind is dispatched from two different top-level
page components, both of which ultimately delegate to the same interactive quiz component.
In tutorial pages, Tutorial.vue keeps a static SectionComponents lookup table
keyed by section.kind and maps assessments straight to
Tutorial/Assessments.vue:
const SectionComponents = {
assessments: Assessments,
hero: Hero,
tasks: SectionList,
callToAction: CallToAction,
};
See
Tutorial.vue#L46-L66
for the dispatch table and the TutorialSection render function that instantiates the
matched component with the section's own properties spread as props.
In free-standing Article pages (a DocC "article" that includes a
@Assessments block, not a full tutorial), Article.vue has its own parallel
SectionKind map and routes assessments to a thin wrapper,
Article/Assessments.vue:
const SectionKind = {
articleBody: 'articleBody',
callToAction: 'callToAction',
hero: 'hero',
assessments: 'assessments',
};
...
[SectionKind.assessments]: Assessments, // Article/Assessments.vue
See
Article.vue#L45-L167
(the SectionKind table, componentFor, and propsFor, which forwards only
anchor and assessments from the section payload).
Article/Assessments.vue does not reimplement anything — it simply re-exports the tutorial
component's props and renders it, supplying a custom #success slot string appropriate for an
article rather than a tutorial:
<template>
<TutorialAssessments v-bind="$props">
<template #success>
<p>Great job, you've answered all the questions for this article.</p>
</template>
</TutorialAssessments>
</template>
See Article/Assessments.vue#L11-L28.
The real behavior lives in
Tutorial/Assessments.vue.
It renders a LinkableElement (root class assessments-wrapper, anchored at the
section's anchor), and inside it a grid Row with class assessments. The
component keeps local state: activeIndex (which question of the assessments array
is showing) and completed (whether the user has finished the quiz). While incomplete, it shows
an AssessmentsProgress "Question N of M" indicator plus a Quiz child bound to
this.assessments[this.activeIndex]; once completed is true it swaps to a
success slot message instead:
<div v-if="!completed">
<Progress v-bind="progress" ref="progress"/>
<Quiz :choices="activeAssessment.choices" :content="activeAssessment.content"
:isLast="isLast" :key="activeIndex" :title="activeAssessment.title"
@submit="onSubmit" @advance="onAdvance" @see-results="onSeeResults" />
</div>
<div v-else class="success">
<slot name="success"><p>{{ SuccessMessage }}</p></slot>
</div>
See
Tutorial/Assessments.vue#L11-L170.
onAdvance increments activeIndex and re-mounts Quiz (the :key
binding forces a fresh instance per question); onSeeResults sets completed = true.
The actual per-question interaction — selecting a radio choice, checking correctness, revealing
justification text, and enabling "Next" — lives one level deeper in
Tutorial/Assessments/Quiz.vue,
which renders a <fieldset class="choices"> of radio-button <label>s
(v-model="selectedIndex"), tracks a userChoices array of
{ checked } flags, and computes showNextQuestion as "every choice flagged
isCorrect has been checked" — i.e. the learner must find all correct answers (there can be
more than one) before advancing. See
Quiz.vue#L11-L152.
Question and choice text is itself further delegated to the generic block-content renderer,
ContentNode (<ContentNode :content="choice.content" />, etc.), since
title/content/choices[].content/justification are all
arrays of RenderBlockContent.
2. Example JSON and rendered mockup
No fixture in this repository's test archives or in swift-docc's own JSON test corpus contains a raw
"kind": "assessments" literal (swift-docc's own coverage for this section,
SemaToRenderNodeTests.swift, asserts against decoded Swift values rather than embedding a JSON
literal). The example below is hand-written to match the schema in the data sheet.
{
"kind": "assessments",
"anchor": "Check-Your-Understanding",
"assessments": [
{
"type": "multiple-choice",
"title": [
{ "type": "paragraph", "inlineContent": [
{ "type": "text", "text": "Which method starts the animation?" }
] }
],
"content": [
{ "type": "paragraph", "inlineContent": [
{ "type": "codeVoice", "code": "anchor.hitTest(view)" }
] }
],
"choices": [
{
"content": [
{ "type": "paragraph", "inlineContent": [
{ "type": "codeVoice", "code": "startAnimating()" }
] }
],
"isCorrect": true,
"justification": [
{ "type": "paragraph", "inlineContent": [
{ "type": "text", "text": "This is correct because it starts the run loop." }
] }
]
},
{
"content": [
{ "type": "paragraph", "inlineContent": [
{ "type": "codeVoice", "code": "stopAnimating()" }
] }
],
"isCorrect": false,
"justification": [
{ "type": "paragraph", "inlineContent": [
{ "type": "text", "text": "This stops the animation instead of starting it." }
] }
],
"reaction": "Not quite!"
}
]
}
]
}
Rendered mockup approximating question 1 of 1, before an answer is chosen:
Question 1 of 1
anchor.hitTest(view) — Which method starts the animation?
startAnimating()stopAnimating()
3. Data sheet
Schema objects, from
Sources/DocCArchive/Vendored/RenderNode.spec.json, cross-checked against the generated
Components.Schemas.AssessmentsSection / .Assessment / .Choice types in
Sources/DocCArchive/generated/Types.swift.
AssessmentsSection
| Field | Type | Required | Enum / default | Note |
|---|---|---|---|---|
kind | string | yes | "assessments" (only value) | Discriminator; generated as KindPayload single-case enum. |
anchor | string | yes | — | Section anchor id for deep-linking, e.g. Check-Your-Understanding. |
assessments | array of Assessment | yes | — | One entry per question; rendered one at a time in the UI. |
Assessment
| Field | Type | Required | Enum / default | Note |
|---|---|---|---|---|
type | string | yes | "multiple-choice" (only value) | Generated as _TypePayload.multipleChoice; only assessment kind DocC currently emits. |
title | array of RenderBlockContent | yes | — | The question phrasing, rendered by ContentNode. |
content | array of RenderBlockContent | no | — | Optional introductory content (often a code block) shown above the choices. |
choices | array of Choice | yes | — | Rendered as radio-button <label>s in Quiz.vue. |
Choice
| Field | Type | Required | Enum / default | Note |
|---|---|---|---|---|
content | array of RenderBlockContent | yes | — | The answer text shown in the choice label. |
isCorrect | boolean | yes | — | Drives correct/incorrect CSS classes and icon choice once checked; a question can have more than one correct choice. |
justification | array of RenderBlockContent | no | — | Explanation revealed only after that choice is selected. |
reaction | string | no | — | Plain-text aside shown after the choice is selected, alongside justification. |
Source: Sources/DocCArchive/Vendored/RenderNode.spec.json lines 216-297 (schema objects
AssessmentsSection, Assessment, Choice); generated types at
Sources/DocCArchive/generated/Types.swift lines 3278-3384.
4. HTML/CSS mapping in DocC-Render output
.assessments-wrapper— root wrapper rendered byLinkableElementinsideTutorial/Assessments.vue; carries the section's top/bottom spacing ($tutorial-section-spacing-single-sidein the tutorial context, or the article-specific padding rules added byArticle/Assessments.vue's own scoped.assessments-wrapperblock)..assessments(on the innerRow) — setsbackground: var(--color-tutorial-assessments-background), which resolves tovar(--color-fill-secondary)persrc/styles/core/colors/_light.scss:182..banner/.title— the "Check Your Understanding" heading band; heading text usesfont-styles(heading-2)andvar(--colors-header-text, --color-header-text)..success— shown oncecompletedis true, styled viafont-styles(alert-content)..quiz,.choices,.choice(inQuiz.vue) — the fieldset/label list of answer choices; each.choicelabel getsactive(currently selected radio),disabled,correct, orincorrectmodifier classes depending onuserChoices/selectedIndexstate..correct/.incorrect— background/border driven byvar(--color-form-valid)/var(--color-form-valid-background)andvar(--color-form-error)/var(--color-form-error-background)(_light.scss:93-96); the choice icon (CheckCircleIcon/ResetCircleIcon) inherits the same fill color..active— focus/selection ring viavar(--color-tutorial-quiz-border-active)(_light.scss:186) plus the sharedfocus-shadow()mixin.input[type="radio"]— visually hidden (opacity: 0, absolutely positioned) but kept in the DOM/tab order so the whole<label>acts as the clickable/keyboard-operable control; this is a real native radio group (name="assessment"), which is how "only one choice selectable at a time, but re-selectable before submit" is implemented..controls/.button-cta(viaButtonLink) — the Submit / Next / See Results buttons, disabled according toselectedIndex === nullorshowNextQuestion.- SCSS files involved:
Tutorial/Assessments.vue(scoped style block),Tutorial/Assessments/Quiz.vue(scoped style block),Tutorial/AssessmentsProgress.vue(scoped style block),Article/Assessments.vue(scoped style block), plus sharedsrc/styles/core/colors/_light.scss/_dark.scssandsrc/styles/core/typography/_font-styles.scss(theassessments-codefont style used for inline code inside questions/choices). - CSS custom properties consumed:
--color-tutorial-assessments-background,--color-tutorial-quiz-border-active,--color-form-valid,--color-form-valid-background,--color-form-error,--color-form-error-background,--colors-header-text/--color-header-text,--colors-text/--color-text,--colors-grid/--color-grid,--colors-secondary-label/--color-secondary-label.
5. Modern CSS-only alternative
Partial
Current behavior in play: Tutorial/Assessments.vue holds activeIndex and
completed as Vue component data(), and swaps which question/success view is
shown via v-if="!completed" plus re-keying the Quiz child on
activeIndex; separately, Quiz.vue holds per-question state
(selectedIndex, userChoices[]) and toggles correct/incorrect
classes and reveal of justification/reaction text via a
v-model-bound native <input type="radio" name="assessment"> per choice, with
button :disabled bindings computed from that state.
The per-question choice interaction (select one radio, reveal that choice's justification, style it
correct/incorrect) maps cleanly onto native CSS today: it is already implemented with a real
<input type="radio"> group, so the "which choice is active/selected" half of the state
could be held purely by :checked plus a general sibling or :has() selector (e.g.
label:has(input:checked) .answer { display: block; }) with zero JavaScript, replacing the
v-if="userChoices[index].checked" conditional reveal of the justification text. This part is
squarely applicable to a native mechanism.
However, the section as a whole is not just a single self-contained toggle: correctness must be checked
against server-supplied isCorrect data (CSS cannot compare a selected choice's identity
against a data-defined "correct answer" — it can only react to which native form control is
:checked, not evaluate a boolean encoded in JSON), and advancing between questions
(onAdvance) replaces the entire rendered question array element (a new
Quiz instance keyed by activeIndex, driven by this.assessments[this.activeIndex])
rather than toggling visibility of pre-rendered siblings, and onSeeResults/onSubmit also
perform imperative scroll-into-view logic (scrollTo/scrollIntoView with a
navigation-bar height offset). None of that survives translation to a static selector — it depends on
which answer the schema marks correct and on scripted scroll positioning. For that reason the overall
assessments section is rated partial: the single-choice reveal/highlight
interaction per question is a good :checked/:has() fit, but correctness
evaluation against JSON data and multi-question progression/auto-scroll are not expressible in CSS alone.