Skip to content

Commit

Permalink
feat(initial label for dropdown)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeddnyx committed Jul 20, 2024
1 parent d57d4d6 commit e624d47
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion components/ui/form/Dropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRef, useState } from "react";
import { useEffect, useRef, useState } from "react";
import { IoIosArrowDown } from "react-icons/io";

import styles from "@/styles/component/form.module.css";
Expand All @@ -12,6 +12,7 @@ export default function DropDown({
labelSide = "top",
placeholder = "Select",
variant = "solid",
value,
onChange,
error,
isRequired = false,
Expand All @@ -24,6 +25,13 @@ export default function DropDown({
const dropdownRef = useRef<HTMLDivElement>(null);
const [getLabel, setGetLabel] = useState("");

useEffect(() => {
const initialOption = options?.find((option) => option.value === value);
if (initialOption) {
setGetLabel(initialOption.label);
}
}, [value, options]);

const handleSelect = (value: string, label: string) => {
onChange({ target: { name, value } });
setGetLabel(label);
Expand Down
1 change: 1 addition & 0 deletions types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ declare interface IDropDown {
label?: string;
labelSide?: "left" | "top";
placeholder?: string;
value?: string;
onChange: any;
isRequired?: boolean;
isDisabled?: boolean;
Expand Down

0 comments on commit e624d47

Please sign in to comment.