Skip to content

[autocomplete] Option to opt out of Escape clearing the input value #4245

Open

Description

@mirka

Feature request

Summary

When the Autocomplete popup is closed and the user presses Escape, the input value is cleared. Is it possible to opt out of this behavior?

For Autocomplete use cases, the input value is often free-form text (e.g. a URL, an address) where suggestions are helpful but the typed value is the primary content. Clearing it on Escape is unexpected — users typically do not expect Escape to erase their input.

From a glance at the source code, this behavior appears to be inherited from the Combobox implementation.

This makes sense for Combobox, where the input reflects a selected value that should be resettable. This is not always true for Autocomplete use cases that sometimes behave more like normal inputs, where some users won't ever trigger open the suggestions popover. The APG also says that clearing the input is "optional".

A clearOnEscape prop or similar would let consumers preserve the input value.

Examples in other libraries

  • MUI Autocomplete has a clearOnEscape prop (defaults to false).
  • Native <datalist> does not clear the input on Escape.

Motivation

There seems to be a workaround for controlled mode, but not for uncontrolled.

onValueChange={ ( newValue, details ) => {
  if ( details?.reason === 'escapeKey' ) return;
  setValue( newValue );
} }

Activity

  1. added
    status: waiting for maintainer
    on Mar 3, 2026
  2. linear commented on Mar 3, 2026

    @linear
  3. changed the title [-][Autocomplete] Option to opt out of Escape clearing the input value[/-] [+][autocomplete] Option to opt out of Escape clearing the input value[/+] on Mar 3, 2026
  4. added
    component: autocomplete
    on Mar 3, 2026
  5. added
    type: new feature
    has workaround
    and removed
    status: waiting for maintainer
    on Mar 10, 2026
  6. atomiks commented on Mar 10, 2026

    @atomiks
    Contributor

    There seems to be a workaround for controlled mode, but not for uncontrolled.

    The cancel() method should work:

    onValueChange={( newValue, details) => {
      if (details.reason === 'escapeKey') details.cancel();
    }}

    The behavior here was to match the Chrome URL omnibox which clears the value as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: autocompletehas workaroundtype: new feature

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions