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

Open
#1,943 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
74/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java, javascript

Research direction

Start by reading wicket-veil.js and the PageVeilBehavior and LocalVeilBehavior implementations named in the issue. Trace how the page and local veils handle keyboard events, then check the existing tests for those behaviors. Done means repeated Enter or Space presses on covered controls do not send duplicate requests, while text entry, editable content, and IME composition remain unaffected.

Written by the indexing model from the issue text.

Description

Affects: 11.0.0 and current master
Component: wicket-extensions, PageVeilBehavior, LocalVeilBehavior, wicket-veil.js

What happens

A page with PageVeilBehavior and a form with an AjaxButton whose onSubmit takes a while:

add(new PageVeilBehavior());
form.add(new AjaxButton("save") {
    @Override
    protected void onSubmit(AjaxRequestTarget target) {
        runs.incrementAndGet();
        Thread.sleep(2000); // a slow action
    }
});

Focus Save with Tab, press Enter, and press Enter again before the answer comes. onSubmit runs twice. Space pressed twice does the same. Clicking twice with the mouse runs it once, as expected.

Checked with real key presses through WebDriver in Chrome 155 and Firefox 124.

Cause

The veil is a transparent div over the page, and it blocks only the mouse; wicket-veil.js says so itself. The focus stays on the button under the veil, so the second key press activates it. Its request waits on channel 0 and is sent once the first one is done.

Fix proposed

While a veil covers an element, drop the keydown (and its keyup) of Enter and Space whose target it covers:

  • for the page veil, any element;
  • for a local veil, the elements inside its host.

Leave alone the keys that type text:

  • Space in text inputs and selects;
  • Enter in a textarea or editable content;
  • keys during IME composition.

Making the content inert would also block the keyboard. But the page veil is a child of body, so inert would have to go on every other child of body, and it takes the focus away and hides the content from assistive technologies while it lasts.

Workaround

A capturing keydown listener of the application's own, which checks whether a .wicket-veil is in the page.

Related: #1631, #1942. Found while working on reiern70/advanced-widgets#141.

Dominant language
Java
Stars
800
Forks
437
Avg merge
21h 36m
Merged PRs (30d)
167

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/wicket

All issues in apache/wicket

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.