Class DisableOnClickController<C extends Component & HasEnabled>

java.lang.Object
com.vaadin.flow.component.shared.internal.DisableOnClickController<C>
Type Parameters:
C - Type of the component that uses this controller.
All Implemented Interfaces:
Serializable

@JsModule("./disableOnClickFunctions.js") public class DisableOnClickController<C extends Component & HasEnabled> extends Object implements Serializable
An internal controller for handling disabling a component when it is clicked. Not intended to be used publicly.

When setDisableOnClick(boolean) is enabled, the component will be immediately disabled upon clicking, both on the client-side and server-side, to prevent multiple clicks or submissions while the server processes the event.

This controller requires that the component implements HasEnabled.

Since:
24.6
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new controller for the given component.
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the mode that determines how long the component stays disabled after it has been disabled on click.
    boolean
    Gets whether the component is currently disabled because it was clicked while disable on click was turned on.
    boolean
    Gets whether the component is set to be disabled when clicked.
    void
    Forces the client-side component's disabled property to be updated before the response is sent to the client, so that it matches the component's effective enabled state, including whether any parent is disabled.
    void
    setDisableOnClick(boolean disableOnClick)
    Sets whether the component should be disabled when clicked.
    void
    Enables disabling the component when clicked, using the given mode to determine how long the component stays disabled.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DisableOnClickController

      public DisableOnClickController(C component)
      Creates a new controller for the given component.
      Parameters:
      component - the component to control, not null
  • Method Details

    • setDisableOnClick

      public void setDisableOnClick(boolean disableOnClick)
      Sets whether the component should be disabled when clicked.

      When set to true, the component will be immediately disabled on the client-side when clicked, preventing further clicks. How long the component stays disabled depends on the current disable on click mode.

      Parameters:
      disableOnClick - whether the component should be disabled when clicked
    • isDisableOnClick

      public boolean isDisableOnClick()
      Gets whether the component is set to be disabled when clicked.
      Returns:
      whether the component is set to be disabled on click
    • setDisableOnClick

      public void setDisableOnClick(DisableOnClickMode mode)
      Enables disabling the component when clicked, using the given mode to determine how long the component stays disabled.
      Parameters:
      mode - the disable on click mode, not null
      Since:
      25.4
      See Also:
    • getDisableOnClickMode

      public DisableOnClickMode getDisableOnClickMode()
      Gets the mode that determines how long the component stays disabled after it has been disabled on click.
      Returns:
      the disable on click mode, not null
      Since:
      25.4
    • isDisabledByClick

      public boolean isDisabledByClick()
      Gets whether the component is currently disabled because it was clicked while disable on click was turned on. This is no longer the case once the enabled state is set by application code, or the component is enabled again automatically.
      Returns:
      whether the component was disabled by disable on click and has not been enabled or disabled explicitly since
      Since:
      25.4
    • onSetEnabled

      public void onSetEnabled()
      Forces the client-side component's disabled property to be updated before the response is sent to the client, so that it matches the component's effective enabled state, including whether any parent is disabled.

      This method should be called from the component's HasEnabled.setEnabled(boolean) method, after the enabled state has been updated.

      Since:
      25.2.7