Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): TextArea 컴포넌트 forwardRef 추가, value prop optional로 변경. #214

Merged
merged 2 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eight-donuts-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sopt-makers/ui': patch
---

Add forwardRef in TextArea component
21 changes: 16 additions & 5 deletions packages/ui/Input/TextArea.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { useMemo, useRef, type ChangeEvent, type TextareaHTMLAttributes, isValidElement, useState } from 'react';
import {
useMemo,
useRef,
type ChangeEvent,
type TextareaHTMLAttributes,
isValidElement,
useState,
forwardRef,
} from 'react';
import * as S from './style.css';
import AlertCircleIcon from './icons/AlertCircleIcon';
import SendIcon from './icons/SendIcon';
Expand All @@ -11,23 +19,23 @@ interface TextAreaProps extends Omit<TextareaHTMLAttributes<HTMLTextAreaElement>
isError?: boolean;
validationFn?: (input: string) => boolean; // isError가 없을 때만 적용
errorMessage?: string; // isError 또는 validationFn 결과가 true일 때만 표시
value: string; // string 타입으로 한정
value?: string; // string 타입으로 한정

disableEnterSubmit?: boolean; // true일 경우, Enter 키는 줄바꿈으로 동작
maxLength?: number; // 없으면 무제한
fixedHeight?: number; // px -> 늘어나지 않도록 높이를 고정
maxHeight?: number; // px -> 늘어나면서 최대 높이를 제한
}

function TextArea(props: TextAreaProps) {
const TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>((props, forwardedRef) => {
const {
className,
topAddon,
rightAddon,
isError,
validationFn,
errorMessage,
value,
value = '',
disableEnterSubmit = false,
maxLength,
fixedHeight,
Expand Down Expand Up @@ -132,6 +140,7 @@ function TextArea(props: TextAreaProps) {

<div className={`${S.textareaWrap} ${hasError ? S.inputError : ''} ${isFocused ? S.focus : ''}`}>
<textarea
ref={forwardedRef}
{...restInputProps}
className={`${S.input} ${S.textarea}`}
id={labelText}
Expand Down Expand Up @@ -170,6 +179,8 @@ function TextArea(props: TextAreaProps) {
) : null}
</div>
);
}
});

TextArea.displayName = 'TextArea';

export default TextArea;
Loading