Skip to content

Drop Enter and Space pressed on an element under an Ajax veil - #1995

Merged
reiern70 merged 2 commits into
masterfrom
veil-keyboard-1943
Nov 24, 2026
Merged

reiern70 merged 2 commits into
masterfrom
veil-keyboard-1943

Conversation

@reiern70

@reiern70 reiern70 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1943

The page and local veils are transparent divs that block only the mouse. The focus stays on the element under the veil, so Enter or Space pressed again on a focused button activated it once more, and Enter in a text field submitted its form again: the request waited in the channel's queue and was sent as soon as the first one was done. An AjaxButton whose onSubmit takes a while ran twice when pressed twice from the keyboard, which is what the veil is there to prevent, and what a double click with the mouse does not do.

What it does now

  • While a veil is up, Wicket.Veil drops, in the capturing phase on the window, the keydown of Enter and Space whose target it covers: any element for the page veil, the elements inside its host for a local veil. The keyup of a dropped key is dropped too, even when the veil has come down meanwhile.
  • Keys that type text are left alone: Space in a text field or a select, both keys in a textarea or in editable content, and any key during an IME composition.
  • Other keys, Tab among them, are not touched, so the focus can still move. A key pressed before the veil came up is released as usual.
  • The javadoc of AbstractVeilBehavior, the script's header and the veil section of the user guide (ajax_12.adoc) say so.

Making the veiled content inert would block the keyboard as well, but the page veil is a child of body, so every other child of body would have to be made inert, and inert content loses the focus and is hidden from assistive technologies while the request runs.

What applications see

A listener reacting to Enter or Space on a covered element while a request runs no longer gets those key events until the veil is lowered. Space no longer scrolls the page while the page veil is up. Other key events are unchanged. No API change, nothing to migrate.

Backport

To wicket-11.x in #2001, a clean cherry-pick. wicket-10.x has no veil.

Tests

  • Six new QUnit tests in veil-test.js; four of them fail without the fix. The file is now wrapped in a function like the newer test scripts, which re-indents it (git diff -w shows the real change).
  • VeilPage gets a form whose Save takes two seconds. VeilPageSeleniumTest presses Enter twice and Space twice on it, and types into its field under the veil, with real key presses through WebDriver. Without the fix the six new cases fail in Chrome and Firefox (two saves instead of one).
  • VeilPageSeleniumTest can now drive Firefox (-Dwicket.selenium.browser=firefox -Dwicket.selenium.firefox=<binary>), and waits for the page's own requests before switching the Ajax engine, which Firefox otherwise found under the veil. All 30 cases pass in Chrome and Firefox.
  • mvn clean verify -Pjs-test is green.

The page and local veils were transparent divs that blocked only the
mouse. The focus stayed on the element under the veil, so Enter or Space
pressed again on a focused button activated it once more, and Enter in a
text field submitted its form again: the request waited in the channel's
queue and was sent as soon as the first one was done. An AjaxButton whose
onSubmit takes a while ran twice when pressed twice from the keyboard,
which is what the veil is there to prevent, and what a double click with
the mouse did not do.

While a veil is up, Wicket.Veil now drops, in the capturing phase on the
window, the keydown of Enter and Space whose target it covers: any element
for the page veil, the elements inside its host for a local veil. The
keyup of a key it dropped is dropped too, even when the veil has come
down meanwhile. Keys that type text are left alone: Space in a text field
or a select, both keys in a textarea or in editable content, and any key
during an IME composition. Other keys, Tab among them, are not touched,
so the focus can still move, and a key pressed before the veil came up is
released as usual.

Making the veiled content inert would block the keyboard as well, but the
page veil is a child of the body, so every other child of the body would
have to be made inert, and inert content loses the focus and is hidden
from assistive technologies while the request runs.

An application that relied on the keyboard under a veil, a listener
reacting to Enter or Space while a request runs for example, no longer
gets those key events for the covered elements until the veil is lowered;
its other key events are unchanged.

VeilPage gets a form whose Save takes two seconds, and
VeilPageSeleniumTest presses Enter and Space on it twice and types into
its field under the veil with real key presses. The test can now drive
Firefox too, with -Dwicket.selenium.browser=firefox, and waits for the
page's own requests to be over before switching the Ajax engine, as
Firefox otherwise finds the switch under the veil. veil-test.js is
wrapped in a function like the newer test scripts, which re-indents it.

GitHub issue #1943
@codecov-commenter

codecov-commenter commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.06%. Comparing base (c7a21a5) to head (4fae51a).
⚠️ Report is 9 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1995      +/-   ##
============================================
+ Coverage     62.99%   63.06%   +0.07%     
- Complexity    11662    11690      +28     
============================================
  Files          1255     1255              
  Lines         48864    48917      +53     
  Branches       6910     6921      +11     
============================================
+ Hits          30783    30851      +68     
+ Misses        15397    15386      -11     
+ Partials       2684     2680       -4     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@papegaaij papegaaij left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Three bugs (shadow DOM, key auto-repeat, the QUnit assertions) and a few nits inline.

… a veil

Review of the keyboard handling of Wicket.Veil found these problems:

- A listener on the window sees a keydown from inside a shadow root
  retargeted to the shadow host, so a text field in a web component was
  classified by the tag name of its host, and Space was dropped in it
  under the veil: typing "a b" gave "ab". A key is now classified by the
  first element of the event's composed path, which is the field itself
  in an open shadow root.
- The dropped keys were recorded on every keydown, auto-repeats included.
  Enter held on a button whose click raises the veil had its repeats
  dropped and recorded, so its keyup was dropped too, and a listener
  pairing keydown and keyup saw Enter still down. Space dropped under the
  veil and still held when the veil came down had its record removed by
  the next repeat, so its keyup passed and clicked the button. The first
  keydown of a press now decides on its release, and its repeats follow
  it: they are dropped when it was dropped, and otherwise only while the
  element is veiled.
- Safari sends the Enter that commits an IME composition after
  compositionend, with isComposing already false. It is recognised by its
  keyCode 229 now.
- A key sent to the window while only a local veil was up threw a
  TypeError from Node.contains(). Tag names are compared in lower case,
  so the fields of a document served as XHTML are recognised too.

The QUnit tests checked that a key reached its element and was not
cancelled in one boolean, so they still passed with preventDefault() or
stopImmediatePropagation() removed from drop(). They check both apart
now, and new tests cover held keys, a field and a button in a shadow
root, the Enter with keyCode 229 and a key sent to the window.

An application now gets Space typed into a text field of a web component
under the veil, and the release of a key held since before the veil came
up.

GitHub issue #1943
@reiern70
reiern70 requested a review from papegaaij November 23, 2026 21:35
@reiern70
reiern70 merged commit 4fef590 into master Nov 24, 2026
3 checks passed
@reiern70
reiern70 deleted the veil-keyboard-1943 branch November 24, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PageVeilBehavior: Enter or Space pressed twice on a focused button sends two requests

3 participants