Skip to content

Commit f8bcd4a

Browse files
committed
refactor: TextField maxLength 계산 로직 함수로 분리
1 parent 84cbfac commit f8bcd4a

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

src/shared/ui/TextField/TextField.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@ const formatNumberWithComma = (digits: string) => {
2020
return new Intl.NumberFormat('ko-KR').format(n);
2121
};
2222

23+
const getMaxLength = ({
24+
isChar,
25+
isTextarea,
26+
maxLength,
27+
}: {
28+
isChar: boolean;
29+
isTextarea: boolean;
30+
maxLength?: number;
31+
}) => {
32+
if (isChar) {
33+
return CHAR_MAX_LENGTH;
34+
}
35+
if (maxLength !== undefined) {
36+
return maxLength;
37+
}
38+
return isTextarea ? TEXTAREA_MAX_LENGTH : undefined;
39+
};
40+
2341
export const TextField = ({
2442
label,
2543
value: controlledValue,
@@ -43,9 +61,7 @@ export const TextField = ({
4361
const isChar = type === 'char';
4462
const isPrice = type === 'price';
4563

46-
const maxLen = isChar
47-
? CHAR_MAX_LENGTH
48-
: (maxLength ?? (isTextarea ? TEXTAREA_MAX_LENGTH : undefined));
64+
const maxLen = getMaxLength({ isChar, isTextarea, maxLength });
4965
const normalizedValue = isPrice ? rawValue.replace(/\D/g, '') : rawValue;
5066

5167
const displayValue = useMemo(() => {

0 commit comments

Comments
 (0)