Skip to content

Commit ca25e9c

Browse files
committed
Add accessibility information
1 parent 5a086eb commit ca25e9c

File tree

1 file changed

+66
-10
lines changed

1 file changed

+66
-10
lines changed

src/Icons/doc/index.rst

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,26 @@ Rendering Icons
239239

240240
{{ ux_icon('flowbite:user-solid') }} <!-- renders "flowbite:user-solid" from ux.symfony.com -->
241241

242+
HTML Syntax
243+
~~~~~~~~~~~
244+
245+
.. code-block:: html+twig
246+
247+
<twig:UX:Icon name="user-profile" />
248+
249+
{# Renders "user-profile.svg" #}
250+
<twig:UX:Icon name="user-profile" class="w-4 h-4" />
251+
252+
{# Renders "sub-dir/user-profile.svg" (sub-directory) #}
253+
<twig:UX:Icon name="sub-dir:user-profile" class="w-4 h-4" />
254+
255+
{# Renders "flowbite:user-solid" from ux.symfony.com #}
256+
<twig:UX:Icon name="flowbite:user-solid" />
257+
258+
.. note::
259+
260+
``symfony/ux-twig-component`` is required to use the HTML syntax.
261+
242262
HTML Attributes
243263
~~~~~~~~~~~~~~~
244264

@@ -275,27 +295,63 @@ Now, all icons will have the ``fill`` attribute set to ``currentColor`` by defau
275295
# renders "user-profile.svg" with fill="red"
276296
{{ ux_icon('user-profile', {fill: 'red'}) }}
277297
298+
Accessibility
299+
-------------
300+
301+
Icons are a great way to add visual elements to your website, but they can be a challenge
302+
for accessibility.
278303

279-
HTML Syntax
280-
~~~~~~~~~~~
304+
According to the `W3C <https://design-system.w3.org/styles/svg-icons.html>`_, there are
305+
three methods to improve icons accessibility, depending on the context:
306+
307+
* **Decorative**: Icons that are purely decorative and do not convey any meaning or function.
308+
* **Informative**: Icons that convey information or a function.
309+
* **Functional**: Icons that are interactive and perform a function.
310+
311+
Decorative Icons
312+
~~~~~~~~~~~~~~~~
313+
314+
If the icon is purely decorative and does not convey any meaning or function, it should be
315+
hidden from screen readers using the ``aria-hidden`` attribute.
281316

282317
.. code-block:: html+twig
283318

284-
<twig:UX:Icon name="user-profile" />
319+
<a href="/profile">
320+
{{ ux_icon('user-profile', {class: 'w-4 h-4', 'aria-hidden': true}) }}
321+
Back to profile
322+
</a>
285323

286-
{# Renders "user-profile.svg" #}
287-
<twig:UX:Icon name="user-profile" class="w-4 h-4" />
324+
Informative Icons
325+
~~~~~~~~~~~~~~~~~
288326

289-
{# Renders "sub-dir/user-profile.svg" (sub-directory) #}
290-
<twig:UX:Icon name="sub-dir:user-profile" class="w-4 h-4" />
327+
If the icon conveys information or a function, it should be given a text alternative that presents
328+
the same content or function, so that it can fulfill the same purpose.
291329

292-
{# Renders "flowbite:user-solid" from ux.symfony.com #}
293-
<twig:UX:Icon name="flowbite:user-solid" />
330+
.. code-block:: html+twig
294331

332+
Today's weather:
333+
{{ ux_icon('cloud-rain', {'aria-label': 'Rainy weather'}) }}
334+
335+
Functional Icons
336+
~~~~~~~~~~~~~~~~
337+
338+
If the icon is interactive and performs a function, it should be given a text alternative that
339+
presents the same content or function, so that it can fulfill the same purpose.
340+
341+
.. code-block:: html+twig
342+
343+
{{ ux_icon('user-profile', {class: 'w-4 h-4', 'aria-label': 'User Profile'}) }}
295344

296345
.. note::
297346

298-
``symfony/ux-twig-component`` is required to use the HTML syntax.
347+
The ``aria-label`` attribute is used to provide a label for the icon. It is read by
348+
screen readers and other assistive technologies.
349+
350+
.. note::
351+
352+
The ``aria-hidden`` attribute is used to hide the icon from screen readers and other
353+
assistive technologies.
354+
299355

300356

301357
Performances

0 commit comments

Comments
 (0)