Skip to content

Commit 621893a

Browse files
aria-* attributes
1 parent d98800b commit 621893a

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/FontAwesomeSVG.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,22 @@ public function get_svg($id, $opts=[]) {
4949
}
5050

5151

52+
// $opts[aria-*]
53+
// strlen('aria-') = 5
54+
$aria_opts = array_filter($opts, function($item, $key){
55+
if(substr($key, 0, 5) == 'aria-') return $item;
56+
}, ARRAY_FILTER_USE_BOTH);
57+
5258

5359

5460
foreach ($doc->getElementsByTagName('svg') as $item) {
5561
if($classes != '') $item->setAttribute('class', $classes);
5662
if($opts['role']) $item->setAttribute('role', $opts['role']);
63+
64+
65+
foreach($aria_opts as $key => $val) {
66+
$item->setAttribute($key, $val);
67+
}
5768

5869

5970
if($opts['title']) {
@@ -69,11 +80,13 @@ public function get_svg($id, $opts=[]) {
6980
$item->setAttribute('aria-labelledby', $title_id);
7081
}
7182

72-
} else {
83+
} elseif(isset($aria_opts['aria-hidden'])) {
7384
$item->setAttribute('aria-hidden', 'true');
7485
}
7586
}
7687

88+
89+
7790
foreach ($doc->getElementsByTagName('path') as $item) {
7891
$item->setAttribute('fill', $opts['fill']);
7992
}

0 commit comments

Comments
 (0)