"use client"; import { Button } from "@/shared/components/ui/button" import { Checkbox } from "@/shared/components/ui/checkbox" import { Popover, PopoverContent, PopoverTrigger, } from "@/shared/components/ui/popover" import { useRef, useState } from "react"; interface MultiSelectProps { name: string; options?: any[]; value?: any[]; onChange: (e: { target: { name: string; value: string[] } }) => void; placeholder?: string; } export default function FormMultiSelect({ name, options = [], value = [], onChange, placeholder = "Pilih data", }: MultiSelectProps) { const toggle = (val:string) => { let newValue:string[]; if (value.includes(val)) { newValue = value.filter((v) => v !== val) } else { newValue = [...value, val] } if (onChange) { onChange({ target: { name, value: newValue, }, }) } } const selectedLabels = options .filter((o) => value.includes(o.value)) .map((o) => o.label) .join(", ") const scrollRef = useRef(null); const [isAtBottom, setIsAtBottom] = useState(false); const handleScroll = () => { console.log('gtw'); const el = scrollRef.current; if (!el) return; const atBottom = el.scrollTop + el.clientHeight >= el.scrollHeight - 2; setIsAtBottom(atBottom); }; return (
{options.map((opt) => ( ))} {!isAtBottom && (
)}
) }