From 68b01cef5eab9295a88ebbac88ac296fc4b97cd6 Mon Sep 17 00:00:00 2001 From: Takhyun Kim Date: Thu, 12 Oct 2023 17:08:58 +0900 Subject: [PATCH] feat(textfield): apply forwardRef to TextField component --- .../src/components/TextField/TextField.tsx | 106 +++++++++--------- 1 file changed, 55 insertions(+), 51 deletions(-) diff --git a/packages/design-system/src/components/TextField/TextField.tsx b/packages/design-system/src/components/TextField/TextField.tsx index fc5be331..e1671e9b 100644 --- a/packages/design-system/src/components/TextField/TextField.tsx +++ b/packages/design-system/src/components/TextField/TextField.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { forwardRef } from "react"; import TextFieldIcon from "./TextFieldIcon"; import { BaseTextField } from "./TextField.style"; @@ -9,57 +9,60 @@ import type { SingleTextFieldProps, } from "./TextField.types"; -const SingleTextField = (props: SingleTextFieldProps) => { - const { - size = "small", - leftIcon, - rightIcon, - leftIconSx, - rightIconSx, - onLeftIconClick, - onRightIconClick, - InputProps, - ...restProps - } = props; +const SingleTextField = forwardRef( + (props, ref) => { + const { + size = "small", + leftIcon, + rightIcon, + leftIconSx, + rightIconSx, + onLeftIconClick, + onRightIconClick, + InputProps, + ...restProps + } = props; - return ( - - ), - endAdornment: rightIcon && ( - - ), - }, - ...InputProps, - }} - /> - ); -}; + return ( + + ), + endAdornment: rightIcon && ( + + ), + }, + ...InputProps, + }} + /> + ); + } +); -const MultiTextField = ({ - size = "small", - onChange, - ...restProps -}: MultiTextFieldProps) => { - return ; -}; +const MultiTextField = forwardRef( + ({ size = "small", onChange, ...restProps }, ref) => { + return ( + + ); + } +); -const TextField = (props: TextFieldProps) => { +const TextField = forwardRef((props, ref) => { const { rows, size, @@ -71,14 +74,15 @@ const TextField = (props: TextFieldProps) => { return multiline ? ( ) : ( - + ); -}; +}); export default TextField;