Repository navigation
Close modal dialogs on Escape and keep feedback submit on the page - #4875
Merged
Merged
Conversation
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]>
Contributor
Docs preview (local build)Handbook preview: https://docs-v3-preview.elastic.dev/elastic/docs-builder/pull/4875/ Sample changed pages: |
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]>
No content change. The review runs on each push. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…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
enabled auto-merge (squash)
November 17, 2026 09:42
akira28
disabled auto-merge
November 17, 2026 09:49
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 thedocumentcapture 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 localdocs-builder servehas no header script, so the bug never showed there.Separately,
hx-booston the body boosts every form the server renders. htmx's handler runs before the feedback script'spreventDefault(), so a submit also sentGET ?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.tslistens for Escape onwindow. When the key event is over, the key was prevented, and a modal dialog is still open, it asks that dialog to close: acancelevent, thenclose(). Nothing is stopped while the event runs, so other handlers see the key as before. A dialog stays open by cancelling itscancelevent, 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
keydownhandler 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.cshtmlmarks the formhx-boost="false", so submitting it only sends thePUT. The one affected snapshot changes by that attribute.Guidance for the next dialog and form
src/Elastic.Documentation.Site/AGENTS.mdgets two rules: open a modal withshowModal()and do not handle Escape, and give a form that script submitshx-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 addhx-boost="false"to them. The Ask AI form is the likelier one to need it.Verify
To see the Escape bug locally, add
<div id="elastic-nav"></div>to a page, loadhttps://www.elastic.co/elastic-nav.js, open any dialog and press Escape.Check on the preview
🤖 Generated with Claude Code