Skip to content

Move DOM event handling out of useEntitySearchInput into its component - #697

Merged
gaidheal1 merged 1 commit into
developmentfrom
claude/issue-573-implementation-wrgq0t
Aug 9, 2026
Merged

Move DOM event handling out of useEntitySearchInput into its component#697
gaidheal1 merged 1 commit into
developmentfrom
claude/issue-573-implementation-wrgq0t

Conversation

@gaidheal1

Copy link
Copy Markdown
Member

Summary

useEntitySearchInput was named and positioned as a logic hook, but it reached into the DOM directly for click-outside dismissal and typed its keydown handler against DOM element interfaces. This splits it along the platform boundary, per #573.

  • Stays in the hook (portable): fuzzy search via fuse.js, result derivation, selection state, the debounce, and the semantic intent of keyboard actions — now exposed as onSelectNext, onSelectPrevious, onDismiss, onCommit instead of a DOM-typed handleKeyDown. onCommit returns whether it took action, so the caller knows whether to suppress the key's default behaviour.
  • Moved to EntitySearchInput.tsx (web): the document mousedown listener for click-outside dismissal (component now owns rootRef and calls onDismiss()), and translation of raw KeyboardEvents into the hook's semantic actions.
  • window.setTimeout / window.clearTimeout → bare setTimeout / clearTimeout.

This branch is stacked on #680 (extracting the beforeunload guard out of useActivityTimer), since both are part of the #569 DOM-decoupling epic and this one was started from that branch.

Acceptance criteria

  • No document or window reference remains in useEntitySearchInput.ts
  • No DOM-element-typed parameters (HTMLInputElement, KeyboardEvent) in the hook's public surface
  • Clicking outside still dismisses the dropdown
  • Keyboard behaviour is unchanged: arrow-key selection, Enter to commit, Escape to dismiss
  • Debounce timing behaviour is unchanged
  • EntitySearchInput.test.tsx still passes

Test plan

  • npx tsc --noEmit — no errors
  • npx eslint src/components/EntitySearchInput/ — no errors
  • npx vitest run — 410/410 pass (pre-existing Playwright browser-launch error is unrelated to this change)

Fixes #573


Generated by Claude Code

@gaidheal1
gaidheal1 force-pushed the claude/issue-573-implementation-wrgq0t branch from 47edbce to 505ea15 Compare August 9, 2026 13:53
@gaidheal1
gaidheal1 marked this pull request as ready for review August 9, 2026 14:13
@gaidheal1
gaidheal1 force-pushed the claude/issue-573-implementation-wrgq0t branch from 505ea15 to aec2148 Compare August 9, 2026 14:13
@gaidheal1
gaidheal1 force-pushed the claude/issue-573-implementation-wrgq0t branch from aec2148 to 27fd993 Compare August 9, 2026 14:33
Base automatically changed from claude/issue-572-fix-c99hxy to development August 9, 2026 14:41
useEntitySearchInput reached into the DOM directly for click-outside
dismissal and typed its keydown handler against KeyboardEvent<HTMLInputElement>.
This splits it along the platform boundary, per #573:

- Hook now exposes intent-shaped actions (onSelectNext, onSelectPrevious,
  onDismiss, onCommit) instead of a DOM-typed handleKeyDown.
- The document mousedown listener for click-outside dismissal moves to
  EntitySearchInput.tsx, which owns the rootRef and translates the
  gesture into onDismiss().
- EntitySearchInput.tsx's handleKeyDown translates raw KeyboardEvents
  into the hook's semantic actions.
- window.setTimeout/window.clearTimeout -> bare setTimeout/clearTimeout.

Fixes #573
@gaidheal1
gaidheal1 force-pushed the claude/issue-573-implementation-wrgq0t branch from 27fd993 to aaf264e Compare August 9, 2026 14:41
@gaidheal1
gaidheal1 merged commit d96103e into development Aug 9, 2026
2 checks passed
@gaidheal1
gaidheal1 deleted the claude/issue-573-implementation-wrgq0t branch August 9, 2026 14:53
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.

2 participants