Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance comment forms #604

Merged
merged 7 commits into from
Jan 15, 2025
Merged

Conversation

ihab4real
Copy link
Collaborator

@ihab4real ihab4real commented Nov 11, 2024

This PR improves the form components in the ReScript implementation by addressing several issues:

  • StackedForm component has both fields labeled "Author", when the second field is for the comment Text and not author. it's correctly specified in the other form components.
  • Fixes potential double-submission edge case: remove the onSubmit attribute in submit buttons as it's already specified in the form itself.
  • form accessibility: added htmlFor and aria attributes.

This change is Reviewable

Summary by CodeRabbit

  • Accessibility Improvements

    • Enhanced form accessibility across comment submission forms
    • Added ariaLabel attributes to form elements, inputs, and submit buttons
    • Improved label-input associations with htmlFor attributes
    • Marked required fields with ariaRequired
  • Bug Fixes

    • Corrected component name from StackedFrom to StackedForm
    • Updated disabled attribute syntax for accuracy

Copy link

coderabbitai bot commented Nov 11, 2024

Walkthrough

This pull request focuses on enhancing the accessibility and correctness of comment form components across different form types (Horizontal, Inline, and Stacked) in the comments module. The changes involve adding ARIA attributes to form elements, correcting label-input associations, and fixing a component rendering typo in the main CommentForm component. These modifications improve screen reader compatibility and ensure proper form interaction without altering the core functionality of the forms.

Changes

File Change Summary
client/app/bundles/comments/rescript/CommentForm/CommentForm.res Corrected component rendering by changing <StackedFrom> to <StackedForm>
client/app/bundles/comments/rescript/CommentForm/forms/HorizontalForm.res Added ARIA labels and attributes to improve form accessibility
client/app/bundles/comments/rescript/CommentForm/forms/InlineForm.res Enhanced form accessibility with ARIA labels, corrected disabled attribute syntax
client/app/bundles/comments/rescript/CommentForm/forms/StackedForm.res Improved form accessibility with ARIA attributes and corrected input handling

Possibly related PRs

  • Upgrade to react 19 #610: The changes in the CommentForm component in CommentForm.jsx involve updates to input handling and references, which may relate to the accessibility enhancements made in the HorizontalForm and InlineForm components in the main PR.

Poem

🐰 A Rabbit's Ode to Accessible Forms 🐰

With labels clear and ARIA's might,
Our forms now shine so crisp and bright.
No screen reader left behind today,
Inputs dance in their accessible way.
Accessibility, our coding delight! 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f4cbe25 and 64248fd.

