Skip to content

Drop Enter and Space pressed on an element under an Ajax veil (11.x) - #2001

Merged
reiern70 merged 2 commits into
wicket-11.xfrom
veil-keyboard-1943-11.x
Nov 24, 2026
Merged

reiern70 merged 2 commits into
wicket-11.xfrom
veil-keyboard-1943-11.x

Conversation

@reiern70

Copy link
Copy Markdown
Contributor

Backport of #1995 to wicket-11.x, for GitHub issue #1943.

  • 51abd90, a clean cherry-pick of Drop Enter and Space pressed on an element under an Ajax veil #1995: while a page or local veil is up, Enter and Space pressed on an element it covers are dropped, together with their release, so the keyboard can no longer activate a button or submit a form under the veil a second time. Keys that type text pass, and other keys, Tab included, are untouched. The veil example gets a keyboard form, and VeilPageSeleniumTest presses the keys for real and can drive Firefox.

No API change, nothing to migrate. Under a veil, Enter and Space no longer reach covered elements until it is lowered.

Verified on this branch:

  • mvn clean verify -Pjs-test is green, japicmp included.

This goes in after #1995. If #1995 changes in review, this branch gets the same change.

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
… 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

Copy link
Copy Markdown
Contributor Author

Mirrored the review changes of #1995 here: 1cf36b1 is a clean cherry-pick of 4fae51a.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.70%. Comparing base (6014597) to head (1cf36b1).

Additional details and impacted files
@@                Coverage Diff                @@
##             wicket-11.x    #2001      +/-   ##
=================================================
- Coverage          62.71%   62.70%   -0.01%     
+ Complexity         11510    11507       -3     
=================================================
  Files               1254     1254              
  Lines              48665    48665              
  Branches            6845     6845              
=================================================
- Hits               30519    30516       -3     
- Misses             15471    15472       +1     
- Partials            2675     2677       +2     
🚀 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.

@reiern70
reiern70 merged commit 8d52d3c into wicket-11.x Nov 24, 2026
3 checks passed
@reiern70
reiern70 deleted the veil-keyboard-1943-11.x branch November 24, 2026 13:49
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.

2 participants