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

💥 395: add new required variable id to all form fields to ensure a11y #396

Merged
merged 4 commits into from
Jan 22, 2025

Conversation

lehju
Copy link
Contributor

@lehju lehju commented Jan 21, 2025

Description

Add ids to form fields so that the screen reader can access the labels and hints.

Reference

closes #395

Summary by CodeRabbit

  • New Features

    • Added unique id attributes to form components (Checkbox, Input, Radio Button, Select, TextArea) to improve accessibility and component identification.
  • Accessibility Improvements

    • Enhanced form components with dynamic id bindings
    • Improved label-input associations
    • Added aria-describedby attributes for better screen reader support

@lehju lehju added the Accessibility Improvements or additions to improve use by people with disabilities label Jan 21, 2025
@lehju lehju requested a review from FabianWilms January 21, 2025 15:24
@lehju lehju self-assigned this Jan 21, 2025
Copy link
Contributor

coderabbitai bot commented Jan 21, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The pull request focuses on enhancing the accessibility of form components across multiple Vue files. By introducing a new id prop to various form components like Checkbox, Input, Radio Button, Select, and TextArea, the changes improve the semantic HTML structure. The modifications ensure that labels, inputs, and hints are correctly associated, making the components more screen reader-friendly and improving overall user interaction.

Changes

File Change Summary
src/components/Form/*.stories.ts Added id property to story exports for Checkbox, Input, Select, TextArea, and RadioButton
src/components/Form/*.vue Updated components to dynamically use id prop for input, label, and hint elements

Assessment against linked issues

Objective Addressed Explanation
Add tabindex and aria-labels
Improve screen reader compatibility

Possibly related PRs

Suggested reviewers

  • FabianWilms
  • langehm

Poem

🌟 Accessibility's sweet embrace,
IDs dancing with label's grace,
Screen readers sing with delight,
Components now shine ever so bright!
A11y magic, code's tender care 🌈


🪧 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.

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.

@lehju
Copy link
Contributor Author

lehju commented Jan 21, 2025

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Jan 21, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@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 (10)
src/components/Form/MucTextArea.stories.ts (1)

26-31: Consider renaming the 'Error' story to avoid shadowing

Thank you for implementing the error state story! To make the code even better, would you consider renaming this story to something like WithError or ErrorState? This would prevent shadowing the global Error property and make the code more maintainable.

Here's a suggested change:

-export const Error = {
+export const WithError = {
   args: {
     ...Default.args,
     id: "error",
     errorMsg: "An error occured",
   },
 };
🧰 Tools
🪛 Biome (1.9.4)

[error] 26-26: Do not shadow the global "Error" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)

src/components/Form/MucTextArea.vue (3)

23-25: Consider conditionally applying aria-describedby 🤔

Thank you for adding the accessibility attributes! One small suggestion to make it even better: consider conditionally applying the aria-describedby attribute only when a hint exists.

Here's how you could improve it:

  <textarea
    :id="'textarea-' + id"
    class="m-textarea"
-   :aria-describedby="'textarea-hint-' + id"
+   :aria-describedby="hint ? 'textarea-hint-' + id : undefined"
    :rows="rows"
    :placeholder="placeholder"
    v-model="modelValue"
  />

31-34: Great addition of keyboard accessibility! Here's a suggestion to make it even better 🌟

Thank you for making the error message focusable! To make it even more accessible, consider adding role="alert" and aria-live="polite" to ensure screen readers announce the error when it appears.

Here's the suggested enhancement:

  <form-error-message
    v-if="errorMsg"
    tabindex="0"
+   role="alert"
+   aria-live="polite"
  >
    {{ errorMsg }}
  </form-error-message>

53-56: Thank you for documenting the new prop! Here's a suggestion to make it even clearer 📝

The JSDoc comment for the id prop could be more descriptive to help other developers understand its purpose and importance for accessibility.

Here's a suggested enhancement:

  /**
-  * id of textarea
+  * Unique identifier for the textarea. Used to associate the textarea with its label and hint text for accessibility.
   */
  id: string;
