Skip to content

style: fix Tabs unexpected focus style#53901

Merged
afc163 merged 2 commits intomasterfrom
style/tabs-unexpected-focus-style
May 23, 2025
Merged

style: fix Tabs unexpected focus style#53901
afc163 merged 2 commits intomasterfrom
style/tabs-unexpected-focus-style

Conversation

@afc163
Copy link
Copy Markdown
Member

@afc163 afc163 commented May 23, 2025

中文版模板 / Chinese template

🤔 This is a ...

  • 🆕 New feature
  • 🐞 Bug fix
  • 📝 Site / documentation improvement
  • 📽️ Demo improvement
  • 💄 Component style improvement
  • 🤖 TypeScript definition improvement
  • 📦 Bundle size optimization
  • ⚡️ Performance optimization
  • ⭐️ Feature enhancement
  • 🌐 Internationalization
  • 🛠 Refactoring
  • 🎨 Code style optimization
  • ✅ Test Case
  • 🔀 Branch merge
  • ⏩ Workflow
  • ⌨️ Accessibility improvement
  • ❓ Other (about what?)

🔗 Related Issues

  • Describe the source of related requirements, such as links to relevant issue discussions.
  • For example: close #xxxx, fix #xxxx

Introduced in #52002

💡 Background and Solution

  • The specific problem to be addressed.
  • List the final API implementation and usage if needed.
  • If there are UI/interaction changes, consider providing screenshots or GIFs.

close #52435
close #53599
close #53886
close react-component/tabs#842

📝 Change Log

Language Changelog
🇺🇸 English Fix Tabs unexpected focus style
🇨🇳 Chinese 修复 Tabs 点击后有残留 focus 样式的问题。

@bolt-new-by-stackblitz
Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 23, 2025

📝 Walkthrough

Summary by CodeRabbit

  • 样式优化
    • 改进了标签页的聚焦样式和轮廓行为,提升了键盘导航的可见性和一致性。
    • 优化了聚焦和悬停状态下的样式分组与间距,使界面更美观。

Walkthrough

本次变更主要优化了 Tabs 组件卡片样式和常规样式下的聚焦(focus)与轮廓(outline)行为。通过更精确的选择器和伪类,调整了聚焦时的样式表现,避免出现多余的蓝色边框,提升了交互一致性,并进行了部分样式分组和格式微调。

Changes

文件/路径 变更摘要
components/tabs/style/index.ts 优化 Tabs 卡片和常规样式下聚焦与轮廓的选择器与表现,移除冗余规则,调整伪类,分组相关样式,格式微调。

Assessment against linked issues

