mirror of
https://github.com/nextui-org/nextui.git
synced 2025-12-08 19:26:11 +00:00
fix(input): missing clear button with file input type (#4599)
This commit is contained in:
parent
6159f47d06
commit
8319308727
5
.changeset/calm-seas-lie.md
Normal file
5
.changeset/calm-seas-lie.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@heroui/input": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix clear button with file input type (#4592)
|
||||||
@ -146,21 +146,26 @@ export function useInput<T extends HTMLInputElement | HTMLTextAreaElement = HTML
|
|||||||
handleValueChange,
|
handleValueChange,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const isFileTypeInput = type === "file";
|
||||||
|
const hasUploadedFiles = ((domRef?.current as HTMLInputElement)?.files?.length ?? 0) > 0;
|
||||||
const isFilledByDefault = ["date", "time", "month", "week", "range"].includes(type!);
|
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 isFilledWithin = isFilled || isFocusWithin;
|
||||||
const isHiddenType = type === "hidden";
|
const isHiddenType = type === "hidden";
|
||||||
const isMultiline = originalProps.isMultiline;
|
const isMultiline = originalProps.isMultiline;
|
||||||
const isFileTypeInput = type === "file";
|
|
||||||
|
|
||||||
const baseStyles = clsx(classNames?.base, className, isFilled ? "is-filled" : "");
|
const baseStyles = clsx(classNames?.base, className, isFilled ? "is-filled" : "");
|
||||||
|
|
||||||
const handleClear = useCallback(() => {
|
const handleClear = useCallback(() => {
|
||||||
setInputValue("");
|
if (isFileTypeInput) {
|
||||||
|
(domRef.current as HTMLInputElement).value = "";
|
||||||
|
} else {
|
||||||
|
setInputValue("");
|
||||||
|
}
|
||||||
|
|
||||||
onClear?.();
|
onClear?.();
|
||||||
domRef.current?.focus();
|
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
|
// 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
|
// i.e. setting ref.current.value to something which is uncontrolled
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user