From eac304e1d6070837ac99e91c31c24dc45caa00ad Mon Sep 17 00:00:00 2001 From: pratik <97376240+pratik9818@users.noreply.github.com> Date: Tue, 28 Nov 2023 12:58:54 +0530 Subject: [PATCH] feat: character limit on tags (#9762) * changing * update all changes * complete all changes * Update components/tag/TagsInput.js * done * done --------- Co-authored-by: Eddie Jaoude --- components/tag/TagsInput.js | 40 +++++++++++++++++++--- pages/account/manage/event/[[...data]].js | 5 ++- pages/account/manage/profile.js | 5 ++- pages/docs/how-to-guides/editing-forms.mdx | 6 ++-- 4 files changed, 47 insertions(+), 9 deletions(-) diff --git a/components/tag/TagsInput.js b/components/tag/TagsInput.js index 4271c17ba25..5741abb1779 100644 --- a/components/tag/TagsInput.js +++ b/components/tag/TagsInput.js @@ -1,19 +1,40 @@ import XMarkIcon from "@heroicons/react/20/solid/XMarkIcon"; import Input from "../form/Input"; +import Notification from "@components/Notification"; -export default function TagsInput({ tags, onTagAdd, onTagRemove, inputRef }) { - - +export default function TagsInput({ + tags, + onTagAdd, + onTagRemove, + inputRef, + showNotification, + setShowNotification, +}) { //key code const { comma, backspace, enter } = { comma: 188, backspace: 8, enter: 13, }; - + const maxLength = 32; const handleKeyUp = (e) => { const inputValue = inputRef.current.value; - if (e.keyCode === comma || inputValue.endsWith(",") || e.keyCode === enter) { + if (inputValue.length >= maxLength && e.keyCode !== backspace) { + // '=' sign because in 32 char ',' sign does't count + setShowNotification({ + show: true, + type: "error", + message: "Tag", + additionalMessage: "Tag limit exceeded", + }); + return; + } + + if ( + e.keyCode === comma || + inputValue.endsWith(",") || + e.keyCode === enter + ) { const newTag = inputValue.trim().replace(/,/g, ""); if (!newTag) { return; @@ -57,6 +78,15 @@ export default function TagsInput({ tags, onTagAdd, onTagRemove, inputRef }) { return ( <> + + setShowNotification({ ...showNotification, show: false }) + } + message={showNotification.message} + additionalMessage={showNotification.additionalMessage} + />