Skip to content

fix: check document.activeElement in addition to event.target for ignoreInputs#89

Open
KevinVandy wants to merge 3 commits intomainfrom
cursor/hotkey-issue-83-30f6
Open

fix: check document.activeElement in addition to event.target for ignoreInputs#89
KevinVandy wants to merge 3 commits intomainfrom
cursor/hotkey-issue-83-30f6

Conversation

@KevinVandy
Copy link
Member

@KevinVandy KevinVandy commented Mar 26, 2026

🎯 Changes

This PR fixes the ignoreInputs option not working properly with libraries like React Aria that intercept and re-dispatch keyboard events.

Problem:
Some libraries like React Aria's Autocomplete intercept keydown events from input elements and re-dispatch them on a different element (like a list item in a collection). In these cases, event.target is the re-dispatched target (e.g., a list item), not the actual focused input. This causes TanStack Hotkeys to incorrectly trigger hotkeys even though the user is typing in an input.

Solution:
In addition to checking event.target, we now also check document.activeElement to detect if the user is actually focused on an input element. This ensures that the ignoreInputs option works correctly even when events are re-dispatched by libraries like React Aria.

Changes:

  • Modified HotkeyManager.#processTargetEvent() to check both event.target and document.activeElement via isInputElement()
  • Modified SequenceManager.#processTargetEvent() with the same fix
  • Added tests for both managers to verify the React Aria-style event re-dispatch scenario

Fixes #83

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).
Open in Web Open in Cursor 

Summary by CodeRabbit

  • Bug Fixes

    • Fixed ignoreInputs option to properly detect input focus even when keyboard events are dispatched from different elements (e.g., in React Aria patterns).
  • Tests

    • Added comprehensive test coverage for the updated input-ignoring behavior with various hotkey and sequence scenarios.
  • Documentation

    • Updated reference documentation with accurate source line numbers.

cursoragent and others added 2 commits March 26, 2026 15:00
…oreInputs

Some libraries like React Aria's Autocomplete intercept keydown events
from input elements and re-dispatch them on a different element (like a
list item). In these cases, event.target is the re-dispatched target,
not the actual focused input. By also checking document.activeElement,
we can properly detect when the user is typing in an input even if the
event has been re-dispatched.

Fixes #83

Co-authored-by: kevinvandy656 <kevinvandy656@gmail.com>
Co-authored-by: kevinvandy656 <kevinvandy656@gmail.com>
@coderabbitai
Copy link

coderabbitai bot commented Mar 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fda15823-172f-4a62-9e1b-bab0e82d2f85

📥 Commits

Reviewing files that changed from the base of the PR and between 4fbe605 and 65000d8.

📒 Files selected for processing (10)
  • .changeset/fix-ignore-inputs-active-element.md
  • docs/reference/classes/HotkeyManager.md
  • docs/reference/classes/SequenceManager.md
  • docs/reference/functions/createSequenceMatcher.md
  • docs/reference/functions/getHotkeyManager.md
  • docs/reference/functions/getSequenceManager.md
  • packages/hotkeys/src/hotkey-manager.ts
  • packages/hotkeys/src/sequence-manager.ts
  • packages/hotkeys/tests/hotkey-manager.test.ts
  • packages/hotkeys/tests/sequence-manager.test.ts

📝 Walkthrough

Walkthrough

The change fixes the ignoreInputs option to work with libraries like React Aria that re-dispatch keyboard events. It now checks both event.target and document.activeElement when deciding whether to ignore input-related hotkeys, enabling proper detection when events originate from focused inputs but are dispatched to different elements.

Changes

