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

4
interface Props extends AnswerProps {
5
  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 (
Lee SeoYeon's avatar
Lee SeoYeon committed
24
    <div className="flex flex-col container w-11/12 h-auto m-3 py-3">
Jiwon Yoon's avatar
Jiwon Yoon committed
25
      <select
Lee SeoYeon's avatar
Lee SeoYeon committed
26
        className="py-2 w-48 hover:bg-gray-200 border border-black rounded"
Jiwon Yoon's avatar
Jiwon Yoon committed
27
28
        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>
  );
};