refactor(player): route the mount-time Play focus through the shared check

The onMounted branch repeated the pad/key test that
shouldClaimFocusOnModality already owns, so it now calls the helper and
also leaves an already-focused element alone. Trims the comments that
came with the original fix down to the non-obvious part.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Georges-Antoine AssiandClaude Opus 5 committed 2026-09-15 20:49:37 -04:00
1 parent 4cf9fed360
commit 1a89306dcd
3 files changed
+13 -13

No files matched your search

+1 -1
View File
@@ -24,7 +24,7 @@ describe("shouldAutofocusSearch", () => {
});
describe("shouldClaimFocusOnModality", () => {
const body = document.createElement("body");
const body = document.body;
const button = document.createElement("button");
it("claims an unfocused page for a pad or a keyboard", () => {
+2 -4
View File
@@ -15,10 +15,8 @@ export function shouldAutofocusSearch(
return win.matchMedia("(hover: hover) and (pointer: fine)").matches;
}
// Whether a switch to a directional input device should pull focus onto a
// view's primary action. Only pad/keyboard navigate by focus, and only an
// unfocused page is up for grabs — a user who tabbed somewhere keeps their
// place.
// Whether a modality switch should pull focus onto a view's primary action:
// only pad/key navigate by focus, and only an unfocused page is up for grabs.
export function shouldClaimFocusOnModality(
modality: InputModality,
active: Element | null,
+10 -8
View File
@@ -361,19 +361,21 @@ onMounted(async () => {
configBiosFile: coreOptions["bios_file"],
});
// Autofocus the Play CTA so gamepad/keyboard users land on the
// primary action without an extra Tab. Mouse / touch keep the
// default no-autofocus behaviour.
if (modality.value === "pad" || modality.value === "key") {
// Land gamepad/keyboard users on the primary action without an extra Tab.
if (
shouldClaimFocusOnModality(
modality.value,
document.activeElement,
document.body,
)
) {
await nextTick();
focusPlayButton();
}
});
// Arriving by mouse leaves the page unfocused, and this view has no spatial
// navigation for the d-pad to walk, so a pad picked up here had no way to
// reach Play (issue #4397). Landing on it the moment the user switches away
// from the mouse gives the pad an entry point.
// This view has no spatial navigation for a d-pad to walk, so landing on Play
// the moment the user picks up a pad is the only entry point into the view.
watch(modality, (next) => {
if (gameRunning.value) return;
if (!shouldClaimFocusOnModality(next, document.activeElement, document.body))