-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Clarify event filter uses in hx-trigger #2914
Conversation
Hey, tbh I'm not so sure about the However, this section could probably be improved to make things clearer. Maybe it could be useful to add this precision, as for ex a Just some ideas out loud, let me know what you think! |
My motivation for If that example is a good approach to the stated problem then I'd agree to keeping it unchanged, other than including the attribute name in the snippet. The precision is for sure worth mentioning, I did not know these nuances of the event scope. Is it worth mentioning CSP here or a step too far? The console will warn the developer quickly when it doesn't work under a strict policy. In my project I chose not to use this solution because it required unsafe-eval. I bound event listeners to my new elements that dispatch an 'input' event from a hidden with no name or value that is always present in my form. That approach is most definately not worth documenting. |
I think we could use another example, such as
I think we can refer to the security section of the docs which contains the following part:
No need to dive more than that I think as it's not the goal of the
Sure, that's understandable! After all you did exacly what is suggested in the docs, i.e.:
|
input is both a tag and an event.
8ba1858
to
e1362e1
Compare
from:input listens to the page and click[event.target.matches('input')] listens to the element.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok so very sorry about it, but I just realized I forgot to take the whole context into account while reviewing this.
As we're in the hx-trigger
doc, though more specifically in the from
details here, I feel like it might be too much information for this place.
Also, it feels weird to me that the docs goes from from
to event filtering to then referencing combining with from
once again while we're still in the from
section's itself
What would you think about:
- Moving the
eval
reference to the "standard event filters" above that describes how filtering works ? - Add a link to the event filtering section in the
from
details using a link anchor (i.e#standard-event-filters
to match the id of that part and auto-scroll to it on click) - Maybe simply illustrate the initial sentence here by 2 examples, something like
for example
hx-trigger="click[event.target.matches('button')]"
would intercept any dynamically swapped in button descendant as the listener is registered on the root element, andhx-trigger="click[event.target.matches('button')]" from:body
would intercept any dynamically swapped in button across the whole page, as we'd be listening on the body
Rough idea, likely too verbose, we'd probably want a more concise sentence than that but you get the idea!
- Or, we could as well put more examples in the event filters section, precisely one with a
event.target.matches
example, then just refer to it in thefrom
section maybe?
Let me know your thoughts!
No worries at all on the back and forth, lets do this well. I like the above, though I'm thinking for the example in "from" we only use the second, one which is most equivalent. |
…nt modifiers section, and link to the standard event filters section instead.
Thanks for your patience! |
Description
hx-trigger
attribute and that you use a CSS selector.Corresponding issue: #2912
Testing
*Viewed the document as rendered markdown.
Checklist
master
for website changes,dev
forsource changes)
approved via an issue
npm run test
) and verified that it succeededTwo unit tests time out on my machine.