Skip to content

Plugin TUI: DialogSelect onSelect not triggered on Enter key #22610

Description

@VespianRex

Description

When a TUI plugin uses api.ui.DialogSelect, pressing Enter does not trigger the onSelect callback. Arrow keys work for navigation, and the visual selection indicator works, but Enter key selection is broken.

Critical Finding

Enter works in all built-in OpenCode dialogs, but NOT in plugin-rendered dialogs. This confirms the bug is specific to the plugin rendering context, not a general keyboard handling issue.

Environment

  • OpenCode version: 1.4.3 (via Homebrew)
  • Terminal: macOS (various terminals tested)
  • Plugin: Custom TUI plugin using api.ui.DialogSelect

Steps to Reproduce

  1. Create a TUI plugin that uses api.ui.DialogSelect with options and onSelect callback
  2. Load the plugin via tui.json
  3. Open the command palette and trigger the plugin
  4. Press Enter to select an option

Expected Behavior

Enter key should trigger onSelect callback with the selected option.

Actual Behavior

  • Enter key does nothing in plugin dialogs
  • Arrow keys work for navigation (up/down changes selection)
  • Visual selection works (highlighted row is visible)
  • Built-in dialogs (model selector, command palette, etc.) work correctly with Enter

Code Example

// Plugin code
api.ui.dialog.replace(() => (
  api.ui.DialogSelect({
    title: "Select Config File",
    options: [
      { title: "Option 1", value: "opt1" },
      { title: "Option 2", value: "opt2" },
    ],
    placeholder: "Choose...",
    onSelect: (option) => {
      console.log("Selected:", option.title);
      // This callback never fires when pressing Enter
    },
  })
));

Investigation Summary

  1. The useKeyboard hook from @opentui/solid is used for key handling
  2. In built-in dialogs, useKeyboard handlers receive all key events including Enter
  3. In plugin dialogs, arrow keys are received but Enter is not
  4. This suggests the plugin rendering context may be intercepting or blocking Enter key events

Root Cause Hypothesis

The issue appears to be in how the plugin API (api.ui.DialogSelect) renders the component. The keyboard event handling chain may be different for plugin-rendered components compared to internal OpenCode components.

Possible causes:

  • Plugin JSX elements are rendered outside the normal SolidJS context
  • Event handlers registered via useKeyboard in plugin context don't receive Enter events
  • Focus management differs between internal and plugin dialogs
  • The InternalKeyHandler.emitWithPriority may not properly route Enter events to plugin components

Workaround Status

No working workaround found. Attempts to use DialogPrompt with onConfirm also failed, suggesting the issue affects all keyboard confirmation events in plugin dialogs.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions