Skip to content
TypeScript

fix(web): Cmd+Enter creates the new project while an option is highlighted (#18901)

Dara Adedeji446be6933f4e
diff --git a/apps/web/src/components/CommandPalette.tsx b/apps/web/src/components/CommandPalette.tsx
index 7280f7457ba..6596e451e3f 100644
--- a/apps/web/src/components/CommandPalette.tsx
+++ b/apps/web/src/components/CommandPalette.tsx
@@ -3072,6 +3072,10 @@ function OpenCommandPaletteDialog(props: {
? "Create & Add"
: "Add";
const addShortcutLabel = hasHighlightedBrowseItem ? `${submitModifierLabel} Enter` : "Enter";
+ const hasHighlightedNewProjectItem = newProjectFlow !== null && highlightedItemValue !== null;
+ const createShortcutLabel = hasHighlightedNewProjectItem
+ ? `${submitModifierLabel} Enter`
+ : "Enter";
const remoteProjectButtonLabel = addProjectCloneFlow
? addProjectCloneFlow.source === "url"
? "Continue"
@@ -3165,15 +3169,17 @@ function OpenCommandPaletteDialog(props: {
}
// Enter creates the project unless an item below the name is
- // highlighted, in which case it runs that item.
+ // highlighted, in which case it runs that item. Mod+Enter always creates.
if (
newProjectFlow !== null &&
event.key === "Enter" &&
- highlightedItemValue === null &&
+ (!hasHighlightedNewProjectItem || isPrimaryModifierPressed(event)) &&
// Enter that confirms an IME composition is part of typing the name.
!event.nativeEvent.isComposing &&
event.keyCode !== 229
) {
+ // Base UI would otherwise also click the highlighted row.
+ (event as typeof event & { preventBaseUIHandler?: () => void }).preventBaseUIHandler?.();
event.preventDefault();
void submitNewProject();
return;
@@ -3383,7 +3389,7 @@ function OpenCommandPaletteDialog(props: {
size="xs"
tabIndex={-1}
className="absolute inset-e-2.5 top-1/2 -translate-y-1/2"
- aria-label="Create (Enter)"
+ aria-label={`Create (${createShortcutLabel})`}
disabled={!canSubmitNewProject}
onMouseDown={(event) => {
event.preventDefault();
@@ -3396,10 +3402,10 @@ function OpenCommandPaletteDialog(props: {
>
<span>{isCreatingNewProject ? "Creating" : "Create"}</span>
<KbdGroup className="pointer-events-none -me-0.5">
- <Kbd>Enter</Kbd>
+ <Kbd>{createShortcutLabel}</Kbd>
</KbdGroup>
</TooltipTrigger>
- <TooltipPopup side="top">Create (Enter)</TooltipPopup>
+ <TooltipPopup side="top">{`Create (${createShortcutLabel})`}</TooltipPopup>
</Tooltip>
) : addProjectCloneFlow?.step === "repository" ? (
<Tooltip>
@@ -3512,8 +3518,9 @@ function OpenCommandPaletteDialog(props: {
inputProps={{
// The submit button is absolutely positioned over the field, so the
// inner input must reserve enough room for the full action label.
- className:
- addProjectCloneFlow?.step === "repository" || newProjectFlow !== null
+ className: hasHighlightedNewProjectItem
+ ? "*:data-[slot=autocomplete-input]:pe-38!"
+ : addProjectCloneFlow?.step === "repository" || newProjectFlow !== null
? "*:data-[slot=autocomplete-input]:pe-32!"
: isBrowsing
? browseInputEndPaddingClass({