Skip to content

Commit ca24b61

Browse files
authored
Merge pull request #2583 from appwrite/fix-SER-493-prevent-global-shortcuts-when-typing-in-select
2 parents 7407bbd + 08989b7 commit ca24b61

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

src/lib/commandCenter/commandCenter.svelte

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@
3030
import { getContext, setContext } from 'svelte';
3131
import { get, writable, type Readable } from 'svelte/store';
3232
import { fade } from 'svelte/transition';
33-
import { commandCenterKeyDownHandler, disableCommands, registerCommands } from './commands';
33+
import {
34+
commandCenterKeyDownHandler,
35+
disableCommands,
36+
isTargetInputLike,
37+
registerCommands
38+
} from './commands';
3439
import { RootPanel } from './panels';
3540
import { addSubPanel, clearSubPanels, subPanels } from './subPanels';
3641
import { addNotification } from '$lib/stores/notifications';
@@ -95,13 +100,9 @@
95100
keys = [];
96101
}, 1000);
97102
98-
function isInputEvent(event: KeyboardEvent) {
99-
return ['INPUT', 'TEXTAREA', 'SELECT'].includes((event.target as HTMLElement).tagName);
100-
}
101-
102103
const handleKeydown = (e: KeyboardEvent) => {
103104
if (!$subPanels.length) {
104-
if (isInputEvent(e)) return;
105+
if (isTargetInputLike(e.target)) return;
105106
keys = [...keys, e.key].slice(-10);
106107
resetKeys();
107108
}

src/lib/commandCenter/commands.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,11 @@ const commandsEnabled = derived(disabledMap, ($disabledMap) => {
100100
return Array.from($disabledMap.values()).every((disabled) => !disabled);
101101
});
102102

103-
function isInputEvent(event: KeyboardEvent) {
104-
return ['INPUT', 'TEXTAREA', 'SELECT'].includes((event.target as HTMLElement).tagName);
103+
export function isTargetInputLike(element: EventTarget | null) {
104+
if (!(element instanceof HTMLElement)) return false;
105+
return !!element.closest(
106+
'input,textarea,select,[contenteditable],[role="combobox"],[role="textbox"],[role="searchbox"],[data-command-center-ignore]'
107+
);
105108
}
106109

107110
function getCommandRank(command: KeyedCommand) {
@@ -204,7 +207,12 @@ export const commandCenterKeyDownHandler = derived(
204207
for (const command of commandsArr) {
205208
if (!isKeyedCommand(command)) continue;
206209
if (!command.forceEnable) {
207-
if (command.disabled || !enabled || isInputEvent(event) || $wizard.show) {
210+
if (
211+
command.disabled ||
212+
!enabled ||
213+
isTargetInputLike(event.target) ||
214+
$wizard.show
215+
) {
208216
continue;
209217
}
210218
}

src/lib/elements/forms/inputSelect.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
helper={error ?? helper}
5757
{required}
5858
state={error ? 'error' : 'default'}
59+
data-command-center-ignore
5960
on:invalid={handleInvalid}
6061
on:input
6162
on:change

0 commit comments

Comments
 (0)