mirror of
https://github.com/bigskysoftware/htmx.git
synced 2025-10-02 07:21:05 +00:00
support closest
syntax in hx-indicator
This commit is contained in:
parent
e5b2273c09
commit
6939290b8f
@ -1482,7 +1482,12 @@ return (function () {
|
|||||||
function mutateRequestIndicatorClasses(elt, action) {
|
function mutateRequestIndicatorClasses(elt, action) {
|
||||||
var indicator = getClosestAttributeValue(elt, 'hx-indicator');
|
var indicator = getClosestAttributeValue(elt, 'hx-indicator');
|
||||||
if (indicator) {
|
if (indicator) {
|
||||||
var indicators = getDocument().querySelectorAll(indicator);
|
var indicators;
|
||||||
|
if (indicator.indexOf("closest ") === 0) {
|
||||||
|
indicators = [closest(elt, indicator.substr(8))];
|
||||||
|
} else {
|
||||||
|
indicators = getDocument().querySelectorAll(indicator);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
indicators = [elt];
|
indicators = [elt];
|
||||||
}
|
}
|
||||||
|
@ -49,4 +49,17 @@ describe("hx-indicator attribute", function(){
|
|||||||
a1.classList.contains("htmx-request").should.equal(false);
|
a1.classList.contains("htmx-request").should.equal(false);
|
||||||
a2.classList.contains("htmx-request").should.equal(false);
|
a2.classList.contains("htmx-request").should.equal(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('allows closest syntax in hx-indicator', function()
|
||||||
|
{
|
||||||
|
this.server.respondWith("GET", "/test", "Clicked!");
|
||||||
|
var div = make('<div id="d1"><button id="b1" hx-get="/test" hx-indicator="closest div">Click Me!</button></div>')
|
||||||
|
var btn = byId("b1");
|
||||||
|
btn.click();
|
||||||
|
btn.classList.contains("htmx-request").should.equal(false);
|
||||||
|
div.classList.contains("htmx-request").should.equal(true);
|
||||||
|
this.server.respond();
|
||||||
|
btn.classList.contains("htmx-request").should.equal(false);
|
||||||
|
div.classList.contains("htmx-request").should.equal(false);
|
||||||
|
});
|
||||||
})
|
})
|
||||||
|
@ -9,7 +9,8 @@ The `hx-indicator` attribute allows you to specify the element that will have th
|
|||||||
added to it for the duration of the request. This can be used to show spinners or progress indicators
|
added to it for the duration of the request. This can be used to show spinners or progress indicators
|
||||||
while the request is in flight.
|
while the request is in flight.
|
||||||
|
|
||||||
The value of this attribute is a CSS query selector of the element or elements to apply the class to.
|
The value of this attribute is a CSS query selector of the element or elements to apply the class to,
|
||||||
|
or the keyword `closest`, followed by a CSS selector, which will find the closest matching parent (e.g. `closest tr`);
|
||||||
|
|
||||||
Here is an example with a spinner adjacent to the button:
|
Here is an example with a spinner adjacent to the button:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user