Skip to content

Commit 13ddab0

Browse files
committed
fix: Textfield에 string 타입으로 입력 시에는 0중복입력이 가능하도록 수정
1 parent b6c32d4 commit 13ddab0

File tree

6 files changed

+15
-9
lines changed

6 files changed

+15
-9
lines changed

app/(shared)/(ThemeTextField)/Container.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default function ThemeTextField({
2323
inputRef,
2424
handleInputChange,
2525
handleInputBlur,
26-
} = useTextField({ id, content, checkErrorText });
26+
} = useTextField({ id, content, inputType, checkErrorText });
2727

2828
return (
2929
<div tabIndex={isFocus ? -1 : tabIndex} onFocus={() => setIsFocus(true)}>
@@ -54,7 +54,7 @@ export default function ThemeTextField({
5454
className={classNames("theme-textfield-input", {
5555
error: errorText,
5656
})}
57-
type={inputType}
57+
type="text"
5858
value={inputValue}
5959
placeholder={inputPlaceholder}
6060
onChange={handleInputChange}

app/(shared)/(ThemeTextField)/TextFieldType.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export type ThemeInfoTextFieldType = {
66
title?: string;
77
content: string;
88
infoText?: string;
9-
inputType?: string;
9+
inputType?: "text" | "number";
1010
inputPlaceholder?: string;
1111
checkErrorText?: ValidationFunction<unknown>;
1212
};

app/(shared)/(ThemeTextField)/useTextField.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { ThemeInfoTextFieldType } from "./TextFieldType";
88
const useTextField = ({
99
id,
1010
content,
11+
inputType,
1112
checkErrorText,
1213
}: ThemeInfoTextFieldType) => {
1314
const [inputValue, setInputValue] = useState<string>(content || "");
@@ -39,9 +40,11 @@ const useTextField = ({
3940

4041
const handleInputChange = (e: ChangeEvent<HTMLInputElement>) => {
4142
const cur = e.target.value;
42-
if (cur.length > 1 && cur.length === cur.split("0").length - 1) {
43-
setInputValue("0");
44-
return;
43+
if (inputType === "number") {
44+
if (cur.length > 1 && cur.length === cur.split("0").length - 1) {
45+
setInputValue("0");
46+
return;
47+
}
4548
}
4649
const error = checkErrorText ? checkErrorText(cur) : "";
4750
if (error) {

app/admin-new/(components)/CreateTheme/createTheme.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const timeTextFieldProps: ThemeInfoTextFieldType = {
5656
title: "탈출 제한 시간(분)",
5757
content: "",
5858
infoText: "",
59-
inputType: "text",
59+
inputType: "number",
6060
inputPlaceholder: "분 단위 숫자로 입력해 주세요",
6161
checkErrorText: timeValidations,
6262
};
@@ -67,7 +67,7 @@ export const hintCountTextFieldProps: ThemeInfoTextFieldType = {
6767
title: "사용 가능한 힌트 수",
6868
content: "",
6969
infoText: "",
70-
inputType: "text",
70+
inputType: "number",
7171
inputPlaceholder: "숫자로 입력해 주세요",
7272
checkErrorText: hintValidations,
7373
};

app/admin-new/(components)/ThemeDrawer/consts/themeDrawerProps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const rateTextFieldProps: ThemeInfoTextFieldType = {
2222
title: "문제 진행률(%)",
2323
content: "",
2424
infoText: "",
25-
inputType: "text",
25+
inputType: "number",
2626
inputPlaceholder: "",
2727
checkErrorText: progressValidations,
2828
};

app/admin-new/(components)/ThemeDrawer/helpers/textFieldHelpers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ export const codeValidations = (value: unknown) => {
88
) {
99
return "숫자로 입력해 주세요.";
1010
}
11+
if (strValue.length > 4) {
12+
return "네자리만 사용할 수 있습니다.";
13+
}
1114
if (numValue > 9999) {
1215
return "네자리만 사용할 수 있습니다.";
1316
}

0 commit comments

Comments
 (0)