From 61e3e88a6c9d57e95441059369ee5a46f5c07601 Mon Sep 17 00:00:00 2001 From: Vivian Phung Date: Wed, 22 May 2024 15:06:50 -0400 Subject: [PATCH] Refactor `Input` and `SearchBar` (#199) ### TL;DR This pull request refactors the `SearchBar` and `Input` components, adding a `ref` to the former and removing an incorrect understanding of `react-hook-form` (yes, i prev "fix" the component) in the latter. ### What changed? A ref is added to the SearchBar component for better control and handling. In the Input component, we have eliminated the usage of 'react-hook-form' and as a result, the 'register' prop is removed. This makes the component less reliant on specific libraries and more reusable. ### How to test? Ensure that proper testing is done on the updated components. Make sure that the `SearchBar` works as expected with its ref and that Input does not depend on 'react-hook-form' anymore. ### Why make this change? This change was made to improve the functionality of the `SearchBar` and the flexibility of the Input component, making them more effective and reusable respectively. The changes also align with the current code quality standards and best practices. --- packages/frontend/src/components/SearchBar.tsx | 3 ++- .../frontend/src/components/shared/Input/Input.tsx | 10 ++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/packages/frontend/src/components/SearchBar.tsx b/packages/frontend/src/components/SearchBar.tsx index a81b9f9..af36927 100644 --- a/packages/frontend/src/components/SearchBar.tsx +++ b/packages/frontend/src/components/SearchBar.tsx @@ -6,7 +6,7 @@ import { Input, InputProps } from './shared/Input'; const SearchBar: React.ForwardRefRenderFunction< HTMLInputElement, InputProps & RefAttributes -> = ({ value, onChange, placeholder = 'Search', ...props }) => { +> = ({ value, onChange, placeholder = 'Search', ...props }, ref) => { return (
); diff --git a/packages/frontend/src/components/shared/Input/Input.tsx b/packages/frontend/src/components/shared/Input/Input.tsx index 503e3d3..0c1841a 100644 --- a/packages/frontend/src/components/shared/Input/Input.tsx +++ b/packages/frontend/src/components/shared/Input/Input.tsx @@ -4,7 +4,6 @@ import { useMemo, ComponentPropsWithoutRef, } from 'react'; -import { FieldValues, UseFormRegister } from 'react-hook-form'; import { WarningIcon } from 'components/shared/CustomIcon'; import { cloneIcon } from 'utils/cloneIcon'; @@ -12,7 +11,7 @@ import { cn } from 'utils/classnames'; import { InputTheme, inputTheme } from './Input.theme'; -export interface InputProps +export interface InputProps extends InputTheme, Omit, 'size'> { label?: string; @@ -20,9 +19,6 @@ export interface InputProps leftIcon?: ReactNode; rightIcon?: ReactNode; helperText?: string; - - // react-hook-form optional register - register?: ReturnType>; } const Input = forwardRef( @@ -34,7 +30,6 @@ const Input = forwardRef( leftIcon, rightIcon, helperText, - register, size, state, appearance, @@ -107,12 +102,11 @@ const Input = forwardRef(
{leftIcon && renderLeftIcon} {rightIcon && renderRightIcon}