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

fix(radio): [radio] fix using aria-hidden="true" on focusable elements #2265

Merged
merged 2 commits into from
Oct 16, 2024

Conversation

zzcr
Copy link
Member

@zzcr zzcr commented Oct 15, 2024

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • Accessibility Improvements
    • Removed aria-hidden="true" from the radio input, enhancing accessibility for assistive technologies.
  • Test Enhancements
    • Updated radio button selection methods in tests to improve specificity and reliability using label filters instead of roles.

Copy link

coderabbitai bot commented Oct 15, 2024

Walkthrough

The pull request modifies the pc.vue file in the packages/vue/src/radio/src directory by removing the aria-hidden="true" attribute from the <input> element of type radio. This change impacts the accessibility of the radio input, affecting how assistive technologies perceive its visibility. The rest of the component's structure, including the template and script sections, remains unchanged. Additionally, several test files have been updated to change the method of selecting radio buttons, enhancing the specificity of the locators used in Playwright tests.

Changes

File Path Change Summary
packages/vue/src/radio/src/pc.vue Removed aria-hidden="true" from the <input> element of type radio.
examples/sites/demos/pc/app/radio/default-slot.spec.ts Updated radio button selection from getByRole to locator with filters for specific label text.
examples/sites/demos/pc/app/radio/group-options.spec.ts Introduced demo locator for #group-options element, refining access to radio buttons and labels.
examples/sites/demos/pc/app/radio/radio-events.spec.ts Changed radio button selection from getByRole to locator with filters based on label text.

Possibly related PRs

Poem

In the meadow where bunnies play,
A radio button found its way.
With aria-hidden now set free,
It hops to help, as it should be!
Accessibility's the joyful tune,
For every bunny, morning to noon! 🐇✨


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.

@github-actions github-actions bot added the bug Something isn't working label Oct 15, 2024
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 (2)
examples/sites/demos/pc/app/radio/radio-events.spec.ts (1)

13-13: Consistent improvement, but consider removing .first()

The change here is consistent with the previous one, which is good for maintainability. However, the use of .first() raises a potential concern:

  1. It suggests there might be multiple elements matching the filter.
  2. Relying on the order of elements can make tests less reliable if the UI structure changes.

Consider making the selector more specific to avoid needing .first(). For example, you could include a parent element's selector if these radio buttons are in different sections.

If possible, try to make the selector unique without relying on .first(). For example:

await demo.locator('specific-parent-selector label').filter({ hasText: '月度' }).click()

This would make the test more robust against potential UI changes.

examples/sites/demos/pc/app/radio/group-options.spec.ts (1)

7-10: Refined radio button and label locators.

The updates to use the demo locator for selecting radio buttons and labels are consistent and improve test specificity. This change maintains existing functionality while reducing the risk of selecting unintended elements.

Consider using more specific selectors (e.g., data-testid attributes) instead of relying on element order with nth(). This could make the tests more resilient to changes in the component's structure.

Example:

const radio1 = demo.locator('[data-testid="radio-1"]')
const radio2 = demo.locator('[data-testid="radio-2"]')
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 04557da and f66850a.

📒 Files selected for processing (3)
  • examples/sites/demos/pc/app/radio/default-slot.spec.ts (1 hunks)
  • examples/sites/demos/pc/app/radio/group-options.spec.ts (1 hunks)
  • examples/sites/demos/pc/app/radio/radio-events.spec.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (4)
examples/sites/demos/pc/app/radio/radio-events.spec.ts (1)

8-9: Improved radio button selection method

The change from getByRole to locator('label').filter({ hasText: '选项二' }) is a good improvement. This new approach:

  1. Is more specific, reducing the risk of selecting the wrong element.
  2. Better mimics user behavior by targeting the label, which is what users typically click.
  3. Is less dependent on the exact role implementation, making the test more robust.
examples/sites/demos/pc/app/radio/group-options.spec.ts (3)

6-6: Improved test specificity with demo locator.

The introduction of the demo locator targeting #group-options is a good practice. It enhances the test's robustness by scoping subsequent actions to a specific demo area, reducing the risk of interacting with unintended elements if the page structure changes.


14-14: Improved radio button selection method.

The updated method for clicking the radio button labeled '一般' is a significant improvement. Using demo.locator('label').filter({ hasText: '一般' }).click() is more robust and less prone to breaking if the order of elements changes. This approach directly targets the desired element based on its text content, which is closer to how a user would interact with the interface.


6-14: Overall improvement in test reliability and maintainability.

The changes made to this test file consistently enhance its specificity and robustness. By introducing the demo locator and refining the selection methods for radio buttons and labels, the test becomes more resilient to potential changes in the page structure. These improvements align well with best practices in test automation, making the test more reliable and easier to maintain in the long run.

Comment on lines +8 to +9
const radio1 = demo.locator('label').filter({ hasText: '内容一:选项描述' })
const radio2 = demo.locator('label').filter({ hasText: '内容二:选项描述' })
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 the trade-offs of the new selector approach

The change from using getByRole (assumed from the PR context) to locator().filter() for selecting radio buttons has both advantages and potential drawbacks:

Advantages:

  1. This approach is less dependent on ARIA roles, which aligns with the PR's objective of fixing issues related to aria-hidden="true" on focusable elements.
  2. It provides more specific selection of elements, potentially reducing false positives in tests.

Potential drawbacks:

  1. The test might become more brittle if the exact text of the labels changes frequently, as it now depends on the specific content of the labels.
  2. This approach might be less accessible-friendly as it doesn't rely on ARIA roles, which are important for accessibility testing.

Consider the following suggestions:

  1. If possible, use data attributes for test selection to make the tests more robust and less dependent on text content.
  2. Document the reason for this change in a comment to provide context for future maintainers.
  3. Ensure that this change doesn't negatively impact the accessibility testing capabilities of your test suite.

Here's a potential improvement using data attributes:

const radio1 = demo.locator('[data-testid="radio-option-1"]')
const radio2 = demo.locator('[data-testid="radio-option-2"]')

This approach would require adding data-testid attributes to your radio button elements in the component, but it would make the tests more robust and easier to maintain.


💡 Codebase verification

Issues Found: aria-hidden="true" is still present in the radio component files

  • packages/vue/src/radio/src/mobile-first.vue
  • packages/vue/src/radio/src/mobile.vue

These elements remain hidden from assistive technologies despite the PR's objective to address aria-hidden="true" usage on focusable elements.

🔗 Analysis chain

Please provide more context on the relationship to the PR objective

While these changes appear to be related to the PR's objective of fixing issues with aria-hidden="true" on focusable elements, the connection is not immediately clear from this file alone. Could you please provide more context on how these test changes relate to the accessibility improvements mentioned in the PR title?

This additional information would help reviewers better understand the full scope and impact of the changes across the codebase.

To gain more context, let's examine the changes in the radio component:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for changes in the radio component related to aria-hidden

# Test: Search for changes related to aria-hidden in the radio component
rg --type vue 'aria-hidden' packages/vue/src/radio

Length of output: 78


Script:

#!/bin/bash
# Description: Re-attempt to search for changes related to aria-hidden in the radio component within .vue files.

# Search for 'aria-hidden' in .vue files within packages/vue/src/radio
rg 'aria-hidden' packages/vue/src/radio --glob '*.vue'

Length of output: 190

@kagol kagol merged commit ee0c2cf into dev Oct 16, 2024
5 of 6 checks passed
@kagol kagol deleted the fix-radio-aria-hidden-error branch November 4, 2024 03:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants