Modal dialogs: pressing Enter on a focused drop-down clicks the default button instead of opening the list

Open Beginner friendly
#17,591 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript

Research direction

Start with src/vs/workbench/browser/positronComponents/positronModalDialog/useModalDialogKeyboard.tsx and trace how the capture-phase Enter handler interacts with the focused DropDownListBox button. Check the modal keyboard tests and the Save Plot Format control to confirm expected behavior. Done means Enter opens the focused drop-down while Enter on the dialog body still invokes its default action.

Written by the indexing model from the issue text.

Description

area: plots area: ui bug

In a Positron modal dialog, pressing Enter while a drop-down has focus runs the dialog's default action (and closes the dialog) instead of opening the drop-down. Space opens it as expected.

In the Save Plot dialog, this means a keyboard user who tabs to Format and presses Enter to pick a format saves the plot to disk at whatever settings were showing.

Steps to reproduce
  1. Make a plot, e.g. plot(1:10) in R.
  2. Click Save Plot in the Plots pane toolbar.
  3. Press Tab until the Format drop-down has focus.
  4. Press Enter.

Expected: the Format list opens, like it does with Space (and like a native <select> or upstream's select box).

Actual: the dialog closes and the plot is saved.

Cause

useModalDialogKeyboard (src/vs/workbench/browser/positronComponents/positronModalDialog/useModalDialogKeyboard.tsx) handles Enter for dialogs without a <form>: it clicks the first button.default unless the focused element is a textarea or a quick pick. The listener runs in the capture phase on the window (positronModalReactRenderer.tsx), so it consumes Enter before the focused DropDownListBox button sees it.

The same check probably catches any other focused button in these dialogs (for example Cancel or Browse), so Enter on them may also run the default action; this hasn't been verified.

Possible fix

Leave Enter to the focused element when it is itself a button (or a control that handles Enter, such as a drop-down), and only click the default button when focus is on a text input or the dialog body. The longer-term path the code comment describes, moving these dialogs to a <form> with enterHandledByCaller, would also fix it.

Accessibility

Keyboard users expect Enter to activate the focused button (WCAG 2.1.1 Keyboard; APG button pattern). Here it triggers an unrelated, irreversible action: writing a file.

Notes
  • Present on main in the Save Plot dialog's Format drop-down. #2875 adds a second drop-down (Size, for PDF) that behaves the same.
  • Found during exploratory testing of #2875.
  • Related but different: #16339 (Enter doing nothing in the dynamic dialog).
Dominant language
TypeScript
Stars
4.4k
Forks
207
Avg merge
1d 16h
Merged PRs (30d)
308

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from posit-dev/positron

All issues in posit-dev/positron

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.