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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ihab4real
Copy link

@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

  • New Features

    • Enhanced accessibility for the comment submission forms by adding aria-label attributes and linking labels to inputs.
    • Marked author name and comment text fields as mandatory with aria-required="true".
  • Bug Fixes

    • Improved usability by ensuring proper association between labels and input fields.

These changes ensure a more inclusive experience for users utilizing assistive technologies.

Copy link

coderabbitai bot commented Nov 11, 2024

Walkthrough

The changes in this pull request involve modifications to the HorizontalForm, InlineForm, and StackedForm components within the CommentForm module. The primary focus is on enhancing accessibility by adding aria-label attributes to the form elements and inputs, ensuring they are properly labeled for screen readers. Additional updates include the introduction of htmlFor attributes in label elements to associate them with their respective input fields, and the removal of unnecessary onSubmit attributes from input elements, as form submission is handled at the form level.

Changes

File Path Change Summary
client/app/bundles/comments/rescript/CommentForm/forms/HorizontalForm.res Added aria-label to form and inputs; included aria-required attributes; updated label elements with htmlFor attributes; modified submit button with aria-label.
client/app/bundles/comments/rescript/CommentForm/forms/InlineForm.res Added aria-label to form and inputs; included aria-required attributes; updated label elements with htmlFor attributes; modified submit button with aria-label; removed onSubmit from input.
client/app/bundles/comments/rescript/CommentForm/forms/StackedFrom.res Added aria-label to form and inputs; included aria-required attributes; updated label elements with htmlFor attributes; modified submit button with aria-label; removed onSubmit from input.

Poem

🐰 In a form where comments flow,
Labels now help readers know.
With aria tags, they find their way,
To share their thoughts without delay.
A hop, a click, the comments bloom,
Accessibility makes room! 🌸


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

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

📒 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)
🚧 Files skipped from review as they are similar to previous changes (3)
  • client/app/bundles/comments/rescript/CommentForm/forms/HorizontalForm.res
  • client/app/bundles/comments/rescript/CommentForm/forms/InlineForm.res
  • client/app/bundles/comments/rescript/CommentForm/forms/StackedFrom.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 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.
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.

1 participant