Skip to content

Commit

Permalink
fix: restore disableOnClick attribute (#7071) (#7072)
Browse files Browse the repository at this point in the history
* fix: restore disableOnClick attribute

* rename to disableonclick

Co-authored-by: Sascha Ißbrücker <[email protected]>
  • Loading branch information
vaadin-bot and sissbruecker authored Jan 29, 2025
1 parent 21f763d commit 1c4a2e6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ public DisableOnClickController(C component) {
public void setDisableOnClick(boolean disableOnClick) {
this.disableOnClick = disableOnClick;
if (disableOnClick) {
component.getElement().setProperty("disableOnClick", "true");
component.getElement().setAttribute("disableonclick", "true");
} else {
component.getElement().removeProperty("disableOnClick");
component.getElement().removeAttribute("disableonclick");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
document.addEventListener('click', (event) => {
const target = event.composedPath().find((node) => node.disableOnClick);
const target = event.composedPath().find((node) => node.hasAttribute && node.hasAttribute('disableonclick'));
if (target) {
target.disabled = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ public void setDisableOnClick_disableOnClickUpdated() {
Assert.assertFalse(component.isDisableOnClick());
}

@Test
public void setDisableOnClick_updatesAttribute() {
component.setDisableOnClick(true);
Assert.assertTrue(
component.getElement().hasAttribute("disableonclick"));

component.setDisableOnClick(false);
Assert.assertFalse(
component.getElement().hasAttribute("disableonclick"));
}

@Test
public void disableOnClickNotSetUp_click_componentIsStillEnabled() {
var componentIsEnabled = new AtomicBoolean(true);
Expand Down

0 comments on commit 1c4a2e6

Please sign in to comment.