Objective Addressed Explanation
修复 Tabs 聚焦后出现异常蓝框问题(#52435, #53599, #53886
切换标签或页面后样式应恢复正常(#53886

Suggested labels

skip-verify-files, lgtm

Suggested reviewers

  • li-jia-nan
  • Wxh16144
  • thinkasany

Poem

兔子跳跃在代码间,
聚焦蓝框不再现。
样式细调如春风,
标签切换更轻松。
outline 闪烁已远去,
体验升级乐无穷!
🐇✨

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


📜 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 557d51d and 14fb413.

📒 Files selected for processing (1)
  • components/tabs/style/index.ts (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
components/tabs/style/index.ts (1)
components/style/index.tsx (1)
  • genFocusOutline (135-139)
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: test-react-latest-dist (dist-min, 2/2)
  • GitHub Check: test-react-latest-dist (dist-min, 1/2)
  • GitHub Check: test-react-latest-dist (dist, 2/2)
  • GitHub Check: test-react-latest-dist (dist, 1/2)
  • GitHub Check: test-react-latest (dom, 2/2)
  • GitHub Check: test-react-latest (dom, 1/2)
  • GitHub Check: test-react-legacy (17, 2/2)
  • GitHub Check: test-react-legacy (17, 1/2)
  • GitHub Check: test-react-legacy (16, 2/2)
  • GitHub Check: test-react-legacy (16, 1/2)
  • GitHub Check: visual-diff snapshot (2/2)
  • GitHub Check: visual-diff snapshot (1/2)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (4)
components/tabs/style/index.ts (4)

720-726: 样式分组优化提升代码可读性

&-btn&-remove 的焦点/激活状态样式进行分组是一个很好的重构,提高了代码的组织性和可维护性。


727-733: 为按钮添加明确的轮廓控制

&-btn 添加 outline: 'none' 确保了一致的焦点样式控制,避免浏览器默认轮廓与自定义焦点样式冲突。


773-783: 代码格式优化增强可读性

添加的空行有助于在视觉上分离不同的样式块,提升代码的可读性和维护性。


178-185:

Details

✅ Verification successful

优化焦点样式选择器逻辑,解决点击后意外焦点样式问题

这些变更正确地解决了 PR 中提到的焦点样式问题:

  1. 使用 :has() 伪类结合 :focus-visible 创建更精确的选择器
  2. 添加显式的 outline: 'none' 规则避免双重轮廓

这种实现只在键盘导航时显示焦点样式,而不是在鼠标点击时显示,符合预期的用户体验。

请运行以下脚本验证 :has() 伪类的浏览器兼容性:


🌐 Web query:

What is the browser compatibility for CSS :has() pseudo-class and :focus-visible pseudo-class?

💡 Result:

Browser Compatibility for CSS :has() and :focus-visible Pseudo-Classes

:has() Pseudo-Class

The :has() relational pseudo-class allows you to select elements based on their children or siblings, enabling powerful "parent selector" patterns that were previously impossible in CSS only. As of 2025, :has() is now supported across all major browsers, although with varying starting versions:

Browser First Version Supported
Chrome 105
Edge 105
Firefox 121
Safari (macOS/iOS) 15.4
Opera 91
  • Chrome: Supported from v105 onward[5][2][4].
  • Edge: Supported from v105 onward[2][4].
  • Firefox: Supported from v121 onward[4][2][3]. Prior to v121, not supported at all or required a flag for experimental use[2][7].
  • Safari (macOS & iOS): Supported from v15.4 onward[5][2][4].
  • Opera: Supported from v91 onward[5][2].
  • Internet Explorer: Not supported in any version[2].

As of early 2025, global support for :has() is around 92% and rising, but a minority of users on legacy browsers (including older versions of Firefox and Safari) will not see your :has()-based styles[4].

:focus-visible Pseudo-Class

The :focus-visible pseudo-class lets you apply focus styles only when a user interacts via keyboard (or similar input), greatly improving accessibility without unsightly outlines on mouse interaction.

Browser First Version Supported
Chrome 86
Edge 86
Firefox 85 (full support)
Safari (macOS/iOS) 15.4
Opera 72
  • Chrome: Supported from v86 onward[6][10].
  • Edge: Supported from v86 onward[10].
  • Firefox: Supported from v85 onward (was available with the -moz- prefix in older versions)[7][10].
  • Safari (macOS & iOS): Supported from v15.4 onward[6][10].
  • Opera: Supported from v72 onward[6].

Summary Table

Pseudo-Class Chrome Edge Firefox Safari Opera
:has() 105+ 105+ 121+ 15.4+ 91+
:focus-visible 86+ 86+ 85+ 15.4+ 72+

Key Compatibility Notes

  • Neither pseudo-class is supported in Internet Explorer.
  • Use feature detection or fallback CSS for users on older browsers, especially when relying on :has().
  • Both selectors are now reliable for use in modern projects targeting recent browser versions, but always check your audience’s browser usage if legacy support matters.

In summary:
:has() is fully supported in all major evergreen browsers from late 2022/early 2023 onward, with Firefox joining in December 2023. :focus-visible has been widely supported since 2022 and is safe for use in most modern environments[2][4][10].

Citations:


CSS :has() 与 :focus-visible 兼容性已验证

根据 MDN、Can I Use 及各大浏览器文档,已确认:

  • :has() 在 Chrome 105+、Edge 105+、Firefox 121+、Safari 15.4+、Opera 91+ 中全面支持;
  • :focus-visible 在 Chrome 86+、Edge 86+、Firefox 85+、Safari 15.4+、Opera 72+ 中全面支持;
  • Internet Explorer 均不支持上述伪类。

结论:可放心在现代浏览器环境中使用更精确的焦点样式选择器。若需兼容 IE 或更老版本浏览器,建议使用 @supports 特性查询或提供简单的降级样式。

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 23, 2025

👁 Visual Regression Report for PR #53901 Passed ✅

🎯 Target branch: master (557d51d)
📖 View Full Report ↗︎
📖 Alternative Report ↗︎

🎊 Congrats! No visual-regression diff found.

@petercat-assistant
Copy link
Copy Markdown

Walkthrough

This pull request addresses an issue with the Tabs component where an unexpected focus style was applied. The changes modify the CSS to ensure that the focus style is only applied when the tab button is focus-visible, thereby fixing the issue of residual focus styles after clicking on tabs.

Changes

File Summary
components/tabs/style/index.ts Adjusted CSS selectors to apply focus styles only when focus-visible is detected, preventing unwanted focus outlines on tab buttons.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 23, 2025

Preview is ready

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 23, 2025

Deploying ant-design with  Cloudflare Pages  Cloudflare Pages

Latest commit: 14fb413
Status: ✅  Deploy successful!
Preview URL: https://30d8065c.ant-design.pages.dev
Branch Preview URL: https://style-tabs-unexpected-focus.ant-design.pages.dev

View logs


[`${componentCls}-tab-focus`]: {
...genFocusOutline(token, -3),
[`${componentCls}-tab-focus:has(${componentCls}-tab-btn:focus-visible)`]: genFocusOutline(
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The focus style is now correctly applied only when the tab button is focus-visible, which resolves the issue of unexpected focus styles persisting after tab clicks.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

emm 能解么 🤔

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 23, 2025

size-limit report 📦

Path Size
dist/antd.min.js 449.6 KB (+17 B 🔺)
dist/antd-with-locales.min.js 537.27 KB (+15 B 🔺)

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 23, 2025

@codecov
Copy link
Copy Markdown

codecov Bot commented May 23, 2025

Bundle Report

Changes will increase total bundle size by 48 bytes (0.0%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
antd.min-array-push 3.39MB 48 bytes (0.0%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: antd.min-array-push

Assets Changed:

Asset Name Size Change Total Size Change (%)
antd-with-locales.min.js 24 bytes 1.85MB 0.0%
antd.min.js 24 bytes 1.54MB 0.0%

@coderabbitai coderabbitai Bot added lgtm This PR has been approved by a maintainer skip-verify-files labels May 23, 2025
@codecov
Copy link
Copy Markdown

codecov Bot commented May 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (557d51d) to head (14fb413).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master    #53901   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          774       774           
  Lines        14019     14019           
  Branches      3712      3712           
=========================================
  Hits         14019     14019           

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

@afc163 afc163 requested a review from Copilot May 23, 2025 13:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue where unexpected focus styles remain on Tabs by refining the focus style rules with updated selectors.

  • Updates the focus outline styling to only apply when a tab button is focus-visible.
  • Introduces the use of the :has pseudo-class and removes redundant outline rules to improve the focus state styling.
Comments suppressed due to low confidence (2)

components/tabs/style/index.ts:178

  • [nitpick] The use of the :has pseudo-class is valid for modern browsers; please confirm that its support aligns with the target browser list or add fallback styles if necessary.
[`${componentCls}-tab-focus:has(${componentCls}-tab-btn:focus-visible)`]: genFocusOutline(token, -3),

components/tabs/style/index.ts:183

  • [nitpick] Consider consolidating or adding a comment to explain the explicit removal of the outline here to improve clarity and maintainability in the focus styling logic.
[`& ${componentCls}-tab${componentCls}-tab-focus ${componentCls}-tab-btn:focus-visible`]: { outline: 'none', },

@afc163 afc163 requested a review from Copilot May 23, 2025 13:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refines the Tabs focus styling by switching to :focus-visible, removing residual outlines on click, and tightening selectors to only show outlines for keyboard navigation.

  • Swap general focus selectors for :focus-visible variants
  • Remove default outlines on tab buttons when clicked
  • Adjust CSS rule specificity to prevent unexpected focus rings


[`${componentCls}-tab-focus`]: {
...genFocusOutline(token, -3),
[`${componentCls}-tab-focus:has(${componentCls}-tab-btn:focus-visible)`]: genFocusOutline(
Copy link

Copilot AI May 23, 2025

Choose a reason for hiding this comment

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

CSS :has() is not fully supported in all browsers (e.g. Firefox). Consider providing a fallback or using an alternative selector so that focus outlines aren’t lost where :has() isn’t available.

Copilot uses AI. Check for mistakes.
-3,
),

[`& ${componentCls}-tab${componentCls}-tab-focus ${componentCls}-tab-btn:focus-visible`]: {
Copy link

Copilot AI May 23, 2025

Choose a reason for hiding this comment

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

[nitpick] The selector & ${componentCls}-tab${componentCls}-tab-focus combines two classes without a clear delimiter. For readability, consider writing it as & .ant-tabs-tab.ant-tabs-tab-focus or splitting into separate rules.

Suggested change
[`& ${componentCls}-tab${componentCls}-tab-focus ${componentCls}-tab-btn:focus-visible`]: {
[`& .${componentCls}-tab.${componentCls}-tab-focus ${componentCls}-tab-btn:focus-visible`]: {

Copilot uses AI. Check for mistakes.
[`&${tabCls}-focus ${tabCls}-btn`]: {
...genFocusOutline(token),
},
[`&${tabCls}-focus ${tabCls}-btn:focus-visible`]: genFocusOutline(token),
Copy link

Copilot AI May 23, 2025

Choose a reason for hiding this comment

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

[nitpick] Selector formatting is inconsistent: here there’s no space after & when targeting the parent class, unlike other rules. Standardize spacing (e.g. & ${tabCls}-focus) for clarity.

Suggested change
[`&${tabCls}-focus ${tabCls}-btn:focus-visible`]: genFocusOutline(token),
[`& ${tabCls}-focus ${tabCls}-btn:focus-visible`]: genFocusOutline(token),

Copilot uses AI. Check for mistakes.
@afc163 afc163 merged commit 9f19708 into master May 23, 2025
53 checks passed
@afc163 afc163 deleted the style/tabs-unexpected-focus-style branch May 23, 2025 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer skip-verify-files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tabs标签切换的时候样式有问题 Tabs. Keyboard focus is triggered unexpectedly when using tab navigation tabs有莫名其妙的蓝框

4 participants