src/components/Form/MucCheckbox.stories.ts (1)

23-23: Thank you for adding the ID! Consider making it more specific.

While adding an ID is great for accessibility, using "default" might be too generic if multiple checkboxes are rendered on the same page. Consider using a more descriptive ID that reflects the checkbox's purpose, like "terms-acceptance" or "newsletter-signup".

-    id: "default",
+    id: "checkbox-story-default",
src/components/Form/MucCheckbox.vue (1)

7-7: Wonderful implementation of accessible checkboxes! 🌟

Great job on implementing the ID prop and correctly associating the label with the input element. The documentation is clear, and the 'checkbox-' prefix helps prevent ID collisions.

One small suggestion to make this even better:

Consider adding prop validation to ensure the ID is always provided and follows a valid format:

 const { label } = defineProps<{
   /**
    * id of checkbox
    */
-  id: string;
+  id: {
+    type: String,
+    required: true,
+    validator: (value: string) => /^[a-zA-Z][\w-]*$/.test(value)
+  };
   /**
    * Label is displayed to the right of the checkbox as information for the user.
    */
   label: string;
 }>();

Also applies to: 14-17, 29-33

src/components/Form/MucCheckboxGroup.stories.ts (1)

25-25: Consider using more descriptive IDs for better accessibility

Thank you for adding IDs to improve accessibility! However, using just the index number as an ID might not be descriptive enough for screen readers. Consider using a more descriptive format similar to the Collapsable story.

-           <MucCheckbox v-for="index in 4" :key="index" :label="'not-collapsed-' + index" :id="index"/>
+           <MucCheckbox v-for="index in 4" :key="index" :label="'not-collapsed-' + index" :id="'not-collapsed-' + index"/>
src/components/Form/MucInput.stories.ts (1)

88-92: Consider renaming the Date story to avoid shadowing

To prevent potential confusion with the global Date object, consider using a more specific name.

-export const Date = {
+export const DateInput = {
   args: {
     id: "date",
     type: "date",
   },
 };
🧰 Tools
🪛 Biome (1.9.4)

[error] 88-88: Do not shadow the global "Date" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)

src/components/Form/MucSelect.vue (2)

Line range hint 32-44: Consider enhancing trigger button accessibility

The trigger button could benefit from additional accessibility attributes:

 <span
   class="m-input__trigger"
   @click="toggleItemList"
+  role="button"
+  :aria-expanded="showItems"
+  :aria-label="'Toggle ' + (label || 'select') + ' dropdown'"
 >

This would:

  • Properly identify it as a button for screen readers
  • Indicate its expanded/collapsed state
  • Provide clear context about its purpose

121-124: Consider enhancing the id prop documentation and validation

Thank you for adding the id prop! To make it even more robust, consider:

 /**
  * id of select
+ * @remarks Must be unique across the page to ensure proper accessibility
  */
-id: string;
+id: {
+  type: String,
+  required: true,
+  validator: (value: string) => value.trim().length > 0
+}

This would:

  • Enforce non-empty strings
  • Clarify the uniqueness requirement
  • Maintain type safety
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 351868f and de45ab0.

📒 Files selected for processing (11)
  • src/components/Form/MucCheckbox.stories.ts (1 hunks)
  • src/components/Form/MucCheckbox.vue (2 hunks)
  • src/components/Form/MucCheckboxGroup.stories.ts (2 hunks)
  • src/components/Form/MucInput.stories.ts (4 hunks)
  • src/components/Form/MucInput.vue (4 hunks)
  • src/components/Form/MucRadioButton.stories.ts (1 hunks)
  • src/components/Form/MucRadioButton.vue (2 hunks)
  • src/components/Form/MucSelect.stories.ts (2 hunks)
  • src/components/Form/MucSelect.vue (3 hunks)
  • src/components/Form/MucTextArea.stories.ts (2 hunks)
  • src/components/Form/MucTextArea.vue (2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/components/Form/MucTextArea.stories.ts

[error] 26-26: Do not shadow the global "Error" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)

src/components/Form/MucInput.stories.ts

