Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

fix(web): a menu opened by a click lights no row until one is picked

Dev jacobf227d593d8c8
diff --git a/desktop/lib/web/footer/web_footer_bar.dart b/desktop/lib/web/footer/web_footer_bar.dart
index 958f1954f..0defc190c 100644
--- a/desktop/lib/web/footer/web_footer_bar.dart
+++ b/desktop/lib/web/footer/web_footer_bar.dart
@@ -68,6 +68,8 @@ class WebFooterBar extends StatelessWidget {
if (position == null) return;
final choice = await showPaneMenu<WorkspaceFooterItem>(
context: context,
+ // Opened by a click: no row is lit until the pointer picks one.
+ focusFirst: false,
position: position,
minWidth: 260,
maxWidth: 360,
diff --git a/desktop/lib/web/shell/web_app_menu.dart b/desktop/lib/web/shell/web_app_menu.dart
index 6624a57cd..25c2e8f3c 100644
--- a/desktop/lib/web/shell/web_app_menu.dart
+++ b/desktop/lib/web/shell/web_app_menu.dart
@@ -74,6 +74,8 @@ class WebAppMenuButton extends StatelessWidget {
);
final chosen = await showPaneMenu<String>(
context: context,
+ // Opened by a click: no row is lit until the pointer picks one.
+ focusFirst: false,
position: RelativeRect.fromLTRB(
origin.dx,
origin.dy + box.size.height + 6,
diff --git a/desktop/lib/web/tabs/web_tab_switcher.dart b/desktop/lib/web/tabs/web_tab_switcher.dart
index dcafc2d27..99efbefe0 100644
--- a/desktop/lib/web/tabs/web_tab_switcher.dart
+++ b/desktop/lib/web/tabs/web_tab_switcher.dart
@@ -92,6 +92,8 @@ class WebTabSwitcher extends StatelessWidget {
if (position == null) return;
final choice = await showPaneMenu<WebTabChoice>(
context: context,
+ // Opened by a click: no row is lit until the pointer picks one.
+ focusFirst: false,
position: position,
minWidth: 260,
maxWidth: 360,
diff --git a/desktop/lib/widgets/pane_menu.dart b/desktop/lib/widgets/pane_menu.dart
index 0cd8a1e7c..05aae2119 100644
--- a/desktop/lib/widgets/pane_menu.dart
+++ b/desktop/lib/widgets/pane_menu.dart
@@ -29,6 +29,10 @@ import 'transient_menus.dart';
///
/// [onOpen] hands the caller the entry and its closer, for a menu that wants to redraw itself
/// while open or to be closed from outside; [onClose] runs once, however the menu ended.
+///
+/// [focusFirst] highlights the first row as the menu opens, for a menu a key opened: Return takes
+/// it. A menu a click opened passes false — the pointer picks the row, and arrows still start at
+/// the first one.
Future<T?> showPaneMenu<T>({
required BuildContext context,
required RelativeRect position,
@@ -37,6 +41,7 @@ Future<T?> showPaneMenu<T>({
void Function(OverlayEntry entry, void Function() close)? onOpen,
VoidCallback? onClose,
bool Function()? shouldRestoreFocus,
+ bool focusFirst = true,
double minWidth = 340,
double maxWidth = 540,
}) {
@@ -84,6 +89,7 @@ Future<T?> showPaneMenu<T>({
delegate: _PaneMenuPosition(position, minWidth, maxWidth),
child: _PaneMenuFocus(
close: () => close(null),
+ focusFirst: focusFirst,
// A row list sizes itself to its widest row ([IntrinsicWidth]) and scrolls as one
// column. A BODY does neither: it is handed the menu's box and lays itself out, which
// is what a panel with something pinned above and below a scrolling middle needs.
@@ -178,8 +184,13 @@ class _PaneMenuPosition extends SingleChildLayoutDelegate {
}
class _PaneMenuFocus extends StatefulWidget {
- const _PaneMenuFocus({required this.close, required this.child});
+ const _PaneMenuFocus({
+ required this.close,
+ required this.focusFirst,
+ required this.child,
+ });
final VoidCallback close;
+ final bool focusFirst;
final Widget child;
@override
@@ -193,7 +204,10 @@ class _PaneMenuFocusState extends State<_PaneMenuFocus> {
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
- if (mounted) _scope.nextFocus();
+ if (!mounted) return;
+ // Either way the menu takes the keyboard — Escape and the arrows are
+ // its own — but only [focusFirst] lights a row before one is asked for.
+ widget.focusFirst ? _scope.nextFocus() : _scope.requestFocus();
});
}
diff --git a/desktop/test/web/web_app_menu_test.dart b/desktop/test/web/web_app_menu_test.dart
index 4f9c50e0c..f9bd46c34 100644
--- a/desktop/test/web/web_app_menu_test.dart
+++ b/desktop/test/web/web_app_menu_test.dart
@@ -70,6 +70,27 @@ void main() {
app.dispose();
});
+ testWidgets('the menu opens with no row lit; keys still walk and close it', (
+ tester,
+ ) async {
+ final app = await _mount(tester);
+ await _openMenu(tester);
+ bool lit(String id) =>
+ Focus.of(tester.element(find.byKey(ValueKey('web-menu:$id'))))
+ .hasPrimaryFocus;
+ // Opened by a click: the pointer picks the row, so none starts lit.
+ expect(lit('machines.list'), isFalse);
+ await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
+ await tester.pump();
+ expect(lit('machines.list'), isTrue);
+ await tester.sendKeyEvent(LogicalKeyboardKey.escape);
+ await tester.pump(const Duration(milliseconds: 100));
+ expect(find.byKey(const ValueKey('web-menu:machines.list')), findsNothing);
+ expect(tester.takeException(), isNull);
+ await tester.pumpWidget(const SizedBox.shrink());
+ app.dispose();
+ });
+
testWidgets('an empty tab opens New harness on a connected machine', (
tester,
) async {