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

未关闭
#1,943 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
74/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
java, javascript

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Java
星标
800
派生
437
平均合并
21 小时 36 分钟
30 天内合并 PR
167

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/wicket 的其他 Issue

查看 apache/wicket 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。