@@ -20,17 +20,23 @@ export function QuestionSet({
20
20
} : QuestionSetProps ) {
21
21
const [ value , setValue ] = React . useState ( '' ) ;
22
22
const validAnswer = React . useRef < string > ( ) ;
23
+ const validAnswerText = React . useRef < string > ( ) ;
23
24
24
25
const [ Question , Choises , Answer ] = Children . toArray ( children ) ;
25
26
26
27
//@ts -ignore
27
28
const choiseElements = Children . map ( Choises . props . children , ( child , index ) => {
28
29
if ( child . props ?. isAnswer ) {
29
30
validAnswer . current = index . toString ( ) ;
31
+ validAnswerText . current = child . props . children ;
30
32
}
33
+ const value = index . toString ( ) ;
34
+ const ariaLabel = `label_${ value } ` ;
31
35
return (
32
- < RadioItem value = { index . toString ( ) } disabled = { answerSubmitted } >
33
- < div className = "flex items-baseline [&>p]:mt-0" > { child . props . children } </ div >
36
+ < RadioItem value = { value } disabled = { answerSubmitted } ariaLabel = { ariaLabel } >
37
+ < div className = "flex items-baseline [&>p]:mt-0" id = { ariaLabel } >
38
+ { child . props . children }
39
+ </ div >
34
40
</ RadioItem >
35
41
) ;
36
42
} ) ;
@@ -63,11 +69,42 @@ export function QuestionSet({
63
69
</ QuizNavigationButton >
64
70
</ form >
65
71
{ answerSubmitted && < AnswerStatus isCorrect = { isCorrect } /> }
66
- { answerSubmitted ? Answer : null }
72
+ { answerSubmitted && (
73
+ < AnswerReveal answerText = { validAnswerText . current } isCorrect = { isCorrect } />
74
+ ) }
75
+ { answerSubmitted ? < AnswerMeta answerMeta = { Answer } /> : null }
67
76
</ CardWrapper >
68
77
) ;
69
78
}
70
79
80
+ function AnswerReveal ( {
81
+ answerText,
82
+ isCorrect
83
+ } : {
84
+ isCorrect : boolean ;
85
+ answerText : React . ReactNode ;
86
+ } ) {
87
+ const userChoseCorrectAnswer = isCorrect ;
88
+ const textMessage = userChoseCorrectAnswer
89
+ ? `✅ You chose the correct answer`
90
+ : `Oops! The correct answer is ` ;
91
+ return (
92
+ < div className = "mt-5 flex flex-col items-start gap-1" >
93
+ < p className = "text-center font-bold" > { textMessage } </ p >
94
+ { answerText }
95
+ </ div >
96
+ ) ;
97
+ }
98
+
99
+ function AnswerMeta ( { answerMeta } : { answerMeta : React . ReactNode } ) {
100
+ return (
101
+ < div className = "mt-5" >
102
+ < p className = "text-left font-bold" > Explanation:</ p >
103
+ { answerMeta }
104
+ </ div >
105
+ ) ;
106
+ }
107
+
71
108
function AnswerStatus ( { isCorrect } : { isCorrect : boolean } ) {
72
109
return (
73
110
< p className = "mt-5 text-center font-bold" >
0 commit comments