"use client"; import { useRef, useState, type ComponentProps } from "react"; import { XIcon } from "lucide-react"; import { Input } from "@/components/ui/input"; import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput } from "@/components/ui/input-group"; export function ClearableInput({ className, ...props }: ComponentProps) { const editableText = ["text", "search", "email", "url", "tel"].includes(props.type ?? "text"); if (!editableText) return ; return ; } export function ClearableInputGroupInput({ ref, onChange, onValueChange, ...props }: ComponentProps) { const inputRef = useRef(null); const [uncontrolledValue, setUncontrolledValue] = useState(props.defaultValue ?? ""); const value = props.value ?? uncontrolledValue; return ( <> { inputRef.current = node; if (typeof ref === "function") return ref(node); if (ref) ref.current = node; }} onChange={(event) => { setUncontrolledValue(event.target.value); onValueChange?.(event.target.value); onChange?.(event); }} /> {String(value).length > 0 && !props.disabled && !props.readOnly ? ( { const input = inputRef.current; if (!input) return; // Use the native setter so React receives the same change as typing. Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")?.set?.call(input, ""); input.dispatchEvent(new Event("input", { bubbles: true })); input.focus(); }} > ) : null} ); }