Skip to content

PromptField: Escape doesn't close the completion menu #11029

Backlog

Description

@samatsea

Provide a general summary of the issue here

In @react-spectrum/ai's PromptTokenField, pressing Escape while the completion menu (from completionTrigger / renderCompletions) is open does nothing. The menu can only be closed by picking an item, deleting the trigger text, or moving focus out of the field.

🤔 Expected Behavior?

Escape closes the open completion menu and leaves the typed text (e.g. @ma) as it is, as in the ARIA combobox pattern. Focus stays in the field, and typing again reopens the menu for the new text.

😯 Current Behavior

The menu stays open after Escape. Escape also doesn't reach the field's onKeyDown prop while the menu is open; it seems to be consumed inside the TokenField/Autocomplete handling, so consumers can't easily add the behavior themselves.

From reading the source (same on main today), PromptTokenFieldPopover derives isOpen only from isFocused, filterAnchor and whether renderCompletions returned items. The Popover is isNonModal with no onOpenChange, so nothing records a dismissal.

StackBlitz Reproduction

Not yet: I couldn't find a PromptField completion example in the docs to fork. A minimal component is in Steps to Reproduce; happy to turn it into a StackBlitz if you can point me to a starting example.

🖥️ Steps to Reproduce

  1. Render a PromptField with a PromptTokenField that has completionTrigger and renderCompletions, for example:
import {PromptField, PromptTokenField, InsertTokenMenuItem} from '@react-spectrum/ai';
import {Text} from '@react-spectrum/s2';

const PEOPLE = ['Maya Lead', 'Sergey Generalov'];

export function Example() {
  return (
    <PromptField>
      <PromptTokenField
        completionTrigger={/@/}
        renderCompletions={(filter) =>
          PEOPLE.filter((name) => name.toLowerCase().includes(filter.slice(1).toLowerCase())).map(
            (name) => (
              <InsertTokenMenuItem
                key={name}
                id={name}
                textValue={name}
                token={{
                  type: 'token',
                  text: name,
                  value: {type: 'custom', anchor: '@', valueType: 'person', data: {}}
                }}>
                <Text slot="label">{name}</Text>
              </InsertTokenMenuItem>
            )
          )
        }
      />
    </PromptField>
  );
}
  1. Focus the field and type @. The completion menu opens.
  2. Press Escape. The menu stays open.

💁 Possible Solution

Track a "dismissed" state in PromptTokenField: Escape with the menu open sets it, keeps focus in the field and doesn't propagate further (so it doesn't also close an enclosing dialog). It clears on the next text change but not on caret-only moves, and PromptTokenFieldPopover treats it as closed.

Two details we hit in our workaround:

  • Clear the dismissal on the first text change rather than comparing with the dismissed text. Otherwise editing back to that same text hides the menu again.
  • Only handle Escape that comes from the text field itself, so menus rendered in the prompt field's toolbar (e.g. an "insert" menu with a submenu) still close normally.

🔦 Context

We use PromptField in Adobe Coworker's chat and group-room composers, where @ lists people and Shared Coworkers to mention. Keyboard users can't dismiss the menu, which is an accessibility problem in multi-person threads that rely on @mentions.

For now we work around it in our wrapper: a capture-phase Escape handler on an ancestor of the field, plus a dismissed-text state that withholds renderCompletions. We'd like to remove that once it's fixed here.

Version

@react-spectrum/ai@0.5.1 (same code in 0.5.2 and on main)
@react-spectrum/s2@1.8.1
react@19.2.6

What browsers are you seeing the problem on?

Chrome

If other, please specify.

No response

What operating system are you using?

macOS

🧢 Your Company/Team

Adobe / Coworker UI

🕷 Tracking Issue

No response

Activity

  1. moved this from 🩺 To Triage to 🔬 To Investigate / Verify in RSP Component Milestoneson Nov 24, 2026
  2. snowystinger commented on Nov 24, 2026

    @snowystinger
    Member

    What would happen if you typed another character after @ma later? would that open it again?

    Also, you can dismiss it by pressing space.
    https://react-spectrum.adobe.com/ai-components

    This example also comes with a link to open it in stackblitz if you need to make adjustments
    Screenshot 2026-11-25 at 10 26 47 am

  3. samatsea commented on Nov 25, 2026

    @samatsea
    Author

    @snowystinger it would work just the same way that @mentions work here in guthub. esc makes the suggestion menu go away, and then if you keep typing characters that map to a suggestion, the suggestion menu reappears. I hear you about space, (github @mentions also do this) but this is missing the esc behavior that is also very common with these sorts of menus.

    Fun fact about this PR/bug/issue is that I work at Adobe too, on AI Harness UX, and was asked to submit here in the spirit of supporting open-source. This gap was cited as an accessibility issue by Adobe's own internal agentic CI/CD pipeline

  4. snowystinger commented on Nov 25, 2026

    @snowystinger
    Member

    Yep, agreed Esc should do something, just solidifying what that is. In the meantime, there is a workaround as well, so users are not blocked on this.

    It looks like Esc in Github works the same as space, just with no new character. Would you like to submit a PR to start an exploration on how we could accomplish this? I'm hopeful it's fairly straightforward. If not, no worries.

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

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions