Skip to content

Commit 423937e

Browse files
authored
Add support for <title> and <desc> elements in SVG for accessibility
1 parent b9f41c9 commit 423937e

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/Icons/doc/index.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,47 @@ of the following attributes: ``aria-label``, ``aria-labelledby`` or ``title``.
481481

482482
<twig:ux:icon name="user-profile" aria-hidden="false" />
483483

484+
## Accessibility: Descriptive Titles and Descriptions
485+
486+
.. versionadded:: NEXT\_VERSION
487+
488+
The `ux_icon()` function and the `<twig:ux:icon>` component now support accessible SVG metadata via the `title` and `desc` attributes.
489+
490+
These are automatically injected into the `<svg>` markup as child elements, and properly referenced using `aria-labelledby` for improved screen reader support.
491+
492+
**How it works:**
493+
494+
When you pass a `title` and/or `desc` attribute, they are rendered inside the `<svg>` as follows:
495+
496+
.. code-block:: html+twig
497+
498+
```
499+
{{ ux_icon('bi:plus-square-dotted', {
500+
width: '16px',
501+
height: '16px',
502+
class: 'text-success',
503+
title: 'Add Stock',
504+
desc: 'This icon indicates stock entry functionality.'
505+
}) }}
506+
```
507+
508+
Renders:
509+
510+
.. code-block:: html
511+
512+
```
513+
<svg class="text-success" width="16px" height="16px" aria-labelledby="icon-title-abc icon-desc-def">
514+
<title id="icon-title-abc">Add Stock</title>
515+
<desc id="icon-desc-def">This icon indicates stock entry functionality.</desc>
516+
<!-- inner SVG content -->
517+
</svg>
518+
```
519+
520+
To learn more about accessible SVG elements:
521+
522+
- `MDN: <title>`\_ — [https://developer.mozilla.org/en-US/docs/Web/SVG/Element/title](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/title)
523+
- `MDN: <desc>`\_ — [https://developer.mozilla.org/en-US/docs/Web/SVG/Element/desc](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/desc)
524+
484525
Performance
485526
-----------
486527

0 commit comments

Comments
 (0)