diff --git a/docs/configuration.md b/docs/configuration.md index c275680..8706149 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -12,9 +12,9 @@ We will get our copy ready for modifications. Available options: -- [$toolbarDecorator](#$toolbarDecorator) -- [$errorModalDecorator](#$errorModalDecorator) -- [$skipViewDecoratorsString](#$skipViewDecoratorsString) +- [$toolbarDecorator](#toolbarDecorator) +- [$errorModalDecorator](#errorModalDecorator) +- [$skipViewDecoratorsString](#skipViewDecoratorsString) ### $toolbarDecorator diff --git a/docs/response.md b/docs/response.md index daa58bf..ffbb95a 100644 --- a/docs/response.md +++ b/docs/response.md @@ -6,6 +6,7 @@ Available methods: - [setReplaceUrl()](#setreplaceurl) - [setReswap()](#setreswap) - [setRetarget()](#setretarget) +- [setReselect()](#setreselect) - [triggerClientEvent()](#triggerclientevent) ### setPushUrl() @@ -40,6 +41,14 @@ Sets the value in `HX-Retarget` header. A CSS selector that updates the target o $this->response->setRetarget('#another-div'); ``` +### setReselect() + +Sets the value in `HX-Reselect` header. A CSS selector that allows you to choose which part of the response is used to be swapped in. Overrides an existing [hx-select](https://htmx.org/attributes/hx-select/) on the triggering element. + +```php +$this->response->setReselect('#another-div'); +``` + ### triggerClientEvent() Allows you to set the headers: `HX-Trigger`, `HX-Trigger-After-Settle` or `HX-Trigger-After-Swap`. diff --git a/src/HTTP/Response.php b/src/HTTP/Response.php index 4ab9b97..eb001e2 100644 --- a/src/HTTP/Response.php +++ b/src/HTTP/Response.php @@ -60,6 +60,19 @@ public function setRetarget(string $selector): Response return $this; } + /** + * A CSS selector that allows you to choose which part + * of the response is used to be swapped in. + * + * @return Response; + */ + public function setReselect(string $selector): Response + { + $this->setHeader('HX-Reselect', $selector); + + return $this; + } + /** * Allows you to trigger client side events. * diff --git a/tests/HTTP/ResponseTest.php b/tests/HTTP/ResponseTest.php index 82b64ca..c7ac42d 100644 --- a/tests/HTTP/ResponseTest.php +++ b/tests/HTTP/ResponseTest.php @@ -77,6 +77,13 @@ public function testSetRetarget(): void $this->assertSame('#element', $this->response->getHeaderLine('HX-Retarget')); } + public function testSetReselect(): void + { + $this->response->setReselect('#element'); + + $this->assertSame('#element', $this->response->getHeaderLine('HX-Reselect')); + } + public function testTriggerClientEvent(): void { $this->response->triggerClientEvent('showMessage');