File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
core/src/components/alert/test/a11y Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -60,5 +60,26 @@ configs({ directions: ['ltr'] }).forEach(({ config, title }) => {
60
60
test ( 'should allow for manually specifying aria attributes' , async ( { page } ) => {
61
61
await testAria ( page , 'customAria' , 'Custom title' , 'Custom description' ) ;
62
62
} ) ;
63
+
64
+ test ( 'should have aria-labelledby and aria-label added to the button when htmlAttributes is set' , async ( { page } ) => {
65
+ const didPresent = await page . spyOnEvent ( 'ionAlertDidPresent' ) ;
66
+
67
+ const button = page . locator ( '#ariaLabelButton' ) ;
68
+ await button . click ( ) ;
69
+
70
+ await didPresent . next ( ) ;
71
+
72
+ const alertButton = page . locator ( 'ion-alert .alert-button' ) ;
73
+
74
+ /**
75
+ * expect().toHaveAttribute() can't check for a null value, so grab and check
76
+ * the value manually instead.
77
+ */
78
+ const ariaLabelledBy = await alertButton . getAttribute ( 'aria-labelledby' ) ;
79
+ expect ( ariaLabelledBy ) . toBe ( 'close-label' ) ;
80
+
81
+ const ariaLabel = await alertButton . getAttribute ( 'aria-label' ) ;
82
+ expect ( ariaLabel ) . toBe ( 'close button' ) ;
83
+ } ) ;
63
84
} ) ;
64
85
} ) ;
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ <h1>Alert - A11y</h1>
24
24
< ion-button id ="noHeaders " expand ="block " onclick ="presentNoHeaders() "> No Headers</ ion-button >
25
25
< ion-button id ="noMessage " expand ="block " onclick ="presentNoMessage() "> No Message</ ion-button >
26
26
< ion-button id ="customAria " expand ="block " onclick ="presentCustomAria() "> Custom Aria</ ion-button >
27
+ < ion-button id ="ariaLabelButton " expand ="block " onclick ="presentAriaLabelButton() "> Aria Label Button</ ion-button >
27
28
</ main >
28
29
29
30
< script >
@@ -76,6 +77,21 @@ <h1>Alert - A11y</h1>
76
77
} ,
77
78
} ) ;
78
79
}
80
+
81
+ function presentAriaLabelButton ( ) {
82
+ openAlert ( {
83
+ header : 'Header' ,
84
+ subHeader : 'Subtitle' ,
85
+ message : 'This is an alert message with custom aria attributes passed to the button.' ,
86
+ buttons : [ {
87
+ text : 'Close' ,
88
+ htmlAttributes : {
89
+ ariaLabel : 'close button' ,
90
+ 'aria-labelledby' : 'close-label' ,
91
+ }
92
+ } ] ,
93
+ } ) ;
94
+ }
79
95
</ script >
80
96
</ body >
81
97
</ html >
You can’t perform that action at this time.
0 commit comments