@@ -155,6 +155,26 @@ Rendering Icons
155
155
156
156
{{ ux_icon('flowbite:user-solid') }} <!-- renders "flowbite:user-solid" from ux.symfony.com -->
157
157
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
+
158
178
HTML Attributes
159
179
~~~~~~~~~~~~~~~
160
180
@@ -191,27 +211,63 @@ Now, all icons will have the ``fill`` attribute set to ``currentColor`` by defau
191
211
# renders "user-profile.svg" with fill="red"
192
212
{{ ux_icon('user-profile', {fill: 'red'}) }}
193
213
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.
194
219
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.
197
232
198
233
.. code-block :: html+twig
199
234
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>
201
239
202
- {# Renders "user-profile.svg" #}
203
- <twig :UX: Icon name="user-profile" class="w-4 h-4" />
240
+ Informative Icons
241
+ ~~~~~~~~~~~~~~~~~
204
242
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.
207
245
208
- {# Renders "flowbite:user-solid" from ux.symfony.com #}
209
- <twig:UX: Icon name="flowbite:user-solid" />
246
+ .. code-block :: html+twig
210
247
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'}) }}
211
260
212
261
.. note ::
213
262
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
+
215
271
216
272
217
273
Performances
0 commit comments