Repository navigation
fix(button-stateful): stop mouseleave from stealing keyboard focus - #3224
Merged
interactivellama merged 2 commits intoOct 26, 2026
Merged
interactivellama merged 2 commits into
interactivellama merged 2 commits into
Conversation
Contributor
|
Thanks for tracking this down, and the root-cause write-up is helpful. Correct me if I'm wrong, but one concern before we merge: SLDS shows Could you keep the blur when the focus isn't :focus-visible (i.e. wasn't from the keyboard), and add a *.browser.test.jsx test covering both cases? Please also drop the unrelated Prettier reformatting (or move it to a separate style: commit) so the fix is easy to review. Thanks! |
zigzagdev
force-pushed
the
fix/button-stateful-mouseleave-blur
branch
2 times, most recently
from
October 24, 2026 08:40
c20ec2f to
1c1feb9
Compare
handleBlur is wired to both onBlur and onMouseLeave and unconditionally
called e.currentTarget.blur(). That blur is intentional for mouse users:
SLDS shows `slds-text-selected-focus` ("Unfollow") on
`.slds-is-selected:focus`, so without it the label stays after a click
once the pointer leaves. But it also ran when the button had keyboard
focus, so moving the mouse away from a tabbed-to button dropped focus.
Only blur when the button is not `:focus-visible`, so mouse-initiated
focus is still cleared and keyboard focus is kept.
The `'relatedTarget' in e` guard before onBlur was a no-op (MouseEvent
has relatedTarget too), so it is simplified to `if (onBlur)` with the
same behavior.
…ocus Adds browser-mode tests, since jsdom has neither `:focus-visible` nor the SLDS stylesheet. A mouse click followed by mouseleave blurs the button and hides "Unfollow"; keyboard focus survives mouseleave.
zigzagdev
force-pushed
the
fix/button-stateful-mouseleave-blur
branch
from
October 24, 2026 08:41
1c1feb9 to
955e9ce
Compare
Contributor
Author
|
I fixed it. And blur is kept now and only skipped when the button has keyboard focus. |
interactivellama
approved these changes
Oct 26, 2026
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.
Fixes #
Additional description
Motivation:
ButtonStateful'shandleBluris wired to bothonBlurandonMouseLeave, and unconditionally callse.currentTarget.blur(). That means simply moving the mouse away from aButtonStatefulthat currently has keyboard focus forces it to lose focus. This is a real accessibility problem for keyboard users who also use a mouse or trackpad.Root cause: This is a long-standing bug, not something the recent React 19 / TypeScript rewrite introduced. The original class component (
components/button-stateful/index.jsx, pre #3195) had the identicalhandleBlurshared betweenonBlurandonMouseLeavewith the same unconditionale.currentTarget.blur(). The rewrite additionally wrapped theonBlurforwarding inif (onBlur && 'relatedTarget' in e), but that guard doesn't actually change behavior, sincerelatedTargetexists on bothFocusEventandMouseEventand is effectively always true.What I did: Removed the forced
e.currentTarget.blur()call.handleBlurnow only forwards theonBlurcallback for both real blur and mouseleave, matching the original's intent of treating "mouse left" as a soft blur signal for consumers, without touching actual DOM focus.CONTRIBUTOR checklist (do not remove)
Please complete for every pull request.
Green gate — all of these must pass locally (CI runs the same):
npm run lintpasses with 0 errors (npm run lint:fixto auto-fix). Warnings are the tracked gradual-migration backlog; do not add new errors.npm run typecheckis clean (tsc --noEmit).npm test -- --runpasses — this runs both Vitest projects (jsdomunit+ real-browserbrowser) and the story HTML snapshots. If you changed rendered markup on purpose, update snapshots withnpm test -- --run -uand review the diff.npm run buildsucceeds (type-check + Vite library build +.d.ts+ entry shims).Behavior & docs:
components/button/__tests__). New props and bug fixes should get a regression test. Tests that genuinely need a real browser (focus traversal, layout/measurement, canvas) go in a*.browser.test.jsxfile (thebrowserproject); everything else is jsdom.npm run storybook→ http://localhost:6007/. Confirm the story actually renders and behaves (deprecated Storyshots/Karma are gone; there is no separate browser-tests server).onRenderContent/onRenderVisualPicker,iconprops,events), not assumptions — a common source of "component looks broken" reports has been stories authored against the wrong API. Cross-check againstcomponents/<name>/__examples__..d.ts(they're generated by the build); JS consumers rely on them via editor type-acquisition.REVIEWER checklist (do not remove)
CIworkflow: lint, typecheck, test, build). Chromatic visual review, if configured, has been checked.components/__tests__/__snapshots__/story-snapshots.test.jsx.snap).@salesforce/design-system-react/components/<name>and nested paths resolve for ESM, CJS, and types). Removing/renaming a public component or export is a breaking change →feat!:/BREAKING CHANGE:and a major version bump.