#4603·rsuite

`useDialog` dialogs ignore Enter (confirm) and Escape (cancel)

Author: welkinwongCreated Sep 26, 2026Updated Sep 26, 2026

What version of rsuite are you using?

6.2.4

What version of React are you using?

19.x

What version of TypeScript are you using (if any)?

5.x / 6.x

What browser are you using?

Chrome, Safari

Describe the Bug

Dialogs opened with useDialog() (alert, confirm, and prompt) no longer respond to the keyboard:

  • Enter does not activate the OK / confirm action on alert and confirm.
  • Escape does not cancel or close alert, confirm, or prompt.

This used to work. The only way to dismiss these dialogs now is to click a footer button. backdrop is "static" and the header close button is hidden, so there is no other dismiss path.

Modal itself still closes on Escape when the caller passes onClose (keyboard defaults to true). The regression is specific to the built-in dialog used by useDialog.

prompt still confirms on Enter while the text input is focused, because that input has its own onKeyDown. Escape still does nothing on a prompt.

Expected Behavior

Match the usual alert-dialog keyboard interaction (and the previous behavior):

Dialog Enter Escape
confirm Resolve true and close (same as OK) Resolve false and close (same as Cancel)
alert Close (same as OK) Close
prompt Submit the input value (already works when the input is focused) Cancel without submitting, same as Cancel

Enter should not be stolen from a textarea (newline). Escape should only close the top-most dialog when several are open.

To Reproduce

typescript
import { CustomProvider, Button, useDialog } from 'rsuite';
import 'rsuite/dist/rsuite.min.css';

function Demo() {
  const dialog = useDialog();

  return (
    <Button
      appearance="primary"
      onClick={async () => {
        const ok = await dialog.confirm('Delete this item?');
        console.log('result', ok);
      }}
    >
      Open confirm
    </Button>
  );
}

export default function App() {
  return (
    <CustomProvider>
      <Demo />
    </CustomProvider>
  );
}
  1. Click Open confirm.
  2. Press Enter. The dialog stays open and the promise does not resolve.
  3. Press Escape. The dialog stays open.
  4. Click OK (resolves true) or Cancel (resolves false) to dismiss it.

The same Escape failure happens with dialog.alert() and dialog.prompt(). Enter on dialog.alert() also does nothing.

Cause

In src/useDialog/Dialog.tsx ([email protected]):

  1. Escape. onClose is destructured off the props and never forwarded to <Modal>. The overlay listens for Escape (keyboard defaults to true in src/internals/Overlay/Modal) and calls onClose, but that prop is undefined on this Modal, so the key is a no-op. Cancel only runs from the Cancel button (handleClose → handleCancel(false)).

  2. Enter. handleInputKeyDown is attached only to the prompt <Input>. alert and confirm have no Enter handler. The OK button is not type="submit", is not inside a <form>, and is not focused on open. Modal autoFocus moves focus to the dialog container (tabIndex={-1}), not the primary button, so Enter does not activate OK.