From ae58a24690ec2a4b522b142947a368c7bed89864 Mon Sep 17 00:00:00 2001 From: Kiet Ho Date: Sun, 29 Mar 2026 12:14:36 -0700 Subject: [PATCH 1/2] Enable Enter on destructive alert dialogs --- .../ProjectSection/CloseProjectDialog.tsx | 7 +- .../FileViewerPane/UnsavedChangesDialog.tsx | 7 +- .../RightSidebar/ChangesView/ChangesView.tsx | 12 ++-- .../DiscardConfirmDialog.tsx | 7 +- .../ui/src/components/ui/alert-dialog.tsx | 31 ++++++-- ...nabled-alert-dialog-primary-action.test.ts | 72 +++++++++++++++++++ ...ter-enabled-alert-dialog-primary-action.ts | 52 ++++++++++++++ 7 files changed, 170 insertions(+), 18 deletions(-) create mode 100644 packages/ui/src/lib/focus-enter-enabled-alert-dialog-primary-action.test.ts create mode 100644 packages/ui/src/lib/focus-enter-enabled-alert-dialog-primary-action.ts diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/ProjectSection/CloseProjectDialog.tsx b/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/ProjectSection/CloseProjectDialog.tsx index 4d5cd2303bf..6e1f11059ca 100644 --- a/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/ProjectSection/CloseProjectDialog.tsx +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/ProjectSection/CloseProjectDialog.tsx @@ -1,10 +1,10 @@ import { AlertDialog, - AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, + EnterEnabledAlertDialogContent, } from "@superset/ui/alert-dialog"; import { Button } from "@superset/ui/button"; @@ -30,7 +30,7 @@ export function CloseProjectDialog({ return ( - + Close project "{projectName}"? @@ -59,6 +59,7 @@ export function CloseProjectDialog({ Cancel - + diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/TabView/FileViewerPane/UnsavedChangesDialog.tsx b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/TabView/FileViewerPane/UnsavedChangesDialog.tsx index 2fc01c985b0..38e9d03ef72 100644 --- a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/TabView/FileViewerPane/UnsavedChangesDialog.tsx +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/TabView/FileViewerPane/UnsavedChangesDialog.tsx @@ -34,16 +34,12 @@ export function UnsavedChangesDialog({ discardLabel = "Discard & Continue", saveLabel = "Save & Continue", }: UnsavedChangesDialogProps) { - const handleSaveAndSwitch = (e: React.MouseEvent) => { - e.preventDefault(); + const handleSaveAndSwitch = () => { onSave(); - // Don't close dialog - parent will close on success }; - const handleDiscardAndSwitch = (e: React.MouseEvent) => { - e.preventDefault(); + const handleDiscardAndSwitch = () => { onDiscard(); - onOpenChange(false); }; return ( @@ -55,16 +51,15 @@ export function UnsavedChangesDialog({ Cancel - - + + diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/RightSidebar/ChangesView/ChangesView.tsx b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/RightSidebar/ChangesView/ChangesView.tsx index d24ad9d03e5..42c5aa2154e 100644 --- a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/RightSidebar/ChangesView/ChangesView.tsx +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/RightSidebar/ChangesView/ChangesView.tsx @@ -1,5 +1,6 @@ import { AlertDialog, + AlertDialogAction, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, @@ -857,20 +858,18 @@ export function ChangesView({ > Cancel - + @@ -898,20 +897,18 @@ export function ChangesView({ > Cancel - + diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/RightSidebar/ChangesView/components/DiscardConfirmDialog/DiscardConfirmDialog.tsx b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/RightSidebar/ChangesView/components/DiscardConfirmDialog/DiscardConfirmDialog.tsx index c17ef011792..2055c5aaf83 100644 --- a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/RightSidebar/ChangesView/components/DiscardConfirmDialog/DiscardConfirmDialog.tsx +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/RightSidebar/ChangesView/components/DiscardConfirmDialog/DiscardConfirmDialog.tsx @@ -1,5 +1,6 @@ import { AlertDialog, + AlertDialogAction, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, @@ -43,19 +44,15 @@ export function DiscardConfirmDialog({ > Cancel - + diff --git a/packages/ui/src/components/ui/alert-dialog.tsx b/packages/ui/src/components/ui/alert-dialog.tsx index ab63ff68526..28bcedd6728 100644 --- a/packages/ui/src/components/ui/alert-dialog.tsx +++ b/packages/ui/src/components/ui/alert-dialog.tsx @@ -1,6 +1,7 @@ "use client"; import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog"; +import type { VariantProps } from "class-variance-authority"; import type * as React from "react"; import { focusEnterEnabledAlertDialogPrimaryAction } from "../../lib/focus-enter-enabled-alert-dialog-primary-action"; @@ -142,11 +143,15 @@ function AlertDialogDescription({ function AlertDialogAction({ className, + size, + variant, ...props -}: React.ComponentProps) { +}: React.ComponentProps & + VariantProps) { return ( ); diff --git a/packages/ui/src/lib/focus-enter-enabled-alert-dialog-primary-action.test.ts b/packages/ui/src/lib/focus-enter-enabled-alert-dialog-primary-action.test.ts index 012b52fac2c..efb22a67770 100644 --- a/packages/ui/src/lib/focus-enter-enabled-alert-dialog-primary-action.test.ts +++ b/packages/ui/src/lib/focus-enter-enabled-alert-dialog-primary-action.test.ts @@ -6,7 +6,7 @@ import { } from "./focus-enter-enabled-alert-dialog-primary-action"; describe("focusEnterEnabledAlertDialogPrimaryAction", () => { - test("focuses the marked primary action and prevents default autofocus", () => { + test("focuses the alert dialog action and prevents default autofocus", () => { let prevented = false; let focused = false; let queriedSelector: string | null = null; diff --git a/packages/ui/src/lib/focus-enter-enabled-alert-dialog-primary-action.ts b/packages/ui/src/lib/focus-enter-enabled-alert-dialog-primary-action.ts index e18aeef0d39..f5ffb8cf87b 100644 --- a/packages/ui/src/lib/focus-enter-enabled-alert-dialog-primary-action.ts +++ b/packages/ui/src/lib/focus-enter-enabled-alert-dialog-primary-action.ts @@ -1,5 +1,5 @@ export const alertDialogPrimaryActionSelector = - "[data-alert-dialog-primary-action]:not([disabled])"; + "[data-slot='alert-dialog-action']:not([disabled])"; interface FocusableLike { focus: () => void;