keyboard press stuff

This commit is contained in:
Nate Kelley 2025-09-29 11:38:03 -06:00
parent c3041b548b
commit 8469471a45
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
2 changed files with 16 additions and 13 deletions

View File

@ -95,26 +95,29 @@ export const BusterInput = ({
if (showSuggestionList && (event.key === 'ArrowUp' || event.key === 'ArrowDown')) {
commandListNavigatedRef.current = true;
}
// If Enter is pressed and command list was navigated, manually trigger selection
if (showSuggestionList && event.key === 'Enter' && commandListNavigatedRef.current) {
event.preventDefault();
event.stopPropagation();
// Find the currently selected item and trigger its click
const selectedItem = commandElement?.querySelector('[data-selected="true"]') as HTMLElement;
if (selectedItem) {
selectedItem.click();
}
}
};
const commandElement = commandRef.current;
if (commandElement) {
commandElement.addEventListener('keydown', handleKeyDown);
commandElement.addEventListener('keydown', handleKeyDown, true); // Use capture phase
return () => {
commandElement.removeEventListener('keydown', handleKeyDown);
commandElement.removeEventListener('keydown', handleKeyDown, true);
};
}
}, [showSuggestionList]);
return (
<Command
ref={commandRef}
value={value}
label={ariaLabel}
className="relative"
onValueChange={(v) => {
console.log('onValueChange', v);
}}
>
<Command ref={commandRef} value={value} label={ariaLabel} className="relative">
<BusterInputContainer
onSubmit={onSubmitPreflight}
onStop={onStopPreflight}

View File

@ -15,9 +15,9 @@ export const SubmitOnEnter = ({
addKeyboardShortcuts() {
return {
Enter: ({ editor }) => {
// If command list has been navigated with arrow keys, let the command list handle Enter
// If command list has been navigated, don't handle here - let the parent handle it
if (commandListNavigatedRef?.current) {
return !!onPressEnter; // Let the command list handle this
return !!onPressEnter;
}
// Otherwise, let Tiptap handle the Enter key