feat(focus): let useFocusManager listen on a given event target - #63
Merged
Merged
Conversation
The focus manager bound keydown and keyup on `document`. A host without a DOM, such as a NativeScript app that reports remote presses through its own bridge, had nowhere to hand those events. `useFocusManager` now takes the target as a second argument, typed as the two listener methods it uses, and still defaults to `document`, so browser apps are unchanged. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
chiefcll
force-pushed
the
focus-manager-event-target
branch
from
September 17, 2026 17:59
b943900 to
49f8c76
Compare
The suite runs its files without isolation, so a document key listener left by another file in the same worker reached the focused element and failed the assertion on CI. Assert that useFocusManager registers no key listener on document instead, which is the property under test. Co-Authored-By: Claude Fable 5.1 <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.
Summary
useFocusManager(keyMap?, target = document): the focus manager bindskeydownandkeyupon the target it is given instead of always ondocument.@solidtv/solidand@solidtv/solid/primitives:KeyEventTarget, the two listener methods the focus manager uses, andKeyEventLike, the three event fields it reads (key,keyCode,repeat). The target is typed againstKeyEventLikerather thanKeyboardEventon purpose: TypeScript compares callback parameters covariantly, so a host whose events are a subset ofKeyboardEventcould not otherwise satisfy the parameter without a cast. Handlers on such a host receive the host's event object.docs/primitives/useFocusManager.md.Browser apps are unchanged: the argument defaults to
document.Why
A host without a DOM has nowhere to hand remote presses. The NativeScript port of SolidTV for Apple TV (solid-tv/renderer#199 and its Phase 2 follow-up) reports presses through a
KeyBridgethat exposes these two methods and raises events shaped likeKeyboardEvent. The canvas polyfill there does install adocument, but itsaddEventListeneris a no-op without a native emitter, so binding there silently drops every key.Test plan
tests/focusManagerTarget.test.tsx: listeners land on the given target,documentevents are ignored when a target is given, and cleanup removes the listeners from the target.pnpm test,pnpm build,pnpm lintuseFocusManager(undefined, keyBridge)against the built package without a cast.🤖 Generated with Claude Code