Skip to content

The escape key should close the right click menu on desktop #98163

@justinmc

Description

@justinmc

When the right click menu is open, pressing the escape key should close it. I confirmed that this is the native behavior on Mac and Windows. I assume Linux is the same but I haven't tried.

Steps to reproduce

  1. Run any Flutter app with a text field on a desktop platform (example given below).
  2. Right click on the text field. The context menu shows.
  3. Press the escape key.

Expected: The context menu closes.
Actual: Nothing happens and the context menu remains on the screen.

Solution

We could add a text editing shortcut for this and it should work for now, but if we allow context menus outside of EditableText (as mentioned in #90563), then the Shortcuts widget won't receive the escape when nothing is focused and it won't always work.

@gspencergoog Is it possible to receive a Shortcut when nothing is focused?

Code
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({
    Key? key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Flutter Demo'),
        ),
        body: const Center(
          child: TextField(),
        ),
      ),
    );
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: desktopRunning on desktopa: text inputEntering text in a text field or keyboard related problems

    Type

    No type

    Projects

    Status

    Done (PR merged)

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions