© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
30 replies
bernhard

Can't use svg in TextColumn

What I want to achive is a column which shows an icon and when you click on it, a defined text is copied to the clipboard.

The problem is, that the
IconColumn
IconColumn
has no
copyable
copyable
method, so I tried to use the
TextColumn
TextColumn
:

TextColumn::make("copy_column")
  ->getStateUsing("Copy")
  ->copyable()
  ->copyableState(fn($record) => $record->id)
TextColumn::make("copy_column")
  ->getStateUsing("Copy")
  ->copyable()
  ->copyableState(fn($record) => $record->id)


this works as expected and it shows the text "Copy". Now I tried to use an icon:

TextColumn::make("copy_column")
            ->getStateUsing(function() {
                return new HtmlString(
                    '<svg style="width: 20px; height: 20px;" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" aria-hidden="true">
                      <path stroke-linecap="round" stroke-linejoin="round" d="M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3"></path>
                    </svg>');
            })
            ->html()
            ->copyable()
            ->copyableState(fn($record) => $record->id)
TextColumn::make("copy_column")
            ->getStateUsing(function() {
                return new HtmlString(
                    '<svg style="width: 20px; height: 20px;" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" aria-hidden="true">
                      <path stroke-linecap="round" stroke-linejoin="round" d="M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3"></path>
                    </svg>');
            })
            ->html()
            ->copyable()
            ->copyableState(fn($record) => $record->id)


but the column is empty. Any ideas?
Solution
ugly, but maybe this works
->icon('heroicon-o-clipboard')
->getStateUsing(fn () => '<span></span>')
->html()
->icon('heroicon-o-clipboard')
->getStateUsing(fn () => '<span></span>')
->html()
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Can't I give default in TextColumn formatStateUsing?
FilamentFFilament / ❓┊help
2y ago
On TextColumn using an HTML ->prefix() with <svg> results in the svg being stripped from the output
FilamentFFilament / ❓┊help
3y ago
How can I use custom svg icon in form suffix action?
FilamentFFilament / ❓┊help
3y ago
how can i use svg in iconcolum column or something similar ?
FilamentFFilament / ❓┊help
3y ago