Skip to content

Commit

Permalink
Merge pull request #64 from michalsn/feat/hx-reselect
Browse files Browse the repository at this point in the history
feat: add `HX-Reselect` header support
  • Loading branch information
michalsn authored Nov 23, 2023
2 parents e81aec8 + 571b6f0 commit ec8c6d8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
6 changes: 3 additions & 3 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions docs/response.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Available methods:
- [setReplaceUrl()](#setreplaceurl)
- [setReswap()](#setreswap)
- [setRetarget()](#setretarget)
- [setReselect()](#setreselect)
- [triggerClientEvent()](#triggerclientevent)

### setPushUrl()
Expand Down Expand Up @@ -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`.
Expand Down
13 changes: 13 additions & 0 deletions src/HTTP/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
7 changes: 7 additions & 0 deletions tests/HTTP/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit ec8c6d8

Please sign in to comment.