Skip to content

Close modal dialogs on Escape and keep feedback submit on the page - #4875

Merged
akira28 merged 7 commits into
mainfrom
fix/api-beta-banner-modal-escape
Nov 17, 2026
Merged

akira28 merged 7 commits into
mainfrom
fix/api-beta-banner-modal-escape

Conversation

@akira28

@akira28 akira28 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Modal dialogs now close on Escape on assembled sites, and submitting the design-system feedback form no longer navigates the page. The Escape fix covers every modal <dialog>, not only the banner's.

Affects: Site UI, API reference

Prompt summary: Escape does not close the feedback dialog that #4867 added to the API beta banner. If the cause is common, fix it for every case. Also fix the second bug found along the way, where submitting the feedback form changes the page.

Why

A modal dialog closes on Escape because the browser runs a default action after the keydown, and any handler that calls preventDefault() cancels it. The elastic.co header script (elastic-nav.js), which assembled sites load, prevents every Escape at the document capture phase. So no modal dialog on those sites closed: the banner's, the flyouts, the table and code-preview dialogs, search and Ask AI. Only the code preview had a workaround. A local docs-builder serve has no header script, so the bug never showed there.

Separately, hx-boost on the body boosts every form the server renders. htmx's handler runs before the feedback script's preventDefault(), so a submit also sent GET ?reason=… and swapped the page in. The URL changed and the thank-you message was lost. The page's own widget did this too, and in the banner's dialog the swap replaced the banner and closed the dialog.

What

One handler restores Escape for every modal dialog

Assets/runtime/modal-escape.ts listens for Escape on window. When the key event is over, the key was prevented, and a modal dialog is still open, it asks that dialog to close: a cancel event, then close(). Nothing is stopped while the event runs, so other handlers see the key as before. A dialog stays open by cancelling its cancel event, as the platform intends. Both bundles bind it next to the htmx hooks.

The workarounds go

The banner's own Escape listener and the code preview's keydown handler are removed, together with their tests. The shared handler has its own tests, including focus on <body>, two open dialogs, a held key and IME composition.

The feedback form is no longer boosted

_Feedback.cshtml marks the form hx-boost="false", so submitting it only sends the PUT. The one affected snapshot changes by that attribute.

Guidance for the next dialog and form

src/Elastic.Documentation.Site/AGENTS.md gets two rules: open a modal with showModal() and do not handle Escape, and give a form that script submits hx-boost="false".

Out of scope: the Ask AI form (data-ask-ai-form) and the search-page form (data-search-page-form) are also submitted by script. I could not check them on a normal page, so I did not add hx-boost="false" to them. The Ask AI form is the likelier one to need it.

Verify

mise run site:test
# modal-escape.test.ts — Escape closes a modal dialog the page prevented the key for, with focus inside or outside it
mise run test
# ApiBetaBannerTests — the design-system dialog's form carries hx-boost="false"
FEATURE_NAVIGATION_PREVIEW=true FEATURE_PAGE_FEEDBACK=true mise run serve
# open a docs page, answer the feedback widget and submit: the URL stays put and "Thank you" shows

To see the Escape bug locally, add <div id="elastic-nav"></div> to a page, load https://www.elastic.co/elastic-nav.js, open any dialog and press Escape.

Check on the preview

  • Elasticsearch API overview — click "let us know", then press Escape: the dialog closes, also after clicking in its text.
  • Elasticsearch: Search — open a code preview from an example card and press Escape: it closes, with the shared handler now doing what its own handler did.
  • Docs home — control page: nothing changes.

🤖 Generated with Claude Code

The elastic.co header prevents the Escape keydown on assembled sites, so
the browser never closed the dialog. The banner now closes it from a
capturing `keydown` listener on `window`, wherever focus is, and keeps
the key from the header's handlers.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@akira28
akira28 requested a review from a team as a code owner November 16, 2026 15:57
@akira28
akira28 requested a review from theletterf November 16, 2026 15:57
@akira28 akira28 added the bug label Nov 16, 2026
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

The elastic.co header prevents the Escape keydown on assembled sites, so
no modal dialog closed. One handler now restores the closing for all of
them, and the banner and carousel workarounds go. The design-system
feedback form is no longer boosted by htmx, which sent a GET with the
reasons in the query string and swapped the page in.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@akira28 akira28 changed the title Close the API beta banner's dialog on Escape Close modal dialogs on Escape and keep feedback submit on the page Nov 16, 2026
akira28 and others added 2 commits November 17, 2026 08:58
No content change. The review runs on each push.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
akira28 and others added 2 commits November 17, 2026 10:28
…alog

With focus on the body, the handler picked the last open dialog in
document order, which is not the top of the layer when dialogs open in
another order. It now records the order in which dialogs open.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…/docs-builder into fix/api-beta-banner-modal-escape
A close and a reopen in one task reach the observer as two records that
both see the dialog open, so the dialog kept its old place in the order.
The observer now keeps the old attribute value of each change and counts
every opening.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@akira28
akira28 requested a review from reakaleek November 17, 2026 09:41
@akira28
akira28 enabled auto-merge (squash) November 17, 2026 09:42
@akira28
akira28 disabled auto-merge November 17, 2026 09:49
@akira28
akira28 merged commit c2f756a into main Nov 17, 2026
44 checks passed
@akira28
akira28 deleted the fix/api-beta-banner-modal-escape branch November 17, 2026 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant