Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/lib/commandCenter/commandCenter.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@
import { getContext, setContext } from 'svelte';
import { get, writable, type Readable } from 'svelte/store';
import { fade } from 'svelte/transition';
import { commandCenterKeyDownHandler, disableCommands, registerCommands } from './commands';
import {
commandCenterKeyDownHandler,
disableCommands,
isTargetInputLike,
registerCommands
} from './commands';
import { RootPanel } from './panels';
import { addSubPanel, clearSubPanels, subPanels } from './subPanels';
import { addNotification } from '$lib/stores/notifications';
Expand Down Expand Up @@ -95,13 +100,9 @@
keys = [];
}, 1000);

function isInputEvent(event: KeyboardEvent) {
return ['INPUT', 'TEXTAREA', 'SELECT'].includes((event.target as HTMLElement).tagName);
}

const handleKeydown = (e: KeyboardEvent) => {
if (!$subPanels.length) {
if (isInputEvent(e)) return;
if (isTargetInputLike(e.target)) return;
keys = [...keys, e.key].slice(-10);
resetKeys();
}
Expand Down
14 changes: 11 additions & 3 deletions src/lib/commandCenter/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,11 @@ const commandsEnabled = derived(disabledMap, ($disabledMap) => {
return Array.from($disabledMap.values()).every((disabled) => !disabled);
});

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

function getCommandRank(command: KeyedCommand) {
Expand Down Expand Up @@ -204,7 +207,12 @@ export const commandCenterKeyDownHandler = derived(
for (const command of commandsArr) {
if (!isKeyedCommand(command)) continue;
if (!command.forceEnable) {
if (command.disabled || !enabled || isInputEvent(event) || $wizard.show) {
if (
command.disabled ||
!enabled ||
isTargetInputLike(event.target) ||
$wizard.show
) {
continue;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/elements/forms/inputSelect.svelte
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this not affect every page with input selects and not just wizards?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want shortcuts to trigger when users are interacting with input selects? 🤔

Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
helper={error ?? helper}
{required}
state={error ? 'error' : 'default'}
data-command-center-ignore
on:invalid={handleInvalid}
on:input
on:change
Expand Down