Skip to content

Commit a2aed0f

Browse files
a11y: <title> id option and aria-labelledby
1 parent 4082041 commit a2aed0f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/FontAwesomeSVG.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,15 @@ public function get_svg($id, $opts=false) {
6060
$title = $doc->createElement("title");
6161
$title->nodeValue = $opts['title'];
6262

63-
// TODO: add aria-labelledby
64-
//$title->setAttribute('id', '');
65-
//$item->setAttribute('aria-labelledby', '');
66-
67-
$item->appendChild($title);
63+
$title_node = $item->appendChild($title);
64+
65+
// <title> id attribute has to be set to add aria-labelledby
66+
if(isset($opts['title_id'])) {
67+
$title_id = $opts['title_id'];
68+
$title_node->setAttribute('id', $title_id);
69+
$item->setAttribute('aria-labelledby', $title_id);
70+
}
71+
6872
} else {
6973
$item->setAttribute('aria-hidden', 'true');
7074
}

0 commit comments

Comments
 (0)