Skip to content

Conversation

@nnaydenow
Copy link
Contributor

@nnaydenow nnaydenow commented Apr 14, 2025

Currently, the click event on the ui5-button is the native click event from the user interaction. This creates some problems. One main issue is that the click event cannot be prevented because the event handler in the template is always attached first. This means that the isPrevented flag is missing if the event is prevented during the bubble phase.

A bigger problem happens when the ui5-button has type="Submit" and is inside a HTML form element. In this case, each time the button is clicked, the form is submitted, even if the click event is prevented.

This pull request fixes the issue by changing the click event to a CustomEvent, instead of the native Event. In most cases, only event.target or event.currentTarget are used, and no other event details are usually needed. To provide backward compatibility the new custom event includes the original native event inside its e.detail.originalEvent, so users can still access the original event if needed.

Fixes: #11103
Fixes: #9830

@nnaydenow nnaydenow merged commit 1f4aa92 into main Apr 30, 2025
12 checks passed
@nnaydenow nnaydenow deleted the btn-custom-event branch April 30, 2025 10:43
@ui5-webcomponents-bot
Copy link
Collaborator

🎉 This PR is included in version v2.10.0-rc.3 🎉

The release is available on v2.10.0-rc.3

Your semantic-release bot 📦🚀

nnaydenow added a commit that referenced this pull request Jun 6, 2025
)

The `ui5-button` component currently has a click event listener attached to its root element. This listener prevents the native click event from propagating and instead triggers a custom event.

However, there's an issue: when the `ui5-button` has a visible border defined on the custom element, clicking that border can trigger a native click event. This happens because only the root element inside the Shadow DOM is observed, not the host element itself.

This PR resolves the issue by adding a click event handler to the host element as well, ensuring consistent event behavior regardless of where on the button the user clicks.

Issue is introduced with: #11318

Fixes: #11556
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.

[Button]: Submit button no longer appears as submitter of event [ui5-button]: wrong behavior in form

4 participants