From 7e5d276b7837c8d519e38d5bdf0fc45f86d93e72 Mon Sep 17 00:00:00 2001 From: devesh saini Date: Sat, 8 Nov 2025 19:06:31 +0530 Subject: [PATCH] added character limit on comments --- src/components/comment/CommentInputForm.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/comment/CommentInputForm.tsx b/src/components/comment/CommentInputForm.tsx index 753ce7525..ca5b26452 100644 --- a/src/components/comment/CommentInputForm.tsx +++ b/src/components/comment/CommentInputForm.tsx @@ -7,6 +7,8 @@ import { toast } from 'sonner'; import { FormErrors } from '../FormError'; import { usePathname } from 'next/navigation'; +const maxCommentLength = 400; + const CommentInputForm = ({ contentId, parentId = undefined, @@ -108,10 +110,18 @@ const CommentInputForm = ({ className="w-full resize-none border-b border-primary/25 bg-transparent p-4 focus:outline-none focus:ring-0" placeholder={parentId ? 'Add a reply...' : 'Add a comment...'} onChange={(e) => { - adjustTextareaHeight(); - setCommentText(e.target.value); + const currentText = e.target.value; + if(currentText<=maxCommentLength){ + adjustTextareaHeight(); + setCommentText(e.target.value); + } + }} // Adjust height on text change + /> +

+ {commentText.length}/{maxCommentLength} +