Skip to content

fix(site-components): preserve slash input in shadow DOM editors - #949

Open
PointerL wants to merge 1 commit into
Tencent:mainfrom
PointerL:fix/site-search-shadow-dom-slash
Open

PointerL wants to merge 1 commit into
Tencent:mainfrom
PointerL:fix/site-search-shadow-dom-slash

Conversation

@PointerL

Copy link
Copy Markdown

🤔 What kind of change does this PR introduce?

  • Bug fix
  • Component interaction improvement
  • Tests

🔗 Related Issue

Self-discovered bug. No matching issue or fix PR was found during the pre-submission search.

💡 Background and solution

The global / search shortcut checks document.activeElement to avoid intercepting text input. For an editor inside an open shadow root, this points to the shadow host instead of the editor. The shortcut therefore calls preventDefault() and opens search while the user is typing. This also affects the search component's own shadow-root input.

Check the keyboard event's composed path for editable elements before handling /, while retaining the existing active-element guard. No public API or dependency changes are required.

Reproduction

  1. On a page with td-doc-search mounted, focus an input inside an open shadow root.
  2. Type a/b.
  3. Before this fix, / is prevented and the global search shortcut fires. After this fix, a/b stays in the editor without activating the shortcut.

The screenshots below use a minimal page importing the actual registerHotkeys() helper. Its open callback focuses a separate search input, making accidental shortcut activation visible.

Before After
Slash is prevented and the search shortcut steals focus The editor retains a/b without activating the shortcut

Validation

  • Added 16 hotkey tests covering shadow-root input/textarea/select, nested shadow roots, contenteditable descendants, light-DOM editors, explicit search shortcuts, Escape and listener cleanup.
  • Before the fix: 5 regression tests failed; 11 compatibility tests passed.
  • After the fix: pnpm run test passed, including coverage (6 files, 26 tests).
  • pnpm run typecheck, pnpm run lint and pnpm run build passed in packages/site-components. The build includes Less compilation.
  • Prettier and git diff --check passed.
  • Browser check: a/b remains in the shadow-root editor; Ctrl+K, Escape and / outside an editor still work. Meta+K is covered by unit tests.

📝 Changelog

  • fix(site-components): Allow typing / in open Shadow DOM editors without triggering the global search shortcut.

  • This PR does not need a changelog entry.

☑️ Checklist before requesting a merge

  • Documentation has been updated or is not required.
  • A demo has been provided or is not required.
  • TypeScript definitions have been updated or are not required.
  • A changelog entry has been provided or is not required.

@tencent-adm

tencent-adm commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
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