📒 Files selected for processing (4)
  • client/app/bundles/comments/rescript/CommentForm/CommentForm.res (1 hunks)
  • client/app/bundles/comments/rescript/CommentForm/forms/HorizontalForm.res (4 hunks)
  • client/app/bundles/comments/rescript/CommentForm/forms/InlineForm.res (3 hunks)
  • client/app/bundles/comments/rescript/CommentForm/forms/StackedForm.res (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • client/app/bundles/comments/rescript/CommentForm/forms/HorizontalForm.res
  • client/app/bundles/comments/rescript/CommentForm/CommentForm.res
  • client/app/bundles/comments/rescript/CommentForm/forms/InlineForm.res
  • client/app/bundles/comments/rescript/CommentForm/forms/StackedForm.res

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (4)
client/app/bundles/comments/rescript/CommentForm/forms/InlineForm.res (1)

37-42: Consider using a button element instead of input type="submit"

While the current implementation works, using a button element with type="submit" is considered better practice for form submissions. It offers better styling flexibility and semantic meaning.

Here's the suggested change:

-      <input
-        type_="submit"
+      <button
+        type_="submit"
         className="self-start px-3 py-1 font-semibold border-0 rounded text-sky-50 bg-sky-600 hover:bg-sky-800"
-        value="Post"
         aria-label="Submit comment"
-      />
+      >
+        {"Post"->React.string}
+      </button>
client/app/bundles/comments/rescript/CommentForm/forms/StackedFrom.res (1)

19-19: Consider a more descriptive label for the comment field

While the accessibility improvements are good, consider changing the label from "Text" to "Comment" or "Comment Text" to be more descriptive of the field's purpose.

-      <label htmlFor="comment_text" className="w-full"> {"Text"->React.string} </label>
+      <label htmlFor="comment_text" className="w-full"> {"Comment"->React.string} </label>

Also applies to: 28-29

client/app/bundles/comments/rescript/CommentForm/forms/HorizontalForm.res (2)

5-5: LGTM! Author field accessibility is well implemented.

Good implementation of label-input association and aria attributes. Consider adding an asterisk (*) to visually indicate the required field, matching the aria-required state.

-      <label htmlFor="comment_author" className="w-full lg:w-2/12 lg:text-end shrink-0"> {"Name"->React.string} </label>
+      <label htmlFor="comment_author" className="w-full lg:w-2/12 lg:text-end shrink-0"> {"Name *"->React.string} </label>

Also applies to: 14-15


38-38: Consider using button element instead of input type="submit".

While the aria-label addition is good, consider using a button element which is more semantic and provides better styling options.

-      <input
-        type_="submit"
-        className="self-start px-3 py-1 font-semibold border-0 rounded text-sky-50 bg-sky-600 hover:bg-sky-800"
-        value="Post"
-        aria-label="Submit comment"
-      />
+      <button
+        type_="submit"
+        className="self-start px-3 py-1 font-semibold border-0 rounded text-sky-50 bg-sky-600 hover:bg-sky-800"
+        aria-label="Submit comment"
+      >
+        {"Post"->React.string}
+      </button>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3e1f722 and b531492.

📒 Files selected for processing (3)
  • client/app/bundles/comments/rescript/CommentForm/forms/HorizontalForm.res (4 hunks)
  • client/app/bundles/comments/rescript/CommentForm/forms/InlineForm.res (3 hunks)
  • client/app/bundles/comments/rescript/CommentForm/forms/StackedFrom.res (3 hunks)
🔇 Additional comments (6)
client/app/bundles/comments/rescript/CommentForm/forms/InlineForm.res (2)

9-9: LGTM! Good accessibility implementation

The label and input are properly associated using htmlFor/id, and the aria attributes enhance screen reader support.

Also applies to: 18-19


23-23: LGTM! Consistent accessibility implementation

The comment text field follows the same good accessibility patterns as the author field.

Also applies to: 32-33

client/app/bundles/comments/rescript/CommentForm/forms/StackedFrom.res (3)

3-3: LGTM! Form accessibility enhancement

The addition of aria-label improves accessibility, and handling submission at the form level prevents potential double submissions.


5-5: LGTM! Author field accessibility improvements

The changes properly associate the label with the input field and add necessary ARIA attributes for screen readers.

Also applies to: 14-15


37-37: LGTM! Submit button accessibility enhancement

The addition of aria-label improves the button's accessibility, and handling submission at the form level prevents potential double submissions.

client/app/bundles/comments/rescript/CommentForm/forms/HorizontalForm.res (1)

3-3: LGTM! Form accessibility enhancement is well implemented.

The addition of aria-label on the form element improves screen reader context, and handling submission at the form level is the correct approach.

/>
</div>
<div className="flex flex-col gap-0 items-center lg:gap-4 lg:flex-row">
<label className="w-full lg:w-2/12 lg:text-end shrink-0"> {"Text"->React.string} </label>
<label htmlFor="comment_text" className="w-full lg:w-2/12 lg:text-end shrink-0"> {"Text"->React.string} </label>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider using textarea for comment input.

While the accessibility improvements are great, a textarea would be more appropriate for comment text as it:

  1. Allows multiline input
  2. Provides better UX for markdown content
  3. Is semantically more correct for longer text input
-      <input
-        type_="text"
+      <textarea
         className="px-3 py-1 leading-4 border border-gray-300 rounded w-full"
         placeholder="Say something using markdown..."
         name="comment_text"
         id="comment_text"
         onChange=handleTextChange
         value={text}
         aria-label="Comment text"
-        aria-required="true"
+        aria-required="true"
+        rows=3
-      />
+      />

Also applies to: 28-29

The disabled prop is incorrectly passed without a value. In ReScript, boolean props need to be explicitly set.
- Use camelCase for aria attributes (ariaLabel, ariaRequired)
- Use boolean `true` instead of string "true" for ariaRequired
- Fix htmlFor placement inside label tags
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
client/app/bundles/comments/rescript/CommentForm/forms/StackedForm.res (3)

9-9: Consider enhancing the author input accessibility further.

While the current accessibility improvements are good, consider adding these additional attributes for better screen reader support:

 <input
   type_="text"
   className="px-3 py-1 leading-4 border border-gray-300 rounded w-full"
   placeholder="Your Name"
   name="comment_author"
   id="comment_author"
   onChange=handleAuthorChange
   value={author}
   ariaLabel="Author name"
   ariaRequired=true
+  role="textbox"
+  ariaInvalid={author->Js.String2.length == 0}
 />

Also applies to: 18-19


23-23: Consider enhancing the comment text input accessibility further.

Similar to the author input, consider adding additional accessibility attributes:

 <input
   type_="text"
   className="px-3 py-1 leading-4 border border-gray-300 rounded w-full"
   placeholder="Say something using markdown..."
   name="comment_text"
   id="comment_text"
   onChange=handleTextChange
   value={text}
   ariaLabel="Comment text"
   ariaRequired=true
+  role="textbox"
+  ariaInvalid={text->Js.String2.length == 0}
 />

Also applies to: 32-33


41-41: Consider enhancing the submit button accessibility.

The submit button could benefit from additional accessibility attributes:

 <input
   type_="submit"
   className="self-start px-3 py-1 font-semibold border-0 rounded text-sky-50 bg-sky-600 hover:bg-sky-800"
   value="Post"
   ariaLabel="Submit comment"
+  role="button"
+  ariaDisabled={disabled}
 />
client/app/bundles/comments/rescript/CommentForm/CommentForm.res (1)

Line range hint 1-149: Consider enhancing form state management for better accessibility.

While the current implementation handles basic form states well, consider adding form validation state to improve accessibility feedback:

  1. Add validation state to track empty required fields
  2. Pass validation state to form components to set ariaInvalid appropriately
  3. Add error messages for screen readers

Example enhancement:

 type state = {
   author: string,
   text: string,
   form: formDisplay,
   savingStatus: savingStatus,
+  validationErrors: array<string>,
 }

 type action =
   | SetAuthor(string)
   | SetText(string)
   | SetFormType(formDisplay)
   | SetSavingError
   | ClearSavingError
   | SetStoreStatusSaving
+  | SetValidationErrors(array<string>)

 let reducer = (state: state, action: action): state => {
   switch action {
   | SetAuthor(author) => {
       ...state,
       author,
+      validationErrors: validateForm({...state, author}),
     }
   | SetText(text) => {
       ...state,
       text,
+      validationErrors: validateForm({...state, text}),
     }
   // ... other cases
   }
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4e95686 and f4cbe25.

📒 Files selected for processing (4)
  • client/app/bundles/comments/rescript/CommentForm/CommentForm.res (2 hunks)
  • client/app/bundles/comments/rescript/CommentForm/forms/HorizontalForm.res (4 hunks)
  • client/app/bundles/comments/rescript/CommentForm/forms/InlineForm.res (3 hunks)
  • client/app/bundles/comments/rescript/CommentForm/forms/StackedForm.res (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • client/app/bundles/comments/rescript/CommentForm/forms/HorizontalForm.res
  • client/app/bundles/comments/rescript/CommentForm/forms/InlineForm.res
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: test (22.x, 3.3.3)
  • GitHub Check: test (22.x, 3.3.3)
  • GitHub Check: test (22.x, 3.3.3)
🔇 Additional comments (2)
client/app/bundles/comments/rescript/CommentForm/forms/StackedForm.res (1)

3-7: LGTM! Form element accessibility improvements.

Good addition of ariaLabel and proper disabled attribute syntax. The form structure with flex layout provides a clean user interface.

client/app/bundles/comments/rescript/CommentForm/CommentForm.res (1)

Line range hint 125-132: LGTM! Correct component name usage.

The component name has been properly corrected from StackedFrom to StackedForm, ensuring proper component rendering.

Copy link
Contributor

@Judahmeek Judahmeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs one minor change before merge.

@Judahmeek Judahmeek merged commit 1a13c23 into shakacode:master Jan 15, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants