ARadio.tsx 1.08 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="md:flex 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
          <input
            className="mr-2"
            type="radio"
            id={choice.text}
            name={element._id}
            onChange={handleChange}
            value={choice.text}
          ></input>
Jiwon Yoon's avatar
Jiwon Yoon committed
30
          <label className="md:text-lg text-base" id={choice.text}>
Jiwon Yoon's avatar
Jiwon Yoon committed
31
32
            {choice.text}
          </label>
Lee SeoYeon's avatar
Lee SeoYeon committed
33
        </div>
34
      ))}
Lee SeoYeon's avatar
Lee SeoYeon committed
35
36
37
    </div>
  );
};