Skip to content

fix: ignore programmatic clicks when disabled - #5392

Merged
vursen merged 6 commits into
mainfrom
throw-disabled-button-click
Nov 2, 2023
Merged

vursen merged 6 commits into
mainfrom
throw-disabled-button-click

Conversation

@TatuLund

@TatuLund TatuLund commented Aug 28, 2023 •

Copy link
Copy Markdown
Contributor

fixes #5414

@sonarqubecloud

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@vursen vursen left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you please reference a ticket? It's required for review.

@TatuLund

TatuLund commented Sep 1, 2023

Copy link
Copy Markdown
Contributor Author

@vursen I created the ticket and linked it.

@vursen vursen left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd argue against throwing exceptions and suggest just ignoring such clicks. This would align with the native browser behavior, which ignores programmatic clicks on disabled buttons without throwing exceptions:

<button disabled>Click!</button>
<script>
const button = document.querySelector('button');
button.addEventListener('click', () => {
  console.log('click');
});
button.click();
</script>

@yuriy-fix

Copy link
Copy Markdown
Contributor

@TatuLund, is it Ok if we adjust the PR to avoid throwing an exception?

@TatuLund

Copy link
Copy Markdown
Contributor Author

@yuriy-fix basically yes, but what is your idea for change?

@yuriy-fix

Copy link
Copy Markdown
Contributor

Following #5392 (review) comment, ignore programmatic clicks on disabled buttons without throwing exceptions.

@vursen vursen changed the title fix: Throw when calling click on disabled button fix: ignore programmatic clicks when disabled Oct 27, 2023
}

@Test
public void disableOnClick_clickRevertsDisabled_componentIsEnabled() {

@vursen vursen Nov 1, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

note: The previous version of the test clicked the already disabled button, which understandably stopped working after the PR change.

@sonarqubecloud

sonarqubecloud Bot commented Nov 1, 2023

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Comment on lines +282 to +283
fireEvent(new ClickEvent<>(this, false, 0, 0, 0, 0, 0, 0, false,
false, false, false));

@vursen vursen Nov 1, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess it's still possible to get click triggered by manually firing this click event. Not sure if it's a big issue.

@vursen
vursen merged commit 40e7360 into main Nov 2, 2023
@vursen
vursen deleted the throw-disabled-button-click branch November 2, 2023 07:46
vaadin-bot pushed a commit that referenced this pull request Nov 2, 2023
Co-authored-by: Sergey Vinogradov <mr.vursen@gmail.com>
vaadin-bot pushed a commit that referenced this pull request Nov 2, 2023
Co-authored-by: Sergey Vinogradov <mr.vursen@gmail.com>
vursen added a commit that referenced this pull request Nov 2, 2023
Co-authored-by: Tatu Lund <tatu@vaadin.com>
Co-authored-by: Sergey Vinogradov <mr.vursen@gmail.com>
vursen added a commit that referenced this pull request Nov 2, 2023
Co-authored-by: Tatu Lund <tatu@vaadin.com>
Co-authored-by: Sergey Vinogradov <mr.vursen@gmail.com>
@vaadin-bot

Copy link
Copy Markdown
Collaborator

This ticket/PR has been released with Vaadin 24.3.0.alpha5 and is also targeting the upcoming stable 24.3.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

It is possible to programmatically emulate click with disabled button

4 participants