Skip to content

Commit a9e05c0

Browse files
fix(devtools): ignore the hotkey while focus is in an editable element (#325)
* fix: ignore the hotkey while focus is in an editable element by guarding the createShortcut callback * fix: enhance shortcut functionality by preventing activation in editable elements * ci: apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 3e19f95 commit a9e05c0

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

.changeset/hungry-donkeys-allow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/devtools': patch
3+
---
4+
5+
Ignore the hotkey while focus is in an editable element by guarding the createShortcut callback

packages/devtools/src/devtools.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,25 @@ export default function DevTools() {
165165
}
166166
})
167167
createEffect(() => {
168+
const isEditableTarget = (element: Element | null) => {
169+
if (!element || !(element instanceof HTMLElement)) return false
170+
if (element.isContentEditable) return true
171+
const tagName = element.tagName
172+
if (
173+
tagName === 'INPUT' ||
174+
tagName === 'TEXTAREA' ||
175+
tagName === 'SELECT'
176+
) {
177+
return true
178+
}
179+
return element.getAttribute('role') === 'textbox'
180+
}
181+
168182
const permutations = getHotkeyPermutations(settings().openHotkey)
169183

170184
for (const permutation of permutations) {
171185
createShortcut(permutation, () => {
186+
if (isEditableTarget(document.activeElement)) return
172187
toggleOpen()
173188
})
174189
}

0 commit comments

Comments
 (0)