Skip to content

Commit

Permalink
feat: 최대 글자 제한을 UI에 표시한다(#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
loopy-lim authored Mar 3, 2024
2 parents 9bcd362 + 1874a05 commit 07a199a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import RadioGroup from "@/components/common/Radio.component";
import Txt from "@/components/common/Txt.component";
import { MAX_TEXT_LENGTH } from "@/src/constants";
import type {
ApplicationBooleanTextarea,
ApplicationQuestion,
} from "@/src/constants/application/type";
import { useLocalStorage } from "@/src/hooks/useLocalstorage.hook";
import { FormEvent } from "react";

interface TextAreaProps {
node: {
Expand All @@ -21,6 +23,9 @@ interface TextAreaProps {

const TextArea = ({ node }: TextAreaProps) => {
const [textValue, setTextValue] = useLocalStorage(node.name, "");
const onInput = (e: FormEvent<HTMLTextAreaElement>) => {
setTextValue(e.currentTarget.value.slice(0, MAX_TEXT_LENGTH));
};

return (
<div className="flex gap-6">
Expand All @@ -32,15 +37,16 @@ const TextArea = ({ node }: TextAreaProps) => {
<Txt className="pl-4 block break-keep">{node.subtitle}</Txt>
</div>
</div>
<div className="flex-1">
<div className="flex-1 relative">
<textarea
className="my-2 border rounded-lg p-4 w-full resize-none"
className="border rounded-lg px-4 py-6 w-full resize-none"
rows={20}
maxLength={1000}
name={node.name}
value={textValue}
onInput={(e) => setTextValue(e.currentTarget.value)}
onInput={onInput}
/>
<div className="absolute bottom-3 right-4 bg-white text-sm">{`(${textValue.length}/${MAX_TEXT_LENGTH})`}</div>
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"use client";

import Txt from "@/components/common/Txt.component";
import { MAX_TEXT_LENGTH } from "@/src/constants";
import {
ApplicationNode,
ApplicationTextarea,
} from "@/src/constants/application/type";
import { useLocalStorage } from "@/src/hooks/useLocalstorage.hook";
import { FormEvent } from "react";

interface ApplicationTextareaProps {
data: ApplicationNode;
Expand All @@ -15,6 +17,10 @@ const ApplicationTexarea = ({ data }: ApplicationTextareaProps) => {
const textData = data as ApplicationTextarea;
const [value, setValue] = useLocalStorage(textData.name, "");

const onInput = (e: FormEvent<HTMLTextAreaElement>) => {
setValue(e.currentTarget.value.slice(0, MAX_TEXT_LENGTH));
};

return (
<>
{textData.title && (
Expand All @@ -25,16 +31,17 @@ const ApplicationTexarea = ({ data }: ApplicationTextareaProps) => {
{textData.subtitle && <Txt>{` ${textData.subtitle}`}</Txt>}
</label>
)}
<textarea
className="my-2 border rounded-lg p-4 w-full resize-none"
rows={20}
name={textData.name}
value={value}
maxLength={1000}
onInput={(e) => {
setValue(e.currentTarget.value);
}}
/>
<div className="relative">
<textarea
className="border rounded-lg px-4 py-6 w-full resize-none"
rows={20}
name={textData.name}
value={value}
maxLength={1000}
onInput={onInput}
/>
<div className="absolute bottom-3 right-4 bg-white text-sm">{`(${value.length}/${MAX_TEXT_LENGTH})`}</div>
</div>
</>
);
};
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,5 @@ export const needValidatePath = [
"/interview",
"/kanban",
];

export const MAX_TEXT_LENGTH = 1000;

0 comments on commit 07a199a

Please sign in to comment.