Cohort / File(s) Summary
Changeset & Documentation
.changeset/fix-ignore-inputs-active-element.md, docs/reference/classes/..., docs/reference/functions/...
Added changeset entry documenting the fix. Updated "Defined in" line references across multiple reference docs (HotkeyManager, SequenceManager, and getter functions) to reflect source code shifts.
Core Input-Ignore Logic
packages/hotkeys/src/hotkey-manager.ts, packages/hotkeys/src/sequence-manager.ts
Enhanced ignoreInputs logic to check both event.target and document.activeElement when determining whether to suppress hotkeys. Preserves existing behavior where hotkeys scoped to specific elements still fire, while preventing unintended triggers when input elements are focused but events are re-dispatched to other elements.
Hotkey Manager Tests
packages/hotkeys/tests/hotkey-manager.test.ts
Added two test cases validating the React Aria pattern: one asserting non-mod hotkeys are ignored when activeElement is an input but event.target differs, and another asserting mod hotkeys fire in the same scenario.
Sequence Manager Tests
packages/hotkeys/tests/sequence-manager.test.ts
Added two test cases for SequenceManager validating the React Aria pattern: one asserting normal sequences are ignored under activeElement/event.target mismatch, and another asserting mod-based sequences fire under the same mismatch condition.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A rabbit hops through React Aria's twisted paths,
Where events take detours but focus stays put,
Now hotkeys check the active element's dance,
Not just where the keystroke lands—
Both locations whisper their truth! 🎹✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: checking document.activeElement in addition to event.target for the ignoreInputs fix.
Description check ✅ Passed The description follows the template with clear sections for changes, rationale, and completed checklists. All required sections are filled out appropriately.
Linked Issues check ✅ Passed All code changes directly address issue #83: both managers check document.activeElement alongside event.target, tests validate the React Aria re-dispatch scenario, and a changeset was added.
Out of Scope Changes check ✅ Passed All changes are in scope: core logic fixes in both managers, comprehensive test coverage for the new behavior, documentation line updates, and a changeset entry.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/hotkey-issue-83-30f6

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

🚀 Changeset Version Preview

1 package(s) bumped directly, 11 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/hotkeys 0.6.1 → 0.6.2 Changeset
@tanstack/angular-hotkeys 0.8.1 → 0.8.2 Dependent
@tanstack/hotkeys-devtools 0.7.1 → 0.7.2 Dependent
@tanstack/preact-hotkeys 0.8.1 → 0.8.2 Dependent
@tanstack/preact-hotkeys-devtools 0.6.1 → 0.6.2 Dependent
@tanstack/react-hotkeys 0.8.1 → 0.8.2 Dependent
@tanstack/react-hotkeys-devtools 0.6.1 → 0.6.2 Dependent
@tanstack/solid-hotkeys 0.8.1 → 0.8.2 Dependent
@tanstack/solid-hotkeys-devtools 0.6.1 → 0.6.2 Dependent
@tanstack/svelte-hotkeys 0.8.1 → 0.8.2 Dependent
@tanstack/vue-hotkeys 0.8.1 → 0.8.2 Dependent
@tanstack/vue-hotkeys-devtools 0.6.1 → 0.6.2 Dependent

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 26, 2026

Open in StackBlitz

@tanstack/angular-hotkeys

npm i https://pkg.pr.new/@tanstack/angular-hotkeys@89

@tanstack/hotkeys

npm i https://pkg.pr.new/@tanstack/hotkeys@89

@tanstack/hotkeys-devtools

npm i https://pkg.pr.new/@tanstack/hotkeys-devtools@89

@tanstack/preact-hotkeys

npm i https://pkg.pr.new/@tanstack/preact-hotkeys@89

@tanstack/preact-hotkeys-devtools

npm i https://pkg.pr.new/@tanstack/preact-hotkeys-devtools@89

@tanstack/react-hotkeys

npm i https://pkg.pr.new/@tanstack/react-hotkeys@89

@tanstack/react-hotkeys-devtools

npm i https://pkg.pr.new/@tanstack/react-hotkeys-devtools@89

@tanstack/solid-hotkeys

npm i https://pkg.pr.new/@tanstack/solid-hotkeys@89

@tanstack/solid-hotkeys-devtools

npm i https://pkg.pr.new/@tanstack/solid-hotkeys-devtools@89

@tanstack/svelte-hotkeys

npm i https://pkg.pr.new/@tanstack/svelte-hotkeys@89

@tanstack/vue-hotkeys

npm i https://pkg.pr.new/@tanstack/vue-hotkeys@89

@tanstack/vue-hotkeys-devtools

npm i https://pkg.pr.new/@tanstack/vue-hotkeys-devtools@89

commit: 65000d8

Copy link

@junlarsen junlarsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat, thanks for being so quick!

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.

Option ignoreInputs does not work for React Aria Collections

3 participants