File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,15 @@ export class UUIIconElement extends LitElement {
19
19
@state ( )
20
20
private _nameSvg : string | null = null ;
21
21
22
+ /**
23
+ * An alternate description to use for assistive devices.
24
+ * If omitted, the icon will be considered presentational and ignored by assistive devices.
25
+ * @type {string }
26
+ * @attr
27
+ * @default
28
+ */
29
+ @property ( ) label = '' ;
30
+
22
31
/**
23
32
* Icon name is used to retrieve the icon from a parent Icon Registry.
24
33
* If no Icon Registry responds to the given name, the fallback svg will be used.
@@ -36,6 +45,7 @@ export class UUIIconElement extends LitElement {
36
45
this . requestIcon ( ) ;
37
46
}
38
47
}
48
+
39
49
private requestIcon ( ) {
40
50
if ( this . _name !== '' && this . _name !== null ) {
41
51
const event = new UUIIconRequestEvent ( UUIIconRequestEvent . ICON_REQUEST , {
@@ -92,6 +102,19 @@ export class UUIIconElement extends LitElement {
92
102
if ( this . _retrievedNameIcon === false ) {
93
103
this . requestIcon ( ) ;
94
104
}
105
+
106
+ const hasLabel = typeof this . label === 'string' && this . label . length > 0 ;
107
+
108
+ if ( hasLabel ) {
109
+ this . setAttribute ( 'role' , 'img' ) ;
110
+ this . setAttribute ( 'aria-label' , this . label ) ;
111
+ this . removeAttribute ( 'aria-hidden' ) ;
112
+ } else {
113
+ this . removeAttribute ( 'role' ) ;
114
+ this . removeAttribute ( 'aria-label' ) ;
115
+ this . setAttribute ( 'aria-hidden' , 'true' ) ;
116
+ }
117
+
95
118
}
96
119
97
120
render ( ) {
You can’t perform that action at this time.
0 commit comments