@@ -56,6 +56,8 @@ export function DocsHelp({
5656 const [ feedbackStatus , setFeedbackStatus ] = useState ( '' ) ;
5757 const [ isSubmitting , setIsSubmitting ] = useState ( false ) ;
5858 const [ error , setError ] = useState ( '' ) ;
59+ const [ commentValue , setCommentValue ] = useState ( '' ) ;
60+ const [ commentError , setCommentError ] = useState ( false ) ;
5961 const feedbackFormRef = useRef < HTMLFormElement > ( null ) ;
6062
6163 // Generate GitHub redirect URL
@@ -85,6 +87,13 @@ export function DocsHelp({
8587
8688 async function createFeedbackHandler ( event : FormEvent ) {
8789 event . preventDefault ( ) ;
90+
91+ // Validate comment is not empty
92+ if ( ! commentValue . trim ( ) ) {
93+ setCommentError ( true ) ;
94+ return ;
95+ }
96+
8897 const formData = new FormData ( feedbackFormRef . current ! ) ;
8998 formData . append ( 'feedback-page' , router . asPath ) ;
9099 setIsSubmitting ( true ) ;
@@ -99,7 +108,7 @@ export function DocsHelp({
99108 body : JSON . stringify ( {
100109 feedbackPage : formData . get ( 'feedback-page' ) ,
101110 feedbackVote : formData . get ( 'feedback-vote' ) ,
102- feedbackComment : formData . get ( 'feedback-comment' ) ,
111+ feedbackComment : commentValue ,
103112 } ) ,
104113 } ,
105114 ) ;
@@ -117,11 +126,17 @@ export function DocsHelp({
117126 }
118127
119128 const createGitHubIssueHandler = ( ) => {
129+ // Validate comment is not empty
130+ if ( ! commentValue . trim ( ) ) {
131+ setCommentError ( true ) ;
132+ return ;
133+ }
134+
120135 const formData = new FormData ( feedbackFormRef . current ! ) ;
121136 setIsSubmitting ( true ) ;
122137 try {
123138 const title = encodeURIComponent ( 'Feedback on Documentation' ) ;
124- const body = encodeURIComponent ( `${ formData . get ( 'feedback-comment' ) } ` ) ;
139+ const body = encodeURIComponent ( `${ commentValue } ` ) ;
125140 const url = `https://github.com/json-schema-org/website/issues/new?title=${ title } &body=${ body } ` ;
126141 window . open ( url , '_blank' ) ;
127142 submitFeedbackHandler ( 'github_issue' ) ;
@@ -136,6 +151,8 @@ export function DocsHelp({
136151 setIsFormOpen ( false ) ;
137152 setFeedbackStatus ( status ) ;
138153 setError ( '' ) ;
154+ setCommentValue ( '' ) ;
155+ setCommentError ( false ) ;
139156 feedbackFormRef . current ! . reset ( ) ;
140157 } ;
141158
@@ -237,16 +254,29 @@ export function DocsHelp({
237254 Let us know your Feedback
238255 </ span >
239256 < span className = 'float-right text-[#7d8590] text-[14px] block' >
240- Optional
257+ Required
241258 </ span >
242259 </ label >
243260 </ p >
244261 < Textarea
245- className = ' py-2 text-[14px] min-h-[28px] px-[12px] align-middle border border-solid border-[#aaaaaa] rounded-md w-full overflow-hidden'
262+ className = { ` py-2 text-[14px] min-h-[28px] px-[12px] align-middle border border-solid ${ commentError ? ' border-red-500 focus:border-red-500' : 'border- [#aaaaaa]' } rounded-md w-full overflow-hidden` }
246263 name = 'feedback-comment'
247264 id = 'feedback-comment'
248265 data-test = 'feedback-form-input'
266+ value = { commentValue }
267+ onChange = { ( e ) => {
268+ setCommentValue ( e . target . value ) ;
269+ if ( e . target . value . trim ( ) ) {
270+ setCommentError ( false ) ;
271+ }
272+ } }
273+ required
249274 />
275+ { commentError && (
276+ < p className = 'text-red-500 text-[12px] mt-1' >
277+ Please provide feedback before submitting
278+ </ p >
279+ ) }
250280 </ div >
251281
252282 < div className = 'flex justify-start items-center mt-1 text-[14px]' >
0 commit comments