fix(button): use :focus-visible for hover-bg, drop click-focused dark state#7437
Draft
talissoncosta wants to merge 2 commits intomainfrom
Draft
fix(button): use :focus-visible for hover-bg, drop click-focused dark state#7437talissoncosta wants to merge 2 commits intomainfrom
talissoncosta wants to merge 2 commits intomainfrom
Conversation
… state The `.btn:focus` rule was applying the hover-bg colour for any focus event including mouse clicks. Browsers leave clicked buttons focused by design, so the button looked permanently pressed until the user clicked elsewhere — visible on every primary button across the app (Storybook surfaces it most obviously, but it happens in production too). Switching the rule to `:focus-visible` keeps the visual indicator for keyboard-driven focus (Tab key) while skipping it for mouse clicks. A11y signal preserved, click-and-stuck appearance gone. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
The previous commit only fixed the base .btn rule. Each theme variant (secondary, tertiary, danger, success, outline, link, project, icon, with-icon) defined its own &:hover, &:focus pair, so the click-and-stuck appearance kept happening on every variant. Replaces all `:focus` references in _buttons.scss with `:focus-visible` (except the one inside the explanatory comment). Same fix shape, applied to the full surface — light and dark themes, every variant, every custom button class. 19 lines changed in a single SCSS file. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thanks for submitting a PR! Please check the boxes below:
Changes
TL;DR. Primary buttons stay visibly "pressed" after a mouse click until the user clicks elsewhere. Switching the focus-state CSS from `:focus` to `:focus-visible` removes the click-and-stuck appearance while preserving the keyboard-focus indicator.
Cause
_buttons.scsslines 8–11 (pre-fix)::focusmatches any focus event, including the focus a browser implicitly gives a button after a mouse click. So the flow is::focusfires → background turns to\$primary600(darker).Visible on every primary button across the app. Storybook surfaces it most obviously because the button stays in view post-click, but it happens in production too — confirmed by clicking Create Identities on the Identities page and watching the button stay dark.
Fix
Single rule change:
:focus→:focus-visible.:focus-visibleis the modern pseudo-class that matches focus only when it arrived via keyboard navigation (Tab) or programmatic focus — not mouse clicks. Browser support is universal across all evergreen browsers.After the change:
:focus-visibledoesn't match → no darkening → no stuck appearance. ✓:focus-visiblematches → background darkens → keyboard users see the focus state. ✓ (a11y preserved):focus-visible { box-shadow: none }rule on the next line stays as-is — same intent (suppress Bootstrap's default focus ring on keyboard focus, since the bg-darkening is the visual indicator).Out of scope
The
:focusreferences in.btn-projectrules (lines 224, 435) are visual focus styles for the project-picker variant. They probably want the same treatment but the.btn-projectrendering is more involved than the base button — kept out of this PR to keep the diff focused. Worth a follow-up if Chromatic flags any visual divergence in those stories.How did you test this code?
mainby clicking Create Identities on the Identities page and observing the button stay darkened until clicking elsewhere.