mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
fix(a11y): associate MCQ options with the correct question (#59297)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user