Add arrow key nav to channel list

This commit is contained in:
2025-08-21 13:45:13 +02:00
parent fa1cbdf97e
commit f2ac7d7209
4 changed files with 188 additions and 16 deletions

View File

@@ -25,11 +25,8 @@ export function useKeyboardShortcuts() {
}
const handleKeydown = (event: KeyboardEvent) => {
// Skip shortcuts when focused on input/textarea elements
const target = event.target as HTMLElement
if (target?.tagName === 'INPUT' || target?.tagName === 'TEXTAREA') {
return
}
const isInInputField = target?.tagName === 'INPUT' || target?.tagName === 'TEXTAREA'
const config: ShortcutConfig = {
key: event.key.toLowerCase(),
@@ -44,6 +41,16 @@ export function useKeyboardShortcuts() {
const shortcut = shortcuts.value.get(shortcutKey)
if (shortcut) {
// Allow certain shortcuts to work globally, even in input fields
const isGlobalShortcut = (shortcut.ctrlKey && shortcut.shiftKey) ||
shortcut.altKey ||
shortcut.key === 'escape'
// Skip shortcuts that shouldn't work in input fields
if (isInInputField && !isGlobalShortcut) {
return
}
if (shortcut.preventDefault !== false) {
event.preventDefault()
}