Skip to content

Commit a33cf2e

Browse files
authored
Merge pull request #30 from cbvora/controlled_inuput
making input as controlled compoenent
2 parents b5b4598 + 6be0cd7 commit a33cf2e

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

components/QuizForm.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ const QuizForm: FC<Props> = ({
100100
if (savedAnswer !== null && typeof savedAnswer === "string") {
101101
return savedAnswer === optionText;
102102
} else {
103-
return;
103+
return false;
104104
}
105105
};
106106

@@ -168,7 +168,7 @@ const QuizForm: FC<Props> = ({
168168
if (savedAnswer?.length) {
169169
return savedAnswer.includes(optionText);
170170
} else {
171-
return;
171+
return false;
172172
}
173173
};
174174

@@ -316,7 +316,7 @@ const QuizForm: FC<Props> = ({
316316
showCorrectAnswer[currentQuestionIndex] || false
317317
}
318318
disabled={showCorrectAnswer[currentQuestionIndex] || false}
319-
defaultChecked={
319+
checked={
320320
isOptionChecked(option.text) ||
321321
isOptionCheckedWithoutReveal(option.text)
322322
}

components/SelectionInput.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const SelectionInput = forwardRef<HTMLInputElement, Props>(
2323
showCorrectAnswer,
2424
disabled = false,
2525
defaultChecked,
26+
checked,
2627
handleChange = () => {},
2728
...rest
2829
},
@@ -38,6 +39,7 @@ const SelectionInput = forwardRef<HTMLInputElement, Props>(
3839
id={id}
3940
className={`peer hidden [&:checked_+_label_svg_path]:block `}
4041
defaultChecked={defaultChecked}
42+
checked={checked}
4143
onClick={handleChange}
4244
{...rest}
4345
/>

0 commit comments

Comments
 (0)