diff --git a/src/core/components/Input/InputSearch/index.tsx b/src/core/components/Input/InputSearch/index.tsx index 8ae2104..6c22274 100644 --- a/src/core/components/Input/InputSearch/index.tsx +++ b/src/core/components/Input/InputSearch/index.tsx @@ -22,17 +22,33 @@ const InputSearch = ( const { readOnly = false, disabled = false, rootClassName, className, value, onChange, autoComplete = "off", error = false, name, ...rest } = props; const { inputValue, onChangeHandler, onResetInputValue } = useInput({ value, regCallback, onChange, name }); const SearchIcon = ; + const el = rootRef.current; + const isForm = el instanceof HTMLFormElement; + + const endComponent = () => { + if(isForm) { + return ( + + ); + } + + return ( +
+ {SearchIcon} +
+ ); + }; const onSubmitHandler = (e: React.FormEvent) => { - e.preventDefault(); + if(!isForm) return; - const el = rootRef.current; + e.preventDefault(); if(!formSubmitHandler) return; - if (el instanceof HTMLFormElement) { - el.reset(); - } + el.reset(); onResetInputValue(); formSubmitHandler(e); @@ -52,7 +68,7 @@ const InputSearch = ( "flex items-center py-2 text-body-02-medium bg-white overflow-hidden border border-gray-02", INPUT_SEARCH_ROUNDED[rounded], )} - onSubmit = {onSubmitHandler} + onSubmit = {el instanceof HTMLFormElement ? onSubmitHandler : undefined} inputComponent = { ( /> } endComponent = { - + endComponent() } /> );