Skip to content

Commit df23830

Browse files
committed
minor #1717 [Icons] aria-hidden="true" doc (smnandre)
This PR was merged into the 2.x branch. Discussion ---------- [Icons] aria-hidden="true" doc Add documentation to explain why & how this works. (moved the first paragraph down to end with the feature / code examples) Commits ------- e644df4 [Icons] aria-hidden="true" doc
2 parents 3747400 + e644df4 commit df23830

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

src/Icons/doc/index.rst

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -342,17 +342,6 @@ Icons add visual elements to your website and they can be a challenge for access
342342
According to the `W3C guide about SVG icon accessibility`_, there are
343343
three methods to improve icons accessibility, depending on the context.
344344

345-
**Decorative icons**
346-
They are purely decorative and do not convey any meaning or function. They
347-
should be hidden from screen readers using the ``aria-hidden`` attribute:
348-
349-
.. code-block:: html+twig
350-
351-
<a href="/profile">
352-
{{ ux_icon('user-profile', {class: 'w-4 h-4', 'aria-hidden': true}) }}
353-
Back to profile
354-
</a>
355-
356345
**Informative icons**
357346
They convey information or a function. They should define a text alternative
358347
that presents the same content or function via the ``aria-label`` attribute
@@ -372,6 +361,33 @@ three methods to improve icons accessibility, depending on the context.
372361
373362
{{ ux_icon('user-profile', {class: 'w-4 h-4', 'aria-label': 'User Profile'}) }}
374363
364+
**Decorative icons**
365+
They are purely decorative and do not convey any meaning or function. They
366+
should be hidden from screen readers using the ``aria-hidden`` attribute.
367+
368+
.. code-block:: html
369+
370+
<a href="/profile">
371+
<svg viewBox="0 0 24 24" class="w-4 h-4" aria-hidden="true">
372+
<!-- ... -->
373+
</svg>
374+
Back to profile
375+
</a>
376+
377+
That is why the ``ux_icon()`` function and the ``<twig:ux:icon>`` component add
378+
``aria-hidden="true"`` attribute **automatically** to icons not having at least one
379+
of the following attributes: ``aria-label``, ``aria-labelledby`` or ``title``.
380+
381+
.. note::
382+
383+
If you don't want to set ``aria-hidden="true"`` for a specific icon, you can
384+
explicitly set the ``aria-hidden`` attribute to ``false``:
385+
386+
.. code-block:: twig+html
387+
388+
<twig:UX:Icon name="user-profile" aria-hidden="false" />
389+
390+
375391
Performance
376392
-----------
377393

0 commit comments

Comments
 (0)