From 9bb02958632a97b39fdff54c0513c2e6bcd144e8 Mon Sep 17 00:00:00 2001 From: caichi Date: Thu, 5 Dec 2024 19:22:02 +0900 Subject: [PATCH 1/2] fix: rune type bug --- web/src/components/atoms/Input/index.tsx | 3 +-- web/src/components/atoms/Markdown/index.tsx | 5 ++--- web/src/components/atoms/TextArea/index.tsx | 3 +-- .../Content/Form/fields/FieldComponents/DefaultField.tsx | 4 ++-- .../Content/Form/fields/FieldComponents/MarkdownField.tsx | 4 ++-- .../Content/Form/fields/FieldComponents/TextareaField.tsx | 4 ++-- .../Schema/FieldModal/FieldDefaultInputs/Markdown/index.tsx | 4 ++-- .../Schema/FieldModal/FieldDefaultInputs/TextArea/index.tsx | 4 ++-- .../Schema/FieldModal/FieldDefaultInputs/TextField/index.tsx | 4 ++-- 9 files changed, 16 insertions(+), 19 deletions(-) diff --git a/web/src/components/atoms/Input/index.tsx b/web/src/components/atoms/Input/index.tsx index e1f17b3f05..f63067e2c0 100644 --- a/web/src/components/atoms/Input/index.tsx +++ b/web/src/components/atoms/Input/index.tsx @@ -5,7 +5,6 @@ import { runes } from "runes2"; export type { SearchProps } from "antd/lib/input"; type Props = { - value?: string; isError?: boolean; } & InputProps; @@ -15,7 +14,7 @@ const Input = forwardRef( if ( isError || (required && !value) || - (maxLength && value && runes(value).length > maxLength) + (maxLength && typeof value === "string" && value && runes(value).length > maxLength) ) { return "error"; } diff --git a/web/src/components/atoms/Markdown/index.tsx b/web/src/components/atoms/Markdown/index.tsx index eafc8c0a1d..cf338440bd 100644 --- a/web/src/components/atoms/Markdown/index.tsx +++ b/web/src/components/atoms/Markdown/index.tsx @@ -6,7 +6,6 @@ import { runes } from "runes2"; import TextArea, { TextAreaProps } from "@reearth-cms/components/atoms/TextArea"; type Props = { - value?: string; onChange?: (value: string) => void; isError?: boolean; } & TextAreaProps; @@ -17,7 +16,7 @@ const MarkdownInput: React.FC = ({ value, onChange, ...props }) => { const isError = useMemo(() => { if (props.isError || (props.required && !value)) { return true; - } else if (props.maxLength && value) { + } else if (props.maxLength && value && typeof value === "string") { return runes(value).length > props.maxLength; } else { return false; @@ -52,7 +51,7 @@ const MarkdownInput: React.FC = ({ value, onChange, ...props }) => { showCount /> ); diff --git a/web/src/components/atoms/TextArea/index.tsx b/web/src/components/atoms/TextArea/index.tsx index 852323b889..118115a323 100644 --- a/web/src/components/atoms/TextArea/index.tsx +++ b/web/src/components/atoms/TextArea/index.tsx @@ -3,7 +3,6 @@ import { forwardRef, useMemo } from "react"; import { runes } from "runes2"; type Props = { - value?: string; isError?: boolean; } & TextAreaProps; @@ -13,7 +12,7 @@ const TextArea = forwardRef( if ( isError || (required && !value) || - (maxLength && value && runes(value).length > maxLength) + (maxLength && typeof value === "string" && value && runes(value).length > maxLength) ) { return "error"; } diff --git a/web/src/components/molecules/Content/Form/fields/FieldComponents/DefaultField.tsx b/web/src/components/molecules/Content/Form/fields/FieldComponents/DefaultField.tsx index 7f01f130bc..8d17c7aa10 100644 --- a/web/src/components/molecules/Content/Form/fields/FieldComponents/DefaultField.tsx +++ b/web/src/components/molecules/Content/Form/fields/FieldComponents/DefaultField.tsx @@ -42,10 +42,10 @@ const DefaultField: React.FC = ({ validator: (_, value) => { if (value && maxLength) { if (Array.isArray(value)) { - if (value.some(v => maxLength < runes(v).length)) { + if (value.some(v => typeof v === "string" && maxLength < runes(v).length)) { return Promise.reject(); } - } else if (maxLength < runes(value).length) { + } else if (typeof value === "string" && maxLength < runes(value).length) { return Promise.reject(); } } diff --git a/web/src/components/molecules/Content/Form/fields/FieldComponents/MarkdownField.tsx b/web/src/components/molecules/Content/Form/fields/FieldComponents/MarkdownField.tsx index e1d552d739..9732475a3a 100644 --- a/web/src/components/molecules/Content/Form/fields/FieldComponents/MarkdownField.tsx +++ b/web/src/components/molecules/Content/Form/fields/FieldComponents/MarkdownField.tsx @@ -36,10 +36,10 @@ const MarkdownField: React.FC = ({ field, itemGroupId, disabl validator: (_, value) => { if (value && maxLength) { if (Array.isArray(value)) { - if (value.some(v => maxLength < runes(v).length)) { + if (value.some(v => typeof v === "string" && maxLength < runes(v).length)) { return Promise.reject(); } - } else if (maxLength < runes(value).length) { + } else if (typeof value === "string" && maxLength < runes(value).length) { return Promise.reject(); } } diff --git a/web/src/components/molecules/Content/Form/fields/FieldComponents/TextareaField.tsx b/web/src/components/molecules/Content/Form/fields/FieldComponents/TextareaField.tsx index 571a4a60f9..86b3feb990 100644 --- a/web/src/components/molecules/Content/Form/fields/FieldComponents/TextareaField.tsx +++ b/web/src/components/molecules/Content/Form/fields/FieldComponents/TextareaField.tsx @@ -36,10 +36,10 @@ const TextareaField: React.FC = ({ field, itemGroupId, disabl validator: (_, value) => { if (value && maxLength) { if (Array.isArray(value)) { - if (value.some(v => maxLength < runes(v).length)) { + if (value.some(v => typeof v === "string" && maxLength < runes(v).length)) { return Promise.reject(); } - } else if (maxLength < runes(value).length) { + } else if (typeof value === "string" && maxLength < runes(value).length) { return Promise.reject(); } } diff --git a/web/src/components/molecules/Schema/FieldModal/FieldDefaultInputs/Markdown/index.tsx b/web/src/components/molecules/Schema/FieldModal/FieldDefaultInputs/Markdown/index.tsx index 5741af8f07..6733bbc76d 100644 --- a/web/src/components/molecules/Schema/FieldModal/FieldDefaultInputs/Markdown/index.tsx +++ b/web/src/components/molecules/Schema/FieldModal/FieldDefaultInputs/Markdown/index.tsx @@ -24,10 +24,10 @@ const MarkdownField: React.FC = ({ multiple, maxLength }) => { validator: (_, value) => { if (value && maxLength) { if (Array.isArray(value)) { - if (value.some(v => maxLength < runes(v).length)) { + if (value.some(v => typeof v === "string" && maxLength < runes(v).length)) { return Promise.reject(); } - } else if (maxLength < runes(value).length) { + } else if (typeof value === "string" && maxLength < runes(value).length) { return Promise.reject(); } } diff --git a/web/src/components/molecules/Schema/FieldModal/FieldDefaultInputs/TextArea/index.tsx b/web/src/components/molecules/Schema/FieldModal/FieldDefaultInputs/TextArea/index.tsx index 7dade9e05e..a09ce64f1c 100644 --- a/web/src/components/molecules/Schema/FieldModal/FieldDefaultInputs/TextArea/index.tsx +++ b/web/src/components/molecules/Schema/FieldModal/FieldDefaultInputs/TextArea/index.tsx @@ -23,10 +23,10 @@ const TextAreaField: React.FC = ({ multiple, maxLength }) => { validator: (_, value) => { if (value && maxLength) { if (Array.isArray(value)) { - if (value.some(v => maxLength < runes(v).length)) { + if (value.some(v => typeof v === "string" && maxLength < runes(v).length)) { return Promise.reject(); } - } else if (maxLength < runes(value).length) { + } else if (typeof value === "string" && maxLength < runes(value).length) { return Promise.reject(); } } diff --git a/web/src/components/molecules/Schema/FieldModal/FieldDefaultInputs/TextField/index.tsx b/web/src/components/molecules/Schema/FieldModal/FieldDefaultInputs/TextField/index.tsx index 73463e78eb..cec429b0e5 100644 --- a/web/src/components/molecules/Schema/FieldModal/FieldDefaultInputs/TextField/index.tsx +++ b/web/src/components/molecules/Schema/FieldModal/FieldDefaultInputs/TextField/index.tsx @@ -24,10 +24,10 @@ const TextField: React.FC = ({ multiple, maxLength }) => { validator: (_, value) => { if (value && maxLength) { if (Array.isArray(value)) { - if (value.some(v => maxLength < runes(v).length)) { + if (value.some(v => typeof v === "string" && maxLength < runes(v).length)) { return Promise.reject(); } - } else if (maxLength < runes(value).length) { + } else if (typeof value === "string" && maxLength < runes(value).length) { return Promise.reject(); } } From be7fffb073709231df38a38521431845c1bbacc2 Mon Sep 17 00:00:00 2001 From: caichi Date: Thu, 5 Dec 2024 19:35:20 +0900 Subject: [PATCH 2/2] fix: condition order --- web/src/components/atoms/Markdown/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/components/atoms/Markdown/index.tsx b/web/src/components/atoms/Markdown/index.tsx index cf338440bd..aa6175de80 100644 --- a/web/src/components/atoms/Markdown/index.tsx +++ b/web/src/components/atoms/Markdown/index.tsx @@ -16,7 +16,7 @@ const MarkdownInput: React.FC = ({ value, onChange, ...props }) => { const isError = useMemo(() => { if (props.isError || (props.required && !value)) { return true; - } else if (props.maxLength && value && typeof value === "string") { + } else if (props.maxLength && typeof value === "string" && value) { return runes(value).length > props.maxLength; } else { return false;