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

Support multiple data-wp-on-window or data-wp-on-document directive with the same event #60683

Closed
DAreRodz opened this issue Apr 11, 2024 · 1 comment · Fixed by #61009
Closed
Labels
[Feature] Interactivity API API to add frontend interactivity to blocks. [Packages] Interactivity /packages/interactivity [Type] Bug An existing feature does not function as intended

Comments

@DAreRodz
Copy link
Contributor

Currently, both data-wp-on-window and data-wp-on-document can't be used more than once on the same element and for the same event type. For example, the following code won't work, because browsers don't support duplicated attributes (data-wp-on-window--click in this case).

<div
  data-wp-interactive="test/on-window"
  data-wp-context='{ "clickCount": 0, "isToggled": false }'
  data-wp-on-window--click="actions.countClick"
  data-wp-on-window--click="actions.toggle"
>Click me!</button>

To fix this, we could use a similar approach to the one in #60661 for data-wp-on, i.e., allowing appending an ID to differentiate multiple directives with the same event.

@DAreRodz DAreRodz added [Type] Enhancement A suggestion for improvement. [Type] Bug An existing feature does not function as intended [Feature] Interactivity API API to add frontend interactivity to blocks. [Packages] Interactivity /packages/interactivity and removed [Type] Enhancement A suggestion for improvement. labels Apr 11, 2024
@cbravobernal
Copy link
Contributor

I'll take a look at this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Interactivity API API to add frontend interactivity to blocks. [Packages] Interactivity /packages/interactivity [Type] Bug An existing feature does not function as intended
2 participants