Skip to content

Commit defe420

Browse files
code-creeperlrljoe
andauthored
Add HTML render support for LinkColumn (rappasoft#1728)
* Add the html render support for the LinkColumn --------- Co-authored-by: Joe <[email protected]>
1 parent 7bff945 commit defe420

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

CHANGELOG.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
All notable changes to `laravel-livewire-tables` will be documented in this file
44

5-
=======
65
## [v3.2.6] - UNRELEASED
76
### New Features
87
- Add configurable wire:model for filters by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1699
@@ -15,7 +14,6 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
1514
- Migrate to PHPUnit Attributes rather than Doc Comments by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1727
1615
- Remove broken test by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1719
1716

18-
1917
## [v3.2.5] - 2024-04-30
2018
### New Features
2119
- Add setConfigurableArea by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1706

docs/columns/available-methods.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ Column::make('Name')
9696
->html(),
9797
```
9898

99+
And this method is also available for the [LinkColumn](./other-column-types#content-link-columns)
100+
101+
```php
102+
LinkColumn::make('Name', 'name')
103+
->title(fn ($row) => 'Title')
104+
->location(fn ($row) => "#$row->id")
105+
->html(),
106+
```
107+
99108
### Using a view
100109

101110
If you would like to render a view for the cell:
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
<a href="{{ $path }}" {!! count($attributes) ? $column->arrayToAttributes($attributes) : '' !!}>{{ $title }}</a>
1+
<a href="{{ $path }}" {!! count($attributes) ? $column->arrayToAttributes($attributes) : '' !!}>
2+
@if($column->isHtml())
3+
{!! $title !!}
4+
@else
5+
{{ $title }}
6+
@endif
7+
</a>

tests/Views/Columns/LinkColumnTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,34 @@ public function test_can_render_field_if_title_and_location_callback(): void
4343

4444
$this->assertNotEmpty($column);
4545
}
46+
47+
/** @test */
48+
public function can_check_ishtml_from_html_column(): void
49+
{
50+
$column = LinkColumn::make('Name', 'name')
51+
->title(fn ($row) => 'Title')
52+
->location(fn ($row) => "#$row->id")
53+
->html();
54+
55+
$this->assertTrue($column->isHtml());
56+
}
57+
58+
/** @test */
59+
public function can_get_html_from_html_label_column(): void
60+
{
61+
$column = LinkColumn::make('Name', 'name')
62+
->title(fn ($row) => '<strong>My Label</strong>')
63+
->location(fn ($row) => "#$row->id")
64+
->html();
65+
66+
$rows = $this->basicTable->getRows();
67+
$location = '#'.$rows->first()->id;
68+
$htmlString = new \Illuminate\Support\HtmlString('<a href="'.$location.'"><strong>My Label</strong></a>');
69+
70+
// Removing every whitespace and line break for the comparison
71+
$expectedHtml = preg_replace('/\s+/', '', $htmlString->toHtml());
72+
$actualHtml = preg_replace('/\s+/', '', $column->getContents($rows->first())->toHtml());
73+
74+
$this->assertSame($expectedHtml, $actualHtml);
75+
}
4676
}

0 commit comments

Comments
 (0)