refactor(client): refactor fill-in-the-blank input change handler (#64014)

This commit is contained in:
Diem-Trang Pham
2025-11-20 16:24:23 -06:00
committed by GitHub
parent cf250739bf
commit da77b22495
2 changed files with 6 additions and 7 deletions
@@ -13,7 +13,7 @@ type FillInTheBlankProps = {
showFeedback: boolean;
feedback: string | null;
showWrong: boolean;
handleInputChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
handleInputChange: (inputIndex: number, value: string) => void;
};
function FillInTheBlanks({
@@ -70,8 +70,9 @@ function FillInTheBlanks({
type='text'
maxLength={blankAnswers[value].length + 3}
className={getInputClass(value)}
onChange={handleInputChange}
data-index={node.value}
onChange={e =>
handleInputChange(node.value, e.target.value)
}
size={blankAnswers[value].length}
autoComplete='off'
aria-label={t('learn.fill-in-the-blank.blank')}
@@ -160,11 +160,9 @@ const ShowFillInTheBlank = ({
}
};
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>): void => {
const inputIndex = parseInt(e.target.getAttribute('data-index') as string);
const handleInputChange = (inputIndex: number, value: string): void => {
const newUserAnswers = [...userAnswers];
newUserAnswers[inputIndex] = e.target.value;
newUserAnswers[inputIndex] = value;
const newAnswersCorrect = [...answersCorrect];
newAnswersCorrect[inputIndex] = null;