Skip to content

Conversation

@Puxhkar
Copy link

@Puxhkar Puxhkar commented Dec 3, 2025

Description

Adds :focus-visible CSS support for better keyboard accessibility.

Changes

  • Shows 2px outline for keyboard navigation (Tab)
  • Hides outline for mouse clicks
  • Uses :where() for low specificity
  • Covers buttons, inputs, links, and other interactive elements

Testing

✅ Built and tested in browser - keyboard shows outlines, mouse clicks don't

Impact

  • Improves keyboard accessibility
  • Better WCAG 2.1 compliance
  • No breaking changes
  • 96%+ browser support

Summary by CodeRabbit

  • Style
    • Improved focus styling for interactive elements to boost keyboard navigation visibility: added a clear, accessible focus outline for keyboard users while suppressing the outline for non-keyboard (mouse) interactions to reduce visual clutter.

✏️ Tip: You can customize this high-level summary in your review settings.

- Add :focus-visible rules to show focus outlines for keyboard navigation
- Add :focus:not(:focus-visible) to hide outlines for mouse clicks
- Improves WCAG 2.1 compliance (SC 2.4.7)
- Uses low-specificity :where() for easy customization
- Covers all interactive elements (buttons, inputs, links, etc.)
@coderabbitai
Copy link

coderabbitai bot commented Dec 3, 2025

Walkthrough

Adds CSS rules to src/components/forms.scss that provide a 2px :focus-visible outline with 2px offset for interactive elements and suppress the outline when elements are focused but not :focus-visible.

Changes

Cohort / File(s) Summary
Accessibility Focus Styling
src/components/forms.scss
Adds :focus-visible outline (2px with 2px offset) for interactive elements (a, button, input, select, textarea, [tabindex]) and removes outline for :focus:not(:focus-visible) on the same elements.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Single CSS file change, limited surface area.
  • Review focus selector correctness and potential specificity or browser support issues.
  • Verify no unintended interactions with existing form styles or component-level overrides.

Poem

🐰 I hopped a path of outline light,
Keyboard taps make focus bright,
Mouse clicks stay calm and low,
A tidy ring helps users know,
Hooray — accessible glow! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately describes the main change: adding :focus-visible CSS support for keyboard accessibility improvements.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

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 e89f83b and eb1a58b.

📒 Files selected for processing (1)
  • src/components/forms.scss (1 hunks)
🔇 Additional comments (1)
src/components/forms.scss (1)

95-105: ✓ Focus-visible rule is well-structured.

The :focus-visible selector is correctly composed with appropriate target elements and uses :where() to maintain low specificity. The outline styling (2px solid, 2px offset) is proper for accessibility.

Comment on lines 108 to 115
:where(
a,
button,
input,
select,
textarea
):focus:not(:focus-visible) {
outline: none;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Critical: Selector mismatch between focus and focus-visible rules.

The :focus:not(:focus-visible) rule (lines 108–115) does not include [tabindex]:not([tabindex="-1"]), whereas the :focus-visible rule (lines 95–105) does. This creates an inconsistency:

  • Custom focusable elements with tabindex will show an outline on keyboard focus (via :focus-visible) ✓
  • But that outline will not be removed when those same elements are focused via mouse, because they're not matched by the second rule ✗

This violates the intended behavior: "keyboard shows outlines and mouse clicks do not."

Apply this fix to make both selectors consistent:

 /* Remove focus outline for mouse users */
 :where(
   a,
   button,
   input,
   select,
-  textarea
+  textarea,
+  [tabindex]:not([tabindex="-1"])
 ):focus:not(:focus-visible) {
   outline: none;
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
:where(
a,
button,
input,
select,
textarea
):focus:not(:focus-visible) {
outline: none;
:where(
a,
button,
input,
select,
textarea,
[tabindex]:not([tabindex="-1"])
):focus:not(:focus-visible) {
outline: none;
}
🤖 Prompt for AI Agents
In src/components/forms.scss around lines 108 to 115, the
:focus:not(:focus-visible) selector omits [tabindex]:not([tabindex="-1"]) which
makes focus and focus-visible rules inconsistent for custom focusable elements;
update the :focus:not(:focus-visible) selector to include
[tabindex]:not([tabindex="-1"]) so it exactly mirrors the earlier :focus-visible
selector (i.e., include a, button, input, select, textarea, and
[tabindex]:not([tabindex="-1"]) in the :focus:not(:focus-visible) rule) and keep
the same rule body (outline: none).

Ensures custom focusable elements with tabindex don't show
outlines on mouse clicks, matching the :focus-visible behavior
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: 0

🧹 Nitpick comments (1)
src/components/forms.scss (1)

94-111: Optional: Consider adding a clarifying comment for maintainers.

The dual pseudo-class pattern (:focus-visible + :focus:not(:focus-visible)) is relatively modern and may not be immediately obvious to future maintainers. A brief inline comment explaining the keyboard vs. mouse distinction could improve maintainability without adding weight to the stylesheet.

Example:

/* Show outline for keyboard focus, hide for mouse focus */
:where(...):focus-visible { ... }
:where(...):focus:not(:focus-visible) { outline: none; }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eb1a58b and 276398a.

📒 Files selected for processing (1)
  • src/components/forms.scss (1 hunks)
🔇 Additional comments (2)
src/components/forms.scss (2)

94-102: Clear and focused keyboard accessibility styling.

The :focus-visible rule correctly applies a 2px outline with 2px offset to keyboard-navigated interactive elements using low-specificity :where() selectors. The use of currentColor ensures the outline adapts to element styling, and coverage includes custom focusable elements via [tabindex]:not([tabindex="-1"]).


104-111: Critical issue from past review has been resolved.

The :focus:not(:focus-visible) rule now correctly includes [tabindex]:not([tabindex="-1"]), making both selectors consistent. This ensures custom focusable elements will properly remove the outline on mouse focus, as intended.

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