Skip to content

fix: dismiss PromptField completion popover on Escape - #11082

Open
yihuiliao wants to merge 4 commits into
mainfrom
promptfield-popover-bug
Open

yihuiliao wants to merge 4 commits into
mainfrom
promptfield-popover-bug

Conversation

@yihuiliao

@yihuiliao yihuiliao commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

#11029

Summary

In PromptTokenField, pressing Escape does not close the completion popover. PromptTokenFieldPopover controls isOpen, but does not pass onOpenChange to <Popover>.

This change passes onOpenChange to <Popover> in PromptTokenFieldPopover and stores a dismissed state ({segments, key}):

  • When the user presses Escape, the popover closes. The typed text and focus stay in the field.
  • Caret-only moves inside the same trigger keep the popover closed.
  • Text edits, trigger anchor changes, or blur clear dismissed and allow the popover to open again.

📝 Test Instructions

  1. Open a PromptField story.
  2. Focus the field and type @ne. Verify that the completion menu opens.
  3. Press Escape. Verify that the menu closes, @ne stays in the field, and focus stays in the field.
  4. Move the caret with Left/Right Arrow inside @ne. Verify that the menu stays closed.
  5. Type or delete a character. Verify that the menu opens again.

Release impact

  • Only changes docs, tests, CI, or development tools. Nothing shipped to users changes.
  • Fixes a bug or improves existing code without changing how apps use it.
  • Adds a feature or API while keeping existing usage working.
  • May break existing usage or require changes in apps that use this code.

✅ PR Checklist

  • I followed the contributing guide.
  • I tested this change locally and included the results in Test Instructions, or explained why testing does not apply.
  • I understand and can explain every change in this PR. If I used AI assistance, I followed the AI contribution guidance.

🧢 Your Project

@yihuiliao yihuiliao changed the title fix: dismiss PromptField comletion popover on Escape fix: dismiss PromptField completion popover on Escape Dec 4, 2026
@rspbot

rspbot commented Dec 4, 2026

Copy link
Copy Markdown

role="presentation"
onKeyDown={onKeyDownProp}
onKeyUp={onKeyUpProp}
style={{width: '100%'}}>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this is only obvious if you have scrollbars turned on, but if you shift+enter until you hit the max height, the width of the input is actually super small and grows as you type which looks weird

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could do style({flexGrow: 1, minWidth: 0}) here and remove the flexGrow: 1 from the TokenField.

@rspbot

rspbot commented Dec 4, 2026

Copy link
Copy Markdown

@yihuiliao
yihuiliao marked this pull request as ready for review December 4, 2026 19:31
@rspbot

rspbot commented Dec 4, 2026

Copy link
Copy Markdown

@rspbot

rspbot commented Dec 4, 2026

Copy link
Copy Markdown

Agent Skills Changes

Modified (10)
Install

React Spectrum S2:

npx skills add https://d1pzu54gtk2aed.cloudfront.net/pr/4b4be89124eabf4930951378d35929a8e1eede62/

React Aria:

npx skills add https://d5iwopk28bdhl.cloudfront.net/pr/4b4be89124eabf4930951378d35929a8e1eede62/

} | null>(null);
if (
dismissed != null &&
(!isFocused || dismissed.segments !== prompt.segments || dismissed.key !== key)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: we can compute isDismissed above to avoid duplicating this.

<Popover
triggerRef={inputRef}
isOpen={isOpen}
onOpenChange={open => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In useCloseOnScroll, can we add:

(target instanceof HTMLElement && target.isContentEditable)

as a condition to the early return, so it won't close the popover if it opens while you're scrolled away and start typing @.

expect(onKeyDown).not.toHaveBeenCalled();
});

describe('dismissing completions with Escape', () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get one more test verifying that Escape:

  • doesn't propagate to PromptTokenField's onKeyDown while the completion menu is open
  • does propagate on a subsequent Escape once the menu is dismissed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants