Skip to content

fix(ui5-li): prevent item-click for disabled nested interactive controls#13275

Merged
plamenivanov91 merged 3 commits intomainfrom
list-wrong-click-handler-fix
Mar 20, 2026
Merged

fix(ui5-li): prevent item-click for disabled nested interactive controls#13275
plamenivanov91 merged 3 commits intomainfrom
list-wrong-click-handler-fix

Conversation

@plamenivanov91
Copy link
Contributor

@plamenivanov91 plamenivanov91 commented Mar 13, 2026

Previously, ListItemBase relied only on a focus-within check in onclick to suppress item press when interactive content was clicked. In Chrome, this is fragile when a nested control disables itself synchronously in its own click handler, because focus can be lost before list item click handling runs, causing ui5-item-click to fire unexpectedly.

The fix keeps the existing focus-within behavior and adds a fallback check over e.composedPath() for disabled interactive targets. Instead of hardcoded ui5-* tag lists, the fallback now uses a duck-typed approach. It handles native interactive controls (button, input, select, textarea) and custom interactive elements identified by custom-element semantics plus disabled or aria-disabled support. Disabled state is resolved via disabled property or aria-disabled="true".

This keeps behavior unchanged for normal focus-driven cases while covering the disable-on-click timing scenario with a more maintainable implementation.

Regression coverage now includes nested ui5-button that disables itself on click and must not fire ui5-item-click, nested disabled custom element that must not fire ui5-item-click, nested enabled custom element that should still fire ui5-item-click, and nested ui5-link behavior that is explicitly covered.

Fixes: #10976

Previously, `_onclick` in `ListItemBase` suppressed the `_press` event
by checking `:has(:focus-within)` on the focus DOM ref. This approach
is fragile: if a nested interactive element (e.g. a button) disables
itself synchronously during its own `click` handler, focus is lost
before the event bubbles up to the list item. As a result, the
`:focus-within` check fails and `ui5-item-click` fires unexpectedly ?
a regression observed in Chrome since v2.4.0.

Replace the focus-based guard with an event-path inspection:
`_isInteractiveContentClicked` walks `e.composedPath()` from the
clicked target up to (but not including) the list item boundary and
returns `true` if any element matches a native or UI5 interactive
control. This correctly suppresses `item-click` regardless of whether
the inner element changes its disabled/focused state during the click.

Add a regression test: nested `ui5-button` that disables itself on
click must not trigger `ui5-item-click` on the parent list item.

Fixes: #10976
@ui5-webcomponents-bot
Copy link
Collaborator

ui5-webcomponents-bot commented Mar 13, 2026

🧹 Preview deployment cleaned up: https://pr-13275--ui5-webcomponents.netlify.app

@ui5-webcomponents-bot ui5-webcomponents-bot temporarily deployed to preview March 13, 2026 16:55 Inactive
@plamenivanov91 plamenivanov91 changed the title fix(ui5-li): prevent item-click when interactive content is clicked fix(ui5-li): prevent item-click when nested control disables on click Mar 13, 2026
@ui5-webcomponents-bot ui5-webcomponents-bot temporarily deployed to preview March 13, 2026 17:51 Inactive
@plamenivanov91 plamenivanov91 changed the title fix(ui5-li): prevent item-click when nested control disables on click fix(ui5-li): prevent item-click for disabled nested interactive controls Mar 13, 2026
@ui5-webcomponents-bot ui5-webcomponents-bot temporarily deployed to preview March 13, 2026 18:14 Inactive
@plamenivanov91 plamenivanov91 merged commit 489891c into main Mar 20, 2026
21 of 22 checks passed
@plamenivanov91 plamenivanov91 deleted the list-wrong-click-handler-fix branch March 20, 2026 11:09
@ui5-webcomponents-bot ui5-webcomponents-bot temporarily deployed to preview March 20, 2026 11:09 Inactive
@ui5-webcomponents-bot
Copy link
Collaborator

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

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

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ui5-list]: Deactivation of button triggers item-click (chrome)

3 participants