Skip to content

feat: add mode to disable on click until response is handled - #10030

Open
sissbruecker wants to merge 4 commits into
mainfrom
feat/disable-on-click-until-response
Open

feat: add mode to disable on click until response is handled#10030
sissbruecker wants to merge 4 commits into
mainfrom
feat/disable-on-click-until-response

Conversation

@sissbruecker

@sissbruecker sissbruecker commented Sep 4, 2026

Copy link
Copy Markdown
Member

Description

Closes #1553

PR explanation

Disable on click protects against accidental double clicks, but until now the button stayed disabled until the application enabled it again from a click listener. For the common case, where the button should only be blocked while the server handles the click, that meant extra code in every listener. This adds a mode where the button is enabled again automatically once the click has been handled, so preventing double submits becomes a one-liner.

  • Added DisableOnClickMode with two modes for how long a button stays disabled after it was disabled on click
    • UNTIL_ENABLED is the existing behavior and the default: the button stays disabled until the application enables it again
    • UNTIL_RESPONSE enables the button again automatically once the click has been handled, with the response to the click
  • Added Button.setDisableOnClick(DisableOnClickMode) and Button.getDisableOnClickMode()
  • In UNTIL_RESPONSE mode, a click listener can still decide the final state by calling setEnabled(true) or setEnabled(false), in which case the automatic enabling is skipped for that click
  • Clicks that reach the server in the same round trip after the first one are ignored, so a fast double click runs the listener only once
  • The automatic enabling also works when the click listener detaches the button, for example by closing a dialog, and the button is attached again later, also in another UI after a reload with @PreserveOnRefresh
  • Clarified in the Javadoc that the default mode requires the application to enable the button again
  • Added unit tests for both modes and an integration test view and tests for UNTIL_RESPONSE

Type of change

  • Feature

Note

UNTIL_RESPONSE enables the button with the next response the server sends after the click. If a click listener calls UI.push() while it is still running, that push is the next response and enables the button before the listener has finished. This is documented on the enum constant.

sissbruecker and others added 2 commits September 4, 2026 17:04
Adds DisableOnClickMode with UNTIL_ENABLED (existing behavior, default)
and UNTIL_RESPONSE, which enables the button again before the response
is sent so accidental extra clicks are blocked without re-enabling it
manually. Related to #1553.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Flow drops a beforeClientResponse action if the component is not attached
to the same UI when the response is sent, so the enable scheduled by
UNTIL_RESPONSE was lost when a click listener detached the component and
it was later attached to another UI, for example after a reload with
@PreserveOnRefresh. Register the actions on every attach instead.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

@vaadin-review-bot vaadin-review-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

✅ Nothing to flag — the changes look good.

@sonarqubecloud

sonarqubecloud Bot commented Sep 7, 2026

Copy link
Copy Markdown

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.

setDisableOnClick() isn't enough RFE

2 participants