From 62ae3ce63beb509363fd12682437f5b8d577d753 Mon Sep 17 00:00:00 2001 From: Brian Lambert Date: Fri, 20 Sep 2024 15:22:48 -0700 Subject: [PATCH] Update default modal button handling so that pressing the Enter key clicks the default button in a PositronModalDialog (#4739) --- .../ui/positronComponents/button/button.tsx | 4 ++-- .../button/positronButton.tsx | 7 +++++-- .../positronModalDialog.tsx | 20 +++++++++++++------ .../positronOKModalDialog.tsx | 1 + .../chooseNewProjectWindowModalDialog.tsx | 1 - .../newProjectModalDialog.tsx | 1 - .../browser/positronModalDialogs.tsx | 3 +-- .../modalDialogs/savePlotModalDialog.tsx | 1 - .../modalDialogs/setPlotSizeModalDialog.tsx | 1 - .../deleteAllVariablesModalDialog.tsx | 2 -- 10 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/vs/base/browser/ui/positronComponents/button/button.tsx b/src/vs/base/browser/ui/positronComponents/button/button.tsx index cafbe4e4ce7..8c96bc2f32d 100644 --- a/src/vs/base/browser/ui/positronComponents/button/button.tsx +++ b/src/vs/base/browser/ui/positronComponents/button/button.tsx @@ -82,9 +82,9 @@ export const Button = forwardRef) => { // Process the key down event. switch (e.code) { - // Space or Enter trigger the onPressed event. + // Space triggers the onPressed event. Note: Do not add 'Enter' here. Enter is reserved + // for clicking the default button in modal popups and modal dialogs. case 'Space': - case 'Enter': sendOnPressed(e); break; } diff --git a/src/vs/base/browser/ui/positronComponents/button/positronButton.tsx b/src/vs/base/browser/ui/positronComponents/button/positronButton.tsx index 05521fc633d..9d095da7205 100644 --- a/src/vs/base/browser/ui/positronComponents/button/positronButton.tsx +++ b/src/vs/base/browser/ui/positronComponents/button/positronButton.tsx @@ -52,9 +52,9 @@ export const PositronButton = forwardRef) => { // Process the key down event. switch (e.code) { - // Space or Enter trigger the onPressed event. + // Space triggers the onPressed event. Note: Do not add 'Enter' here. Enter is reserved + // for clicking the default button in modal popups and modal dialogs. case 'Space': - case 'Enter': // Consume the event. e.preventDefault(); e.stopPropagation(); @@ -123,3 +123,6 @@ export const PositronButton = forwardRef ); }); + +// Set the display name. +PositronButton.displayName = 'PositronButton'; diff --git a/src/vs/workbench/browser/positronComponents/positronModalDialog/positronModalDialog.tsx b/src/vs/workbench/browser/positronComponents/positronModalDialog/positronModalDialog.tsx index 8fd0d199717..02e428b2bdf 100644 --- a/src/vs/workbench/browser/positronComponents/positronModalDialog/positronModalDialog.tsx +++ b/src/vs/workbench/browser/positronComponents/positronModalDialog/positronModalDialog.tsx @@ -42,8 +42,6 @@ export interface PositronModalDialogProps { title: string; width: number; height: number; - enterAccepts?: boolean; - onAccept: () => void; onCancel?: () => void; } @@ -112,11 +110,21 @@ export const PositronModalDialog = (props: PropsWithChildren( + 'button.default:not([disabled])' + ); + if (defaultButton) { + consumeEvent(); + defaultButton.click(); } break; } diff --git a/src/vs/workbench/browser/positronComponents/positronModalDialog/positronOKModalDialog.tsx b/src/vs/workbench/browser/positronComponents/positronModalDialog/positronOKModalDialog.tsx index a826463f631..8871843daf5 100644 --- a/src/vs/workbench/browser/positronComponents/positronModalDialog/positronOKModalDialog.tsx +++ b/src/vs/workbench/browser/positronComponents/positronModalDialog/positronOKModalDialog.tsx @@ -20,6 +20,7 @@ import { PositronModalDialog, PositronModalDialogProps } from 'vs/workbench/brow */ export interface OKModalDialogProps extends PositronModalDialogProps { okButtonTitle?: string; + onAccept: () => void; } /** diff --git a/src/vs/workbench/browser/positronNewProjectWizard/chooseNewProjectWindowModalDialog.tsx b/src/vs/workbench/browser/positronNewProjectWizard/chooseNewProjectWindowModalDialog.tsx index 0263ce1f91c..e402fa0c9ef 100644 --- a/src/vs/workbench/browser/positronNewProjectWizard/chooseNewProjectWindowModalDialog.tsx +++ b/src/vs/workbench/browser/positronNewProjectWizard/chooseNewProjectWindowModalDialog.tsx @@ -111,7 +111,6 @@ const ChooseNewProjectWindowModalDialog = (props: ChooseNewProjectWindowModalDia 'positron.chooseNewProjectWindowModalDialog.title', 'Create New Project' ))()} - onAccept={accept} >
diff --git a/src/vs/workbench/browser/positronNewProjectWizard/newProjectModalDialog.tsx b/src/vs/workbench/browser/positronNewProjectWizard/newProjectModalDialog.tsx index 11773386081..0b3c43fc468 100644 --- a/src/vs/workbench/browser/positronNewProjectWizard/newProjectModalDialog.tsx +++ b/src/vs/workbench/browser/positronNewProjectWizard/newProjectModalDialog.tsx @@ -195,7 +195,6 @@ const NewProjectModalDialog = (props: NewProjectModalDialogProps) => { renderer={props.renderer} width={700} height={520} title={(() => localize('positronNewProjectWizard.title', "Create New Project"))()} - onAccept={acceptHandler} onCancel={cancelHandler} > diff --git a/src/vs/workbench/contrib/positronModalDialogs/browser/positronModalDialogs.tsx b/src/vs/workbench/contrib/positronModalDialogs/browser/positronModalDialogs.tsx index 75a832bba93..4d4ba2b8dc6 100644 --- a/src/vs/workbench/contrib/positronModalDialogs/browser/positronModalDialogs.tsx +++ b/src/vs/workbench/contrib/positronModalDialogs/browser/positronModalDialogs.tsx @@ -117,7 +117,7 @@ export class PositronModalDialogs implements IPositronModalDialogsService { }; renderer.render( - + {renderHtml( message, @@ -188,7 +188,6 @@ export class PositronModalDialogs implements IPositronModalDialogsService { title={title} width={400} height={200} - onAccept={acceptHandler} onCancel={cancelHandler} > diff --git a/src/vs/workbench/contrib/positronPlots/browser/modalDialogs/savePlotModalDialog.tsx b/src/vs/workbench/contrib/positronPlots/browser/modalDialogs/savePlotModalDialog.tsx index 6b099091a42..e393021ac63 100644 --- a/src/vs/workbench/contrib/positronPlots/browser/modalDialogs/savePlotModalDialog.tsx +++ b/src/vs/workbench/contrib/positronPlots/browser/modalDialogs/savePlotModalDialog.tsx @@ -282,7 +282,6 @@ const SavePlotModalDialog = (props: SavePlotModalDialogProps) => { width={SAVE_PLOT_MODAL_DIALOG_WIDTH} height={SAVE_PLOT_MODAL_DIALOG_HEIGHT} title={(() => localize('positron.savePlotModalDialog.title', "Save Plot"))()} - onAccept={acceptHandler} onCancel={cancelHandler} renderer={props.renderer}> diff --git a/src/vs/workbench/contrib/positronPlots/browser/modalDialogs/setPlotSizeModalDialog.tsx b/src/vs/workbench/contrib/positronPlots/browser/modalDialogs/setPlotSizeModalDialog.tsx index 0daa620cd5f..05e5e04e3fc 100644 --- a/src/vs/workbench/contrib/positronPlots/browser/modalDialogs/setPlotSizeModalDialog.tsx +++ b/src/vs/workbench/contrib/positronPlots/browser/modalDialogs/setPlotSizeModalDialog.tsx @@ -106,7 +106,6 @@ const SetPlotSizeModalDialog = (props: SetPlotSizeModalDialogProps) => { width={350} height={200} title={(() => localize('positronSetPlotSizeModalDialogTitle', "Custom Plot Size"))()} - onAccept={acceptHandler} onCancel={cancelHandler}> diff --git a/src/vs/workbench/contrib/positronVariables/browser/modalDialogs/deleteAllVariablesModalDialog.tsx b/src/vs/workbench/contrib/positronVariables/browser/modalDialogs/deleteAllVariablesModalDialog.tsx index 3e57dd68886..f0f1c8e2e54 100644 --- a/src/vs/workbench/contrib/positronVariables/browser/modalDialogs/deleteAllVariablesModalDialog.tsx +++ b/src/vs/workbench/contrib/positronVariables/browser/modalDialogs/deleteAllVariablesModalDialog.tsx @@ -58,7 +58,6 @@ export const DeleteAllVariablesModalDialog = (props: DeleteAllVariablesModalDial renderer={props.renderer} width={375} height={175} - enterAccepts={true} title={(() => localize( 'positron.deleteAllVariablesModalDialogTitle', "Delete All Variables" @@ -66,7 +65,6 @@ export const DeleteAllVariablesModalDialog = (props: DeleteAllVariablesModalDial secondaryActionTitle={(() => localize('positron.delete', "Delete"))()} secondaryActionDestructive={true} primaryActionTitle={(() => localize('positron.cancel', "Cancel"))()} - onAccept={cancelHandler} onCancel={cancelHandler} onSecondaryAction={acceptHandler} onPrimaryAction={cancelHandler}