Skip to content

fix: accept onfocusin/onfocusout in a11y_mouse_events_have_key_events - #18689

Open
giaBaoJS wants to merge 1 commit into
sveltejs:mainfrom
giaBaoJS:fix/a11y-mouse-events-focusin-focusout
Open

fix: accept onfocusin/onfocusout in a11y_mouse_events_have_key_events#18689
giaBaoJS wants to merge 1 commit into
sveltejs:mainfrom
giaBaoJS:fix/a11y-mouse-events-focusin-focusout

Conversation

@giaBaoJS

@giaBaoJS giaBaoJS commented Aug 23, 2026

Copy link
Copy Markdown

Fixes #8089

a11y_mouse_events_have_key_events currently accepts only focus as a partner for mouseover and only blur as a partner for mouseout. But focus and blur do not bubble, so an element that is not itself focusable — the common case for a hover-triggered tooltip wrapper, a <div>, a heading — can never receive them. The bubbling equivalents are focusin and focusout.

The result is that correct markup gets warned about, and the only way to silence the warning is to attach a handler that can never fire:

<!-- warns today, even though this is the accessible version -->
<h1 onmouseover={show} onfocusin={show}>Hello</h1>

<!-- doesn't warn, but `onfocus` never fires on a non-focusable <h1> -->
<h1 onmouseover={show} onfocus={show}>Hello</h1>

This widens the check to treat focusin/focusout as satisfying the rule, which is what @f-elix suggested on the issue. No new API and no new warnings — it strictly removes false positives; markup with neither focus nor focusin still warns.

Changes

  • a11y/index.js: accept focusin alongside focus, and focusout alongside blur
  • messages/compile-warnings/a11y.md: document the accepted alternatives (+ regenerated documentation/docs/98-reference/.generated/compile-warnings.md via pnpm generate)
  • Two cases added to the a11y-mouse-events-have-key-events validator sample

Test plan

FILTER=a11y-mouse-events-have-key-events pnpm test packages/svelte/tests/validator/test.ts
#  Tests  3 passed | 3 skipped (6)

pnpm test
#  Test Files  34 passed (34)
#  Tests  7753 passed | 69 skipped (7822)

pnpm lint          # clean
pnpm --filter svelte check   # clean

The new fixture cases fail without the source change (the compiler emits two unexpected a11y_mouse_events_have_key_events warnings on lines 21 and 23), and the two pre-existing cases — <div onmouseover> and <div onmouseout> with no focus partner at all — still warn, so the rule is not simply disabled.

@pkg-svelte-dev

Copy link
Copy Markdown

Install the latest version of svelte from d27f703:

pnpm add https://pkg.svelte.dev/svelte/c/d27f7034776940efdbb4ed8599931ac3812abe61

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/svelte/pr/18689

Note

This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed.

@changeset-bot

changeset-bot Bot commented Aug 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d27f703

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.

a11y-mouse-events-have-key-events warning when using focusin/focusout

1 participant