ADropdownForm.tsx 1012 Bytes
Newer Older
1
import React, { useState } from "react";
2
import { DropdownType, AnswersType } from "../types";
Lee SeoYeon's avatar
Lee SeoYeon committed
3

4
5
type Props = {
  element: DropdownType;
Jiwon Yoon's avatar
Jiwon Yoon committed
6
  answerQuestion: any | undefined;
7
8
};

Jiwon Yoon's avatar
Jiwon Yoon committed
9
export const ADropdownForm = ({ element, answerQuestion }: Props) => {
Jiwon Yoon's avatar
Jiwon Yoon committed
10
11
12
13
  const [answer, setAnswer] = useState("");

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