Skip to content

[ux-icons] title attribute to handle differently #1807

@Nayte91

Description

@Nayte91

Hello all,

Let's consider a random icon with a title attribute:

<twig:UX:Icon name="foo" title="Hello!" />

It will render with a correct title attribute, but nothing will happen on your browser.

The reason is that using a title attribute seems to be discouraged by W3C, for SVGs but also any other HTML elements.

On the SVG side, the best practice is to use a title tag at the beginning of the svg tag content. That's for example what font awesome do, here's a random icon rendering when I put a title="whatever" in the i tag:

<svg class="svg-inline--fa fa-star" data-replay-favorite-target="icon" aria-labelledby="svg-inline--fa-title-GKRKa00WHbm5" data-prefix="fas" data-icon="star" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512" data-fa-i2svg=""><title id="svg-inline--fa-title-GKRKa00WHbm5">Whatever</title><path fill="currentColor" d="M316.9 svg stuff"></path></svg>
<!-- <i class="fa-solid fa-star" title="Whatever" data-replay-favorite-target="icon"></i> Font Awesome fontawesome.com -->

And this title is correctly displayed on browser.

So it seems that the iconRenderer should process the title attribute a bit differently than the other ones, by prepending a <title>$value</title> element inside the rendered SVGs, otherwise it will not work/shoot in the foot of accessibility.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions