File tree 4 files changed +63
-0
lines changed
4 files changed +63
-0
lines changed Original file line number Diff line number Diff line change 2
2
class =" {{ classes.main }} "
3
3
dir =" {{ effectiveDir }} "
4
4
role =" region"
5
+ aria-label =" {{ ariaLebelText }} "
5
6
aria-labelledby =" {{ _id }} -desc {{ _id }} -heading" >
6
7
{{ #if hasHeader }}
7
8
<div class =" {{ classes.header }} "
Original file line number Diff line number Diff line change 1
1
import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js" ;
2
2
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js" ;
3
3
import { fetchI18nBundle , getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js" ;
4
+ import getEffectiveAriaLabelText from "@ui5/webcomponents-base/dist/util/getEffectiveAriaLabelText.js" ;
4
5
import { isSpace , isEnter } from "@ui5/webcomponents-base/dist/Keys.js" ;
5
6
import CardTemplate from "./generated/templates/CardTemplate.lit.js" ;
6
7
import Icon from "./Icon.js" ;
@@ -111,6 +112,31 @@ const metadata = {
111
112
type : Boolean ,
112
113
} ,
113
114
115
+ /**
116
+ * Defines the aria-label attribute for the <code>ui5-card</code>
117
+ *
118
+ * @type {String }
119
+ * @since 1.0.0-rc.9
120
+ * @private
121
+ * @defaultvalue ""
122
+ */
123
+ ariaLabel : {
124
+ type : String ,
125
+ } ,
126
+
127
+ /**
128
+ * Receives id(or many ids) of the elements that label the <code>ui5-card</code>
129
+ *
130
+ * @type {String }
131
+ * @defaultvalue ""
132
+ * @private
133
+ * @since 1.0.0-rc.9
134
+ */
135
+ ariaLabelledby : {
136
+ type : String ,
137
+ defaultValue : "" ,
138
+ } ,
139
+
114
140
_headerActive : {
115
141
type : Boolean ,
116
142
noAttribute : true ,
@@ -212,6 +238,10 @@ class Card extends UI5Element {
212
238
return ! ! ( this . heading || this . subheading || this . status || this . hasAction || this . avatar ) ;
213
239
}
214
240
241
+ get ariaLebelText ( ) {
242
+ return getEffectiveAriaLabelText ( this ) ;
243
+ }
244
+
215
245
get ariaCardRoleDescription ( ) {
216
246
return this . i18nBundle . getText ( ARIA_ROLEDESCRIPTION_CARD ) ;
217
247
}
Original file line number Diff line number Diff line change 102
102
< ui5-button icon ="overflow " slot ="action " design ="Transparent "> </ ui5-button >
103
103
</ ui5-card >
104
104
105
+ < h3 > Test ariaLabel and ariaLabelledBy</ h3 >
106
+ < ui5-card
107
+ id ="textAreaAriaLabel "
108
+ heading ="Linked activities (5) "
109
+ subheading ="quick links "
110
+ aria-label ="Hello World "
111
+ class ="myCard ">
112
+ </ ui5-card >
113
+
114
+ < br >
115
+ < ui5-label id ="infoText "> info text</ ui5-label >
116
+
117
+ < ui5-card
118
+ id ="textAreaAriaLabelledBy "
119
+ aria-labelledby ="infoText "
120
+ heading ="New jobs (5) "
121
+ subheading ="find one ">
122
+ </ ui5-card >
123
+
105
124
< script >
106
125
card . addEventListener ( "ui5-headerClick" , function ( event ) {
107
126
console . log ( event ) ;
Original file line number Diff line number Diff line change @@ -32,4 +32,17 @@ describe("Card general interaction", () => {
32
32
33
33
assert . strictEqual ( field . getProperty ( "value" ) , "3" , "The events count should remain 3 as the header is not interactive." ) ;
34
34
} ) ;
35
+
36
+
37
+ it ( "Tests aria-label and aria-labelledby" , ( ) => {
38
+ const card1 = browser . $ ( "#textAreaAriaLabel" ) . shadow$ ( ".ui5-card-root" ) ;
39
+ const card2 = browser . $ ( "#textAreaAriaLabelledBy" ) . shadow$ ( ".ui5-card-root" ) ;
40
+ const EXPECTED_ARIA_LABEL1 = "Hello World" ;
41
+ const EXPECTED_ARIA_LABEL2 = "info text" ;
42
+
43
+ assert . strictEqual ( card1 . getAttribute ( "aria-label" ) , EXPECTED_ARIA_LABEL1 ,
44
+ "The aria-label is correctly set internally." ) ;
45
+ assert . strictEqual ( card2 . getAttribute ( "aria-label" ) , EXPECTED_ARIA_LABEL2 ,
46
+ "The aria-label is correctly set internally." ) ;
47
+ } ) ;
35
48
} ) ;
You can’t perform that action at this time.
0 commit comments