@@ -144,7 +144,6 @@ it('has the proper aria attributes', () => {
144
144
expect ( panel ) . toHaveAttribute ( 'aria-labelledby' )
145
145
} )
146
146
147
- // test that tab moves focus to the next focusable element
148
147
it ( 'tab moves focus to the next focusable element' , async ( ) => {
149
148
renderComponent ( {
150
149
template : `
@@ -178,7 +177,43 @@ it('tab moves focus to the next focusable element', async () => {
178
177
expect ( last ) . toHaveFocus ( )
179
178
} )
180
179
181
- // test that aria-contols for button is same as id for panel
180
+
181
+ it ( 'shift+tab moves focus to the previous focusable element' , async ( ) => {
182
+ renderComponent ( {
183
+ template : `
184
+ <CAccordion>
185
+ <CAccordionItem>
186
+ <CAccordionHeader>First section</CAccordionHeader>
187
+ <CAccordionPanel>Panel 1</CAccordionPanel>
188
+ </CAccordionItem>
189
+ <CAccordionItem>
190
+ <CAccordionHeader>Second section</CAccordionHeader>
191
+ <CAccordionPanel>Panel 2</CAccordionPanel>
192
+ </CAccordionItem>
193
+ <CAccordionItem>
194
+ <CAccordionHeader>Last section</CAccordionHeader>
195
+ <CAccordionPanel>Panel 3</CAccordionPanel>
196
+ </CAccordionItem>
197
+ </CAccordion>`
198
+ } )
199
+
200
+ const first = screen . getByText ( 'First section' )
201
+ const second = screen . getByText ( 'Second section' )
202
+ const last = screen . getByText ( 'Last section' )
203
+
204
+ await userEvent . tab ( )
205
+ expect ( first ) . toHaveFocus ( )
206
+
207
+ await userEvent . tab ( )
208
+ expect ( second ) . toHaveFocus ( )
209
+
210
+ await userEvent . tab ( )
211
+ expect ( last ) . toHaveFocus ( )
212
+
213
+ await userEvent . tab ( { shift : true } ) // shift+tab
214
+ expect ( second ) . toHaveFocus ( )
215
+ } )
216
+
182
217
it ( 'aria-contols for button is same as id for panel' , ( ) => {
183
218
renderComponent ( {
184
219
template : `
@@ -195,7 +230,6 @@ it('aria-contols for button is same as id for panel', () => {
195
230
expect ( button . getAttribute ( 'aria-controls' ) ) . toEqual ( panel . getAttribute ( 'id' ) )
196
231
} )
197
232
198
- // test that aria-expanded is true/false when accordion is open/closed
199
233
it ( 'aria-expanded is true/false when accordion is open/closed' , ( ) => {
200
234
renderComponent ( {
201
235
template : `
@@ -215,7 +249,6 @@ it('aria-expanded is true/false when accordion is open/closed', () => {
215
249
expect ( button ) . toHaveAttribute ( 'aria-expanded' , 'true' )
216
250
} )
217
251
218
- // test that panel has role=region and aria-labelledby
219
252
it ( 'panel has role=region and aria-labelledby' , ( ) => {
220
253
renderComponent ( {
221
254
template : `
@@ -230,30 +263,4 @@ it('panel has role=region and aria-labelledby', () => {
230
263
231
264
expect ( panel ) . toHaveAttribute ( 'aria-labelledby' )
232
265
expect ( panel ) . toHaveAttribute ( 'role' , 'region' )
233
- } )
234
-
235
- // eslint-disable-next-line no-undef
236
- xit ( 'arrow up & down moves focus to next/previous accordion' , async ( ) => {
237
- renderComponent ( {
238
- template : `
239
- <CAccordion>
240
- <CAccordionItem>
241
- <CAccordionHeader>Section 1 title</CAccordionHeader>
242
- <CAccordionPanel>Panel 1</CAccordionPanel>
243
- </CAccordionItem>
244
- <CAccordionItem>
245
- <CAccordionHeader>Section 2 title</CAccordionHeader>
246
- <CAccordionPanel>Panel 2</CAccordionPanel>
247
- </CAccordionItem>
248
- </CAccordion>`
249
- } )
250
-
251
- const first = screen . getByText ( 'Section 1 title' )
252
- const second = screen . getByText ( 'Section 2 title' )
253
-
254
- await fireEvent . keyDown ( first , { key : 'ArrowDown' , keyCode : 40 } )
255
- expect ( second ) . toHaveFocus ( )
256
-
257
- await fireEvent . keyDown ( second , { key : 'ArrowUp' , keyCode : 38 } )
258
- expect ( first ) . toHaveFocus ( )
259
- } )
266
+ } )
0 commit comments