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
has no copyable
method, so I tried to use the TextColumn
:
this works as expected and it shows the text "Copy". Now I tried to use an icon:
but the column is empty. Any ideas?Solution:Jump to solution
ugly, but maybe this works
```php
->icon('heroicon-o-clipboard')
->getStateUsing(fn () => '<span></span>')
->html()...
23 Replies
Btw. using an (base64) image works:
Tried that as well, not working.
Funny thing is, that the cell is empty
Using
Blade:render
and just plain return new HtmlString( '<svg style="width: 20px;...
while using
<img>
it worksHow about when you make it a custom icon as explained here: https://filamentphp.com/docs/3.x/support/icons
Good idea for reusability anyway
Why? The
heroicon-o-clipboard
is just fine, I don't need a custom icon.Oh sorry, thought you were looking for a custom icon.
share the whole code please
Html runs through symfony/html-sanitizer, it might be that svg isn’t an allowed tag.
The whole code is just
Or not working:
The problem is, that it seems that svg is somehow parsed out
everything else works
See my message
Oh. That miight be the problem 😮
ahh, use getStateUsing instead of formatStateUsing
probably copy_column isnt a column..
Tried both
Thats right, but thats irrelevant, since all other versions are working, including regular text, html and even images. @awcodes is right. SVG gets parsed out.
Will make a PR to add copyable to IconColumn ;).
Thanks all for your time!
You could possibly bind to the HtmlSanitizerInterface and modify the settings too.
Currently it’s using ->allowSafeElements() and svg isn’t considered a safe element since it’s technically executable markup outside of a code block.
Solution
ugly, but maybe this works
This works. Thanks! Didn't know there was an icon method on the TextColumn 😄
yes, there is.. But it is joining with the state, and I had thought you didn't want this.
In my case, this doesn't matter, since i dont need the state at all, since I get the state for the clipboard by myself
copyableState
. Thank you very muchnice, because I didn't like this
->getStateUsing(fn () => '<span></span>')
😅