Skip to content

Conversation

@shuningYanger
Copy link
Contributor

@shuningYanger shuningYanger commented Oct 24, 2025

无障碍模式下虚拟输入框的元素设置了role=textbox,如果同时设置了aria-label,输入框中的元素会读两遍
修改了该问题,兼容没有输入内容可以读出placeholder,有输入内容时仅读屏一次

Summary by CodeRabbit

发版说明

  • 新功能

    • 点击虚拟输入内容时会触发聚焦状态,提升交互反馈与键盘可访问性。
  • Bug 修复

    • 优化无障碍标签逻辑:有值时不再将实际值作为 aria-label,空值时使用占位提示作为无障碍标签,改善屏幕阅读器体验。

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Oct 24, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Oct 24, 2025

Preview is ready

@gemini-code-assist
Copy link

Summary of Changes

Hello @shuningYanger, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在解决虚拟输入框在无障碍模式下的读屏重复问题。当一个设置了 role=textbox 的虚拟输入框同时拥有 aria-label 属性时,读屏器会错误地播报内容两次。本次修改通过调整 src/components/virtual-input/virtual-input.tsx 文件中 aria-label 属性的赋值逻辑,使其在有输入内容时避免重复播报,并在没有输入内容时,仍能让读屏器播报占位符,从而提升用户体验。

Highlights

  • 无障碍优化: 调整了虚拟输入框中 aria-label 属性的条件逻辑,以解决无障碍模式下读屏器重复播报输入内容的问题。
  • 读屏行为改进: 新逻辑旨在确保在输入框有内容时避免重复播报,并在无内容时兼容播报占位符。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link

coderabbitai bot commented Oct 24, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

在虚拟输入组件中:1) 点击处理流程中在调用 onClick 后新增副作用 setHasFocus(true),引入点击后聚焦状态;2) 调整内容容器的无障碍标签逻辑,aria-label 在有值时为 undefined,无值时使用 placeholder

Changes

Cohort / File(s) 变更摘要
虚拟输入组件行为与无障碍调整
src/components/virtual-input/virtual-input.tsx
点击处理器中在 onClick 调用后添加 setHasFocus(true);调整 aria-label 赋值由 `value

Sequence Diagram(s)

sequenceDiagram
    participant U as 用户
    participant C as ContentContainer
    participant V as VirtualInput (组件)
    rect rgb(235,245,255)
    U->>C: 点击
    C->>V: 调用 onClick (若存在)
    V-->>C: 返回
    note right of V #ccffdd: 新增副作用
    V->>V: setHasFocus(true)
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • 关注点:点击处理器中新增的 focus 状态副作用对组件生命周期/父组件的影响;aria-label 更改对屏幕阅读器行为的可访问性测试。

Poem

🐰 一次轻点带新焦,
标签悄悄藏其音。
空时占位代言说,
翻页无声更安心。 ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed 标题"fix: 解决无障碍输入框读屏两次问题"(修复:解决辅助功能输入框屏幕阅读器读取两次的问题)准确反映了此PR的主要变更。根据PR目标和代码摘要,此变更的核心是通过修改aria-label逻辑来解决辅助功能模式下屏幕阅读器重复读取的问题。具体地,当存在输入值时aria-label使用undefined,当值不存在时才回退到placeholder,这直接对应了标题中描述的修复目标。标题清晰具体,不含模糊用语,准确传达了变更的意图。
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 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 1fa5009 and 5ec3624.

📒 Files selected for processing (1)
  • src/components/virtual-input/virtual-input.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/virtual-input/virtual-input.tsx

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai bot requested a review from zombieJ October 24, 2025 02:45
@dosubot dosubot bot added the bug label Oct 24, 2025
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

你好,感谢你为改善无障碍体验所做的努力。这个 PR 旨在解决虚拟输入框内容被读屏软件重复朗读的问题。

在审查代码时,我发现对 aria-label 的逻辑调整可能未完全实现预期目标,并且可能引入了新的问题:当输入框为空时,placeholder 将不会被朗读。

我已在代码中提供了一条具体的审查意见和代码建议,希望能帮助你修正此问题,以确保在有内容时只朗读一次,无内容时能正确朗读 placeholder。请查看我的评论。

ref={contentRef}
aria-disabled={mergedProps.disabled}
aria-label={value || mergedProps.placeholder}
aria-label={value && mergedProps.placeholder}

Choose a reason for hiding this comment

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

critical

你好,这个修改似乎没有完全达到预期的效果,并且引入了新的无障碍问题。

根据你的 PR 描述,期望的行为是:

  • 当输入框没有内容(value 为空)时,读屏软件应该读出 placeholder
  • 当输入框有内容时,为了避免重复朗读,应该只读出 value 本身。

当前的修改 aria-label={value && mergedProps.placeholder} 会导致:

  1. value 为空字符串 '' 时,aria-label 的值也是 '',这会导致读屏软件不会读出 placeholder,这是一个功能退步。
  2. value 有内容时(例如 '123'),aria-label 会被设置为 mergedProps.placeholder 的值。这会导致读屏软件先读 placeholder 再读 value(例如 “请输入内容,123”),这与“仅读屏一次”的目标不符。

正确的做法是仅在 value 为空时才提供 aria-label。请参考下面的代码建议进行修改。

          aria-label={!value ? mergedProps.placeholder : undefined}

Copy link
Contributor

Choose a reason for hiding this comment

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

value ? undefined : mergedProps.placeholder

我觉得这样更好

@coderabbitai coderabbitai bot added lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files. labels Oct 24, 2025
@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. size:S This PR changes 10-29 lines, ignoring generated files. labels Oct 24, 2025
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: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4cda8ca and 484d47b.

📒 Files selected for processing (1)
  • src/components/virtual-input/virtual-input.tsx (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/components/virtual-input/virtual-input.tsx (1)
src/components/virtual-input/demos/demo1.tsx (1)
  • value (7-94)

@shuningYanger shuningYanger marked this pull request as draft October 24, 2025 02:53
@coderabbitai coderabbitai bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Oct 24, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 24, 2025

npm i https://pkg.pr.new/ant-design/ant-design-mobile/antd-mobile@6977

commit: 5ec3624

@codecov
Copy link

codecov bot commented Oct 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.94%. Comparing base (4cda8ca) to head (5ec3624).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6977   +/-   ##
=======================================
  Coverage   92.94%   92.94%           
=======================================
  Files         337      337           
  Lines        7358     7359    +1     
  Branches     1860     1834   -26     
=======================================
+ Hits         6839     6840    +1     
- Misses        483      511   +28     
+ Partials       36        8   -28     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@shuningYanger shuningYanger marked this pull request as ready for review October 28, 2025 02:06
@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. size:S This PR changes 10-29 lines, ignoring generated files. labels Oct 28, 2025
@zombieJ zombieJ merged commit bcd6a57 into ant-design:master Oct 28, 2025
14 checks passed
}
mergedProps.onClick?.(e)
mergedProps.onClick?.(e);
setHasFocus(true)
Copy link
Contributor

Choose a reason for hiding this comment

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

这里应该调用下 setFocus 比较合理,一个是有个判断,第二个是会触发 onFocus 外部回调

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants