ADropdown.tsx 992 Bytes
Newer Older
1
import React, { useState } from "react";
2
import { IDropdown, IAnswerProps } from "../types";
Lee SeoYeon's avatar
Lee SeoYeon committed
3

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

  const handleChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
    const { value } = event.currentTarget;
12
    answerQuestion.content = value;
Jiwon Yoon's avatar
Jiwon Yoon committed
13
    setAnswer(value);
14
    if (answerQuestion.content) {
Jiwon Yoon's avatar
Jiwon Yoon committed
15
16
17
18
19
      answerQuestion.requiredCheck = true;
    } else {
      answerQuestion.requiredCheck = false;
    }
    console.log(answerQuestion);
Jiwon Yoon's avatar
Jiwon Yoon committed
20
  };
Lee SeoYeon's avatar
Lee SeoYeon committed
21
  return (
Lee SeoYeon's avatar
Lee SeoYeon committed
22
    <div className="flex flex-col container w-11/12 h-auto m-3 py-3">
Jiwon Yoon's avatar
Jiwon Yoon committed
23
      <select
Lee SeoYeon's avatar
Lee SeoYeon committed
24
        className="py-2 w-48 hover:bg-gray-200 border border-black rounded"
Jiwon Yoon's avatar
Jiwon Yoon committed
25
26
        onChange={handleChange}
      >
27
        {element.content.choices.map((choice) => (
jang dong hyeok's avatar
jang dong hyeok committed
28
29
30
          <option key={choice.value} value={choice.text}>
            {choice.text}
          </option>
31
        ))}
Lee SeoYeon's avatar
Lee SeoYeon committed
32
33
34
35
      </select>
    </div>
  );
};