Skip to content

Commit

Permalink
fix(ui): TextArea Value prop이 undefined일 경우 발생하는 타입 에러 수정 (#216)
Browse files Browse the repository at this point in the history
* fix: Textarea value.length undefined

* cs
  • Loading branch information
Brokyeom authored Nov 26, 2024
1 parent b3e4965 commit 6d311fd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/pretty-eggs-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sopt-makers/ui': patch
---

TextArea Value prop이 undefined일 경우 발생하는 타입 에러 수정
2 changes: 1 addition & 1 deletion apps/docs/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function App() {
rightAddon={{ onClick: () => handleTextareaSubmit() }}
validationFn={textareaValidation}
errorMessage='Error Message'
value={textarea}
// value={textarea}
onChange={handleTextareaChange}
maxLength={300}
/>
Expand Down
10 changes: 5 additions & 5 deletions packages/ui/Input/TextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>((props, forwarde
isError,
validationFn,
errorMessage,
value = '',
value,
disableEnterSubmit = false,
maxLength,
fixedHeight,
Expand All @@ -45,8 +45,8 @@ const TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>((props, forwarde
const { onChange, ...restInputProps } = inputProps;
const { disabled, readOnly, required } = restInputProps;

const isValid = validationFn ? validationFn(value) : true;
const isEmpty = value.length === 0;
const isValid = validationFn ? validationFn(value ?? '') : true;
const isEmpty = value && value.length === 0;

const submitButtonRef = useRef<HTMLButtonElement | null>(null);

Expand Down Expand Up @@ -171,8 +171,8 @@ const TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>((props, forwarde
)}

{maxLength ? (
<p className={`${S.count} ${value.length > maxLength ? S.maxCount : ''}`}>
{value.length}/{maxLength}
<p className={`${S.count} ${!isEmpty && value && value.length > maxLength ? S.maxCount : ''}`}>
{value?.length}/{maxLength}
</p>
) : null}
</div>
Expand Down

0 comments on commit 6d311fd

Please sign in to comment.