Open tim-timman opened 1 year ago
It’s an inherited attribute and therefore virtually added to the element that triggers the event.
Besides that it feels like a "breaking" change to me.
Wouldn’t a hx-target 'closest:.content .message-body' work? As set on .content?
This wouldn’t even break when behavior was changed according to your PR.
Wouldn’t a hx-target 'closest:.content .message-body' work? As set on .content?
This wouldn’t even break when behavior was changed according to your PR.
No, that just results in a htmx:targetError
, unless I'm misunderstanding what you mean. But it is unchanged with our without my change.
Edit: Accidentally clicked the wrong thing.
closest
appears to only be able to target ancestors. So although .content .message-body
does match from one of the parent nodes, I guess it doesn't match according to "closest" due to the actual matches not being a ancestors.
@andryyy Is correct that this would absolutely be a breaking change, and we cannot merge it for this reason. For the time being, I think the best we can do is a documentation change, but we can also discusses whether the behavior you want can be added somehow.
The issue
Using hx-target with extended CSS selectors are not selecting targets relative to the
hx-target
attribute, but instead relative to the "issuer" element (one with anhx-get
for example). I find this being unintuitive and makes the extended selectors less useful.Example
Expectation
Clicking the button would update
Target
with the result of the request. As it would find the ancestor'shx-target
, where thenext .target
isTarget
.Reality
Clicking the button to make the request results in a
htmx:targetError
, because it uses the ancestor's hx-target selectornext .target
but does the search from the button—hence doesn't find one.Fix
Make the search relative to the where the used
hx-target
element. I can't think of a case where the current implementation is preferable.Code to easily reproduce
Here's a Python script to spin up a modified SimpleHTTPServer to serve the an example of the expected behavior more visually. Using bulma stylesheet to make it a bit more easier on the eyes–looking like this:
Save and run with
python3
.