ARadio.tsx 1.07 KB
Newer Older
Jiwon Yoon's avatar
Jiwon Yoon committed
1
import React, { useState } from "react";
2
import { IRadio, IAnswerProps } from "../types";
Lee SeoYeon's avatar
Lee SeoYeon committed
3

4
export const ARadio = ({ element, answer: answerQuestion }: IAnswerProps) => {
Jiwon Yoon's avatar
Jiwon Yoon committed
5
6
7
8
  const [answer, setAnswer] = useState("");

  const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
    const { value } = event.currentTarget;
9
    answerQuestion.content = value;
Jiwon Yoon's avatar
Jiwon Yoon committed
10
    setAnswer(value);
11
    if (answerQuestion.content) {
Jiwon Yoon's avatar
Jiwon Yoon committed
12
13
14
15
16
      answerQuestion.requiredCheck = true;
    } else {
      answerQuestion.requiredCheck = false;
    }
    console.log(answerQuestion);
Jiwon Yoon's avatar
Jiwon Yoon committed
17
  };
Lee SeoYeon's avatar
Lee SeoYeon committed
18
  return (
Jiwon Yoon's avatar
Jiwon Yoon committed
19
    <div className="flex w-full gap-2 justify-center my-3">
20
      {element.content.choices.map((choice) => (
Jiwon Yoon's avatar
Jiwon Yoon committed
21
        <div key={choice.value} className="mx-2">
Jiwon Yoon's avatar
Jiwon Yoon committed
22
23
24
25
26
27
28
29
30
31
32
          <input
            className="mr-2"
            type="radio"
            id={choice.text}
            name={element._id}
            onChange={handleChange}
            value={choice.text}
          ></input>
          <label className="text-lg" id={choice.text}>
            {choice.text}
          </label>
Lee SeoYeon's avatar
Lee SeoYeon committed
33
        </div>
34
      ))}
Lee SeoYeon's avatar
Lee SeoYeon committed
35
36
37
    </div>
  );
};