Skip to content

Commit 1ccdec9

Browse files
committed
Add accessibility information
1 parent b974e3b commit 1ccdec9

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
@@ -155,6 +155,26 @@ Rendering Icons
155155

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

158+
HTML Syntax
159+
~~~~~~~~~~~
160+
161+
.. code-block:: html+twig
162+
163+
<twig:UX:Icon name="user-profile" />
164+
165+
{# Renders "user-profile.svg" #}
166+
<twig:UX:Icon name="user-profile" class="w-4 h-4" />
167+
168+
{# Renders "sub-dir/user-profile.svg" (sub-directory) #}
169+
<twig:UX:Icon name="sub-dir:user-profile" class="w-4 h-4" />
170+
171+
{# Renders "flowbite:user-solid" from ux.symfony.com #}
172+
<twig:UX:Icon name="flowbite:user-solid" />
173+
174+
.. note::
175+
176+
``symfony/ux-twig-component`` is required to use the HTML syntax.
177+
158178
HTML Attributes
159179
~~~~~~~~~~~~~~~
160180

@@ -191,27 +211,63 @@ Now, all icons will have the ``fill`` attribute set to ``currentColor`` by defau
191211
# renders "user-profile.svg" with fill="red"
192212
{{ ux_icon('user-profile', {fill: 'red'}) }}
193213
214+
Accessibility
215+
-------------
216+
217+
Icons are a great way to add visual elements to your website, but they can be a challenge
218+
for accessibility.
194219

195-
HTML Syntax
196-
~~~~~~~~~~~
220+
According to the `W3C <https://design-system.w3.org/styles/svg-icons.html>`_, there are
221+
three methods to improve icons accessibility, depending on the context:
222+
223+
* **Decorative**: Icons that are purely decorative and do not convey any meaning or function.
224+
* **Informative**: Icons that convey information or a function.
225+
* **Functional**: Icons that are interactive and perform a function.
226+
227+
Decorative Icons
228+
~~~~~~~~~~~~~~~~
229+
230+
If the icon is purely decorative and does not convey any meaning or function, it should be
231+
hidden from screen readers using the ``aria-hidden`` attribute.
197232

198233
.. code-block:: html+twig
199234

200-
<twig:UX:Icon name="user-profile" />
235+
<a href="/profile">
236+
{{ ux_icon('user-profile', {class: 'w-4 h-4', 'aria-hidden': true}) }}
237+
Back to profile
238+
</a>
201239

202-
{# Renders "user-profile.svg" #}
203-
<twig:UX:Icon name="user-profile" class="w-4 h-4" />
240+
Informative Icons
241+
~~~~~~~~~~~~~~~~~
204242

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

208-
{# Renders "flowbite:user-solid" from ux.symfony.com #}
209-
<twig:UX:Icon name="flowbite:user-solid" />
246+
.. code-block:: html+twig
210247

248+
Today's weather:
249+
{{ ux_icon('cloud-rain', {'aria-label': 'Rainy weather'}) }}
250+
251+
Functional Icons
252+
~~~~~~~~~~~~~~~~
253+
254+
If the icon is interactive and performs a function, it should be given a text alternative that
255+
presents the same content or function, so that it can fulfill the same purpose.
256+
257+
.. code-block:: html+twig
258+
259+
{{ ux_icon('user-profile', {class: 'w-4 h-4', 'aria-label': 'User Profile'}) }}
211260

212261
.. note::
213262

214-
``symfony/ux-twig-component`` is required to use the HTML syntax.
263+
The ``aria-label`` attribute is used to provide a label for the icon. It is read by
264+
screen readers and other assistive technologies.
265+
266+
.. note::
267+
268+
The ``aria-hidden`` attribute is used to hide the icon from screen readers and other
269+
assistive technologies.
270+
215271

216272

217273
Performances

0 commit comments

Comments
 (0)