From 09f80dfe4d3a313b41bd712f91bac0b43fccb0c7 Mon Sep 17 00:00:00 2001 From: Flo Drews Date: Thu, 5 Dec 2024 13:15:25 +0100 Subject: [PATCH 1/7] feat(textarea): add possibility to set max char length --- app/components/inputs/Textarea.tsx | 5 +- .../inputs/__test__/Textarea.test.tsx | 68 ++++++++++++++++++- .../userFeedback/FeedbackFormBox.tsx | 1 + .../cms/components/StrapiTextarea.tsx | 13 +++- stories/Textarea.stories.tsx | 4 ++ 5 files changed, 83 insertions(+), 8 deletions(-) diff --git a/app/components/inputs/Textarea.tsx b/app/components/inputs/Textarea.tsx index 9761cb3f2..c34652210 100644 --- a/app/components/inputs/Textarea.tsx +++ b/app/components/inputs/Textarea.tsx @@ -3,7 +3,6 @@ import type { AriaRole, ReactNode } from "react"; import { useField } from "remix-validated-form"; import { Details } from "~/components/Details"; import InputLabel from "~/components/inputs/InputLabel"; -import { TEXTAREA_CHAR_LIMIT } from "~/services/validation/inputlimits"; import { type ErrorMessageProps } from "."; import InputError from "./InputError"; import RichText from "../RichText"; @@ -17,6 +16,7 @@ type TextareaProps = Readonly<{ content: string; }; placeholder?: string; + maxCharacterLimit: number; errorMessages?: ErrorMessageProps[]; formId?: string; classNameLabel?: string; @@ -33,6 +33,7 @@ const Textarea = ({ label, details, placeholder, + maxCharacterLimit, errorMessages, classNameLabel, role, @@ -60,7 +61,7 @@ const Textarea = ({ {...getInputProps({ id: name, placeholder, - maxLength: TEXTAREA_CHAR_LIMIT, + maxLength: maxCharacterLimit, })} rows={TEXT_AREA_ROWS} className={classNames( diff --git a/app/components/inputs/__test__/Textarea.test.tsx b/app/components/inputs/__test__/Textarea.test.tsx index e901a329f..35ebacfd5 100644 --- a/app/components/inputs/__test__/Textarea.test.tsx +++ b/app/components/inputs/__test__/Textarea.test.tsx @@ -27,15 +27,24 @@ afterEach(() => { describe("Textarea component", () => { it("renders without errors", () => { const componentName = "test-textarea"; + const maxLength = 5000; + getInputProps.mockImplementationOnce(() => ({ id: componentName, placeholder: "Test Placeholder", + maxLength: maxLength, })); + const RemixStub = createRemixStub([ { path: "", Component: () => ( -