Skip to content

Conversation

StevenRenaux
Copy link
Contributor

@StevenRenaux StevenRenaux commented Sep 15, 2025

Q A
Bug fix? yes
New feature? no
Docs? no
License MIT

If we use fill or stroke attributes to update the color icon, as explained into https://symfony.com/bundles/ux-icons/current/index.html#default-attributes, nothing happens.

Let's explore a default Boostrap SVG together: https://icons.getbootstrap.com/icons/person/

{{ ux_icon('bi:person') }}

If we go into Bootstrap to grab that icon, it looks like this

<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-person" viewBox="0 0 16 16">
  <path d="M8 8a3 3 0 1 0 0-6 3 3 0 0 0 0 6m2-3a2 2 0 1 1-4 0 2 2 0 0 1 4 0m4 8c0 1-1 1-1 1H3s-1 0-1-1 1-4 6-4 6 3 6 4m-1-.004c-.001-.246-.154-.986-.832-1.664C11.516 10.68 10.289 10 8 10s-3.516.68-4.168 1.332c-.678.678-.83 1.418-.832 1.664z"/>
</svg>

UX-icon uses Iconify's icons and this icon is not completely the same https://github.com/iconify/icon-sets/blob/master/json/bi.json#L4472
Iconify returns the path tag for the bootsrap icon, this part is incremented with the fill attribute or the stroke, depend on the need.

<path fill="currentColor" d="M8 8a3 3 0 1 0 0-6a3 3 0 0 0 0 6m2-3a2 2 0 1 1-4 0a2 2 0 0 1 4 0m4 8c0 1-1 1-1 1H3s-1 0-1-1s1-4 6-4s6 3 6 4m-1-.004c-.001-.246-.154-.986-.832-1.664C11.516 10.68 10.289 10 8 10s-3.516.68-4.168 1.332c-.678.678-.83 1.418-.832 1.664z"></path>

But if we add fill or stroke to it will add these attributes to the svg tag and will not update the ones into the path tags, and that's the problem.

{{ ux_icon('bi:person', {fill: 'red'}) }}

<!-- Rendered -->
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="red" aria-hidden="true"><path fill="currentColor" d="M8 8a3 3 0 1 0 0-6a3 3 0 0 0 0 6m2-3a2 2 0 1 1-4 0a2 2 0 0 1 4 0m4 8c0 1-1 1-1 1H3s-1 0-1-1s1-4 6-4s6 3 6 4m-1-.004c-.001-.246-.154-.986-.832-1.664C11.516 10.68 10.289 10 8 10s-3.516.68-4.168 1.332c-.678.678-.83 1.418-.832 1.664z"></path></svg>

With the modifications the path tag also follow the same rules

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="red" aria-hidden="true"><path fill="red" d="M8 8a3 3 0 1 0 0-6a3 3 0 0 0 0 6m2-3a2 2 0 1 1-4 0a2 2 0 0 1 4 0m4 8c0 1-1 1-1 1H3s-1 0-1-1s1-4 6-4s6 3 6 4m-1-.004c-.001-.246-.154-.986-.832-1.664C11.516 10.68 10.289 10 8 10s-3.516.68-4.168 1.332c-.678.678-.83 1.418-.832 1.664z"></path></svg>

@carsonbot carsonbot added Bug Bug Fix Status: Needs Review Needs to be reviewed labels Sep 15, 2025
@carsonbot carsonbot changed the title Fix icon color Fix icon color Sep 15, 2025
@StevenRenaux StevenRenaux force-pushed the Fix/Fix-icon-color-fill-and-stroke-attributes branch from dce6c8d to 76d2253 Compare September 15, 2025 14:18
@StevenRenaux StevenRenaux force-pushed the Fix/Fix-icon-color-fill-and-stroke-attributes branch from 76d2253 to 0751dad Compare September 15, 2025 14:20
@smnandre
Copy link
Member

This is also a massive BC break here, don't you think ? And losing the read-only side of thing ..

DId you try simply setting the color on the icon ?

Copy link
Member

@smnandre smnandre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the idea, but we need to find a better method...

And i'm not yet convinced of the usage... at least not in the one you provided.. maybe i'm not seeing something

}

if ('fill' === $name) {
$this->innerSvg = str_replace('fill="currentColor"', "fill=\"{$value}\"", $this->innerSvg);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard BC break here.

}

if ('stroke' === $name) {
$this->innerSvg = str_replace('stroke="currentColor"', "stroke=\"{$value}\"", $this->innerSvg);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep an only place we echo value and espace / encode them correctly (just below)

@carsonbot carsonbot added Status: Needs Work Additional work is needed and removed Status: Needs Review Needs to be reviewed labels Sep 17, 2025
@StevenRenaux
Copy link
Contributor Author

StevenRenaux commented Sep 18, 2025

This is also a massive BC break here, don't you think ? And losing the read-only side of thing ..

DId you try simply setting the color on the icon ?

@smnandre
I know, and I agree. It was mainly to show where the problem lies. The documentation suggests this is possible, but it's not with this attribute (https://symfony.com/bundles/ux-icons/current/index.html#default-attributes).

Looking at this again this morning, I just found that this is possible with the color attribute and is even perfect in this case.
https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Attribute/color

The color attribute is used to provide a potential indirect value, currentColor, for the fill, stroke, stop-color, flood-color,
and lighting-color attributes.

Perhaps the documentation should be modified accordingly, and mention that if you want to change the color, you can do it via CSS, as Iconify also mentions in its documentation.

image
{{ ux_icon('flowbite:clock-outline', {class: 'size-4 text-gray-500'}) }}

Or with this color attribute. And we ultimately avoid the current problem with the fill attribute.

{{ ux_icon('flowbite:clock-outline', {class: 'size-4', color: 'gray'}) }}

WDYT?

@StevenRenaux
Copy link
Contributor Author

StevenRenaux commented Sep 19, 2025

Already noticed by another PR #2671

@smnandre
Copy link
Member

Very open if you want to open a PR on the documentation with clear and positive information about this

(please do not only mention Tailwind that's the only thing I'm asking for haha)

poke me if you need any guidance here :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug Fix Status: Needs Work Additional work is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants