From bdfa0e9e07d1073d1e3581edc23852d5efdacd8b Mon Sep 17 00:00:00 2001 From: chacha Date: Mon, 30 Sep 2024 23:11:34 +0900 Subject: [PATCH] feat: add optional to PhoneInput --- packages/web/src/common/components/Forms/PhoneInput.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/web/src/common/components/Forms/PhoneInput.tsx b/packages/web/src/common/components/Forms/PhoneInput.tsx index ae9bcd9..c4c1e25 100644 --- a/packages/web/src/common/components/Forms/PhoneInput.tsx +++ b/packages/web/src/common/components/Forms/PhoneInput.tsx @@ -84,7 +84,7 @@ const InputWrapper = styled.div` `; // Component -const PhoneInput: React.FC = ({ +const PhoneInput: React.FC = ({ label = "", placeholder, disabled = false, @@ -92,6 +92,7 @@ const PhoneInput: React.FC = ({ handleChange = () => {}, // setValue setErrorStatus = () => {}, onChange = undefined, // display results (complicated) + optional = false, ...props }) => { const [error, setError] = useState(""); @@ -117,7 +118,7 @@ const PhoneInput: React.FC = ({ const isValidFormat = /^(\d{3}-\d{4}-\d{4})$/.test(value) || /^\d*$/.test(value.replace(/-/g, "")); - if (!value) { + if (!optional && !value) { setError("필수로 채워야 하는 항목입니다"); } else if (!isValidFormat) { setError("숫자만 입력 가능합니다");