@@ -239,6 +239,26 @@ Rendering Icons
239
239
240
240
{{ ux_icon('flowbite:user-solid') }} <!-- renders "flowbite:user-solid" from ux.symfony.com -->
241
241
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
+
242
262
HTML Attributes
243
263
~~~~~~~~~~~~~~~
244
264
@@ -275,27 +295,63 @@ Now, all icons will have the ``fill`` attribute set to ``currentColor`` by defau
275
295
# renders "user-profile.svg" with fill="red"
276
296
{{ ux_icon('user-profile', {fill: 'red'}) }}
277
297
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.
278
303
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.
281
316
282
317
.. code-block :: html+twig
283
318
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>
285
323
286
- {# Renders "user-profile.svg" #}
287
- <twig :UX: Icon name="user-profile" class="w-4 h-4" />
324
+ Informative Icons
325
+ ~~~~~~~~~~~~~~~~~
288
326
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.
291
329
292
- {# Renders "flowbite:user-solid" from ux.symfony.com #}
293
- <twig:UX: Icon name="flowbite:user-solid" />
330
+ .. code-block :: html+twig
294
331
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'}) }}
295
344
296
345
.. note ::
297
346
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
+
299
355
300
356
301
357
Performances
0 commit comments