diff --git a/CHANGELOG.md b/CHANGELOG.md index 21d986add..1b9fcb087 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,6 @@ All notable changes to `laravel-livewire-tables` will be documented in this file -======= ## [v3.2.6] - UNRELEASED ### New Features - 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 - Migrate to PHPUnit Attributes rather than Doc Comments by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1727 - Remove broken test by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1719 - ## [v3.2.5] - 2024-04-30 ### New Features - Add setConfigurableArea by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1706 diff --git a/docs/columns/available-methods.md b/docs/columns/available-methods.md index d7158a04f..ab41c7095 100644 --- a/docs/columns/available-methods.md +++ b/docs/columns/available-methods.md @@ -96,6 +96,15 @@ Column::make('Name') ->html(), ``` +And this method is also available for the [LinkColumn](./other-column-types#content-link-columns) + +```php +LinkColumn::make('Name', 'name') + ->title(fn ($row) => 'Title') + ->location(fn ($row) => "#$row->id") + ->html(), +``` + ### Using a view If you would like to render a view for the cell: diff --git a/resources/views/includes/columns/link.blade.php b/resources/views/includes/columns/link.blade.php index 603331743..e361ae7f5 100644 --- a/resources/views/includes/columns/link.blade.php +++ b/resources/views/includes/columns/link.blade.php @@ -1 +1,7 @@ -arrayToAttributes($attributes) : '' !!}>{{ $title }} \ No newline at end of file +arrayToAttributes($attributes) : '' !!}> + @if($column->isHtml()) + {!! $title !!} + @else + {{ $title }} + @endif + diff --git a/tests/Views/Columns/LinkColumnTest.php b/tests/Views/Columns/LinkColumnTest.php index add1c4c25..4a204c0ff 100644 --- a/tests/Views/Columns/LinkColumnTest.php +++ b/tests/Views/Columns/LinkColumnTest.php @@ -43,4 +43,34 @@ public function test_can_render_field_if_title_and_location_callback(): void $this->assertNotEmpty($column); } + + /** @test */ + public function can_check_ishtml_from_html_column(): void + { + $column = LinkColumn::make('Name', 'name') + ->title(fn ($row) => 'Title') + ->location(fn ($row) => "#$row->id") + ->html(); + + $this->assertTrue($column->isHtml()); + } + + /** @test */ + public function can_get_html_from_html_label_column(): void + { + $column = LinkColumn::make('Name', 'name') + ->title(fn ($row) => 'My Label') + ->location(fn ($row) => "#$row->id") + ->html(); + + $rows = $this->basicTable->getRows(); + $location = '#'.$rows->first()->id; + $htmlString = new \Illuminate\Support\HtmlString('My Label'); + + // Removing every whitespace and line break for the comparison + $expectedHtml = preg_replace('/\s+/', '', $htmlString->toHtml()); + $actualHtml = preg_replace('/\s+/', '', $column->getContents($rows->first())->toHtml()); + + $this->assertSame($expectedHtml, $actualHtml); + } }