Skip to content

[ux-icons] fill attribute override #1803

Open
@Nayte91

Description

@Nayte91

Hello,

I continue to play with ux-icons, and there is a weird behavior:

  1. create or open a svg,
  2. put in its svg tag a fill="#fff" attribute,
  3. in your html, put something like <div style="color: red;">{{ ux_icon('mysvg') }}</div>,
  4. clean your cache,
  5. check out that your icon is red; The fill attribute inside svg tag is discarded by currentColor config,
  6. modify your function to add an attribute: <div style="color: red;">{{ ux_icon('mysvg', {fill: '#00f'}) }}</div>,
  7. clean your cache,
  8. check that your icon is blue; This fill attribute takes precedence.

When you render this, your svg is filled by red, not by your white #fff. Thing is that the ux_icon component put the default fill="currentColor" attribute even if there is already a fill attribute in the file.

Maybe it is not intended, or counter-intuitive, and the function should check if fill exists before writing one? Because is a given project, there is some icons that you want to be color swappable, and that can be a majority that deserves a default fill="currentColor" config for it, but also have few icons that must stay in a given color and not move from it (at least not as easily as just color: whatever). For example brand icons, action buttons, ...

Current workaround is to put the fill attribute inside the svg tag, for example on a path tag or wrap the tags with a g tag. Or to give the color control to CSS 😄

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions