diff --git a/.changeset/calm-seas-lie.md b/.changeset/calm-seas-lie.md new file mode 100644 index 000000000..47f0564fd --- /dev/null +++ b/.changeset/calm-seas-lie.md @@ -0,0 +1,5 @@ +--- +"@heroui/input": patch +--- + +fix clear button with file input type (#4592) diff --git a/packages/components/input/src/use-input.ts b/packages/components/input/src/use-input.ts index 0eb3409e3..96ec39906 100644 --- a/packages/components/input/src/use-input.ts +++ b/packages/components/input/src/use-input.ts @@ -146,21 +146,26 @@ export function useInput 0; const isFilledByDefault = ["date", "time", "month", "week", "range"].includes(type!); - const isFilled = !isEmpty(inputValue) || isFilledByDefault; + const isFilled = !isEmpty(inputValue) || isFilledByDefault || hasUploadedFiles; const isFilledWithin = isFilled || isFocusWithin; const isHiddenType = type === "hidden"; const isMultiline = originalProps.isMultiline; - const isFileTypeInput = type === "file"; const baseStyles = clsx(classNames?.base, className, isFilled ? "is-filled" : ""); const handleClear = useCallback(() => { - setInputValue(""); + if (isFileTypeInput) { + (domRef.current as HTMLInputElement).value = ""; + } else { + setInputValue(""); + } onClear?.(); domRef.current?.focus(); - }, [setInputValue, onClear]); + }, [setInputValue, onClear, isFileTypeInput]); // if we use `react-hook-form`, it will set the input value using the ref in register // i.e. setting ref.current.value to something which is uncontrolled