Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabled button can emit click events #7334

Open
tomivirkki opened this issue Apr 15, 2024 · 3 comments
Open

Disabled button can emit click events #7334

tomivirkki opened this issue Apr 15, 2024 · 3 comments

Comments

@tomivirkki
Copy link
Member

Description

A <vaadin-button> marked as disabled can still emit click events if you cancel its pointer-events: none CSS rule.

Expected outcome

A disabled button should not emit click events

Minimal reproducible example

<script type="module">
  const button = document.querySelector('vaadin-button');
  button.style.pointerEvents = 'auto';
  button.addEventListener('click', () => {
    console.log('Button clicked');
  });

  // Dynamically import the button to make sure the fix also works in cases
  // where the event listener is added before the web component is defined.
  import('@vaadin/button');
</script>

<vaadin-button disabled>Edit</vaadin-button>

Steps to reproduce

  • Open the page with the provided snippet
  • Click the disabled button
  • See the logs

Environment

Vaadin version(s): All

Browsers

Issue is not browser related

@tomivirkki tomivirkki changed the title disabled button can emit click events Disabled button can emit click events Apr 15, 2024
@web-padawan
Copy link
Member

make sure the fix also works in cases where the event listener is added before the web component is defined.

I think we can make it work using capture phase, but then custom event listener can also use it and still run earlier 🤷‍♂️

@web-padawan
Copy link
Member

Note: according to vaadin/flow-components#6183 (comment), some people expect to be able to listen for clicks on disabled buttons. If we fix this issue, then the linked BFP would be affected.

@rolfsmeds
Copy link
Contributor

Arguably, if you're modifying the default CSS of the button in a way that, by definition, affects its behavior, the change in behavior is your choice. So I don't see this as a bug since it works as intended unless you mess with it.

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

No branches or pull requests

3 participants