[error] 88-88: Do not shadow the global "Date" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)

🔇 Additional comments (15)
src/components/Form/MucTextArea.stories.ts (1)

21-21: Thank you for adding unique IDs to improve accessibility! 🎉

The addition of descriptive IDs for each story variant is a great improvement for accessibility. These IDs will help ensure proper association between labels, inputs, and hints for screen readers.

Also applies to: 29-29, 38-38, 46-46

src/components/Form/MucTextArea.vue (2)

8-8: Thank you for improving label accessibility! 🎉

The dynamic binding of the label's for attribute to the textarea ID is a great accessibility enhancement. This ensures proper association between the label and textarea, making it easier for screen readers to announce the label when the textarea receives focus.


14-18: Excellent work on the hint implementation! 💫

Great improvements here:

  1. The v-if="hint" prevents empty hint elements from being rendered
  2. The unique ID enables proper association with the textarea via aria-describedby

This makes the component more semantic and screen-reader friendly.

src/components/Form/MucRadioButton.stories.ts (1)

27-28: Excellent work on the radio button IDs! 👏

Great implementation of unique IDs for both the static and dynamically generated radio buttons. This will significantly improve the screen reader experience.

src/components/Form/MucSelect.stories.ts (1)

21-21: Great work on providing unique IDs for each select variant! ✨

I appreciate how you've given each select component a unique, purpose-describing ID. This is exactly what we need for proper accessibility support.

Also applies to: 58-58, 66-66

src/components/Form/MucCheckboxGroup.stories.ts (1)

36-40: Great job on descriptive IDs! 👍

The IDs in the Collapsable story are well-structured and descriptive, making it clear which checkboxes belong to which section. This is excellent for accessibility!

src/components/Form/MucRadioButton.vue (2)

7-24: Excellent accessibility implementation! 🎉

Really appreciate the thorough implementation of accessibility features:

  • Proper label association using for attribute
  • ARIA description linking with aria-describedby
  • Consistent ID prefixing pattern with 'radio-'

37-40: Well-documented prop definition

Thank you for adding clear documentation for the new id prop. This helps other developers understand its purpose and importance.

src/components/Form/MucInput.stories.ts (1)

Line range hint 23-99: Great work on unique, descriptive IDs! 🌟

Really appreciate how each story variant has a meaningful, context-specific ID. This makes the stories more accessible and easier to test.

🧰 Tools
🪛 Biome (1.9.4)

[error] 88-88: Do not shadow the global "Date" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)

src/components/Form/MucInput.vue (3)

Line range hint 8-38: Comprehensive accessibility implementation! 🎯

Excellent work on implementing all the necessary accessibility features:

  • Proper label association with for attribute
  • Unique IDs for input and hint elements
  • ARIA description linking with aria-describedby

69-69: Good addition of keyboard accessibility

Thank you for making the error message keyboard-focusable with tabindex="0". This ensures that keyboard users can access error messages easily.


102-105: Clear prop documentation

Appreciate the clear documentation for the new id prop. This helps maintain code quality and helps other developers understand its purpose.

src/components/Form/MucSelect.vue (3)

6-10: Great job on implementing proper label-input association! 🎉

The label is correctly associated with the input using the for attribute, which is essential for accessibility. The dynamic ID generation using 'select-' + id ensures uniqueness.


14-16: Well done on implementing hint text accessibility! 👏

The hint text is properly associated with the input using a unique ID, which will help screen reader users understand the input's purpose.


25-25: Perfect implementation of input accessibility attributes! ✨

The input element correctly uses both:

  • Unique ID matching the label's for attribute
  • aria-describedby linking to the hint text

Also applies to: 28-28

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 21, 2025
@FabianWilms
Copy link
Member

rest is looking good!

@lehju lehju merged commit 1b5ddee into beta Jan 22, 2025
8 checks passed
@lehju lehju deleted the 395-form-components-accessibility branch January 22, 2025 07:26
Copy link

🎉 This PR is included in version 3.0.0-beta.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accessibility Improvements or additions to improve use by people with disabilities released on @beta
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Form components accessibility
2 participants