fix(a11y): associate MCQ options with the correct question (#59297)

This commit is contained in:
Huyen Nguyen
2025-03-19 02:03:45 -07:00
committed by GitHub
parent 2d222bf7d2
commit 9f8ba47b66
2 changed files with 13 additions and 4 deletions
@@ -35,8 +35,10 @@ function MultipleChoiceQuestions({
}
/>
{questions.map((question, questionIndex) => (
<div key={questionIndex}>
<PrismFormatted className={'line-numbers'} text={question.text} />
<fieldset key={questionIndex}>
<legend className='mcq-question-text'>
<PrismFormatted className={'line-numbers'} text={question.text} />
</legend>
<div className='video-quiz-options'>
{question.answers.map(({ answer }, answerIndex) => {
const isSubmittedAnswer =
@@ -57,7 +59,7 @@ function MultipleChoiceQuestions({
htmlFor={`mc-question-${questionIndex}-answer-${answerIndex}`}
>
<input
name='quiz'
name={`mc-question-${questionIndex}`}
checked={selectedOptions[questionIndex] === answerIndex}
className='sr-only'
onChange={() =>
@@ -109,7 +111,7 @@ function MultipleChoiceQuestions({
})}
</div>
<Spacer size='m' />
</div>
</fieldset>
))}
<Spacer size='m' />
</>
@@ -150,3 +150,10 @@ input:focus-visible + .video-quiz-input-visible {
.mcq-prism-incorrect code {
color: var(--danger-color);
}
/* Override the default styles of `legend` element */
.mcq-question-text {
border: none;
color: var(--primary-color);
margin: 0;
}