@@ -145,5 +145,51 @@ describe('button-toolbar', () => {
145
145
146
146
wrapper . destroy ( )
147
147
} )
148
+
149
+ it ( 'keyboard navigation works' , async ( ) => {
150
+ const wrapper = mount ( App , {
151
+ attachToDocument : true
152
+ } )
153
+
154
+ await wrapper . vm . $nextTick ( )
155
+
156
+ expect ( wrapper . is ( 'div.btn-toolbar' ) ) . toBe ( true )
157
+ expect ( wrapper . attributes ( 'tabindex' ) ) . toBe ( '0' )
158
+
159
+ const $btns = wrapper . findAll ( 'button' )
160
+ expect ( $btns ) . toBeDefined ( )
161
+ expect ( $btns . length ) . toBe ( 6 )
162
+
163
+ // Focus first button
164
+ $btns . at ( 0 ) . element . focus ( )
165
+ expect ( document . activeElement ) . toBe ( $btns . at ( 0 ) . element )
166
+
167
+ // Cursor right
168
+ $btns . at ( 0 ) . trigger ( 'keydown.right' )
169
+ await wrapper . vm . $nextTick ( )
170
+ expect ( document . activeElement ) . toBe ( $btns . at ( 1 ) . element )
171
+
172
+ // Cursor right (skips disabled button)
173
+ $btns . at ( 1 ) . trigger ( 'keydown.right' )
174
+ await wrapper . vm . $nextTick ( )
175
+ expect ( document . activeElement ) . toBe ( $btns . at ( 3 ) . element )
176
+
177
+ // Cursor shift-right (focuses last button)
178
+ $btns . at ( 1 ) . trigger ( 'keydown.right' , { shiftKey : true } )
179
+ await wrapper . vm . $nextTick ( )
180
+ expect ( document . activeElement ) . toBe ( $btns . at ( 5 ) . element )
181
+
182
+ // Cursor left
183
+ $btns . at ( 5 ) . trigger ( 'keydown.left' )
184
+ await wrapper . vm . $nextTick ( )
185
+ expect ( document . activeElement ) . toBe ( $btns . at ( 4 ) . element )
186
+
187
+ // Cursor shift left (focuses first button)
188
+ $btns . at ( 5 ) . trigger ( 'keydown.left' , { shiftKey : true } )
189
+ await wrapper . vm . $nextTick ( )
190
+ expect ( document . activeElement ) . toBe ( $btns . at ( 0 ) . element )
191
+
192
+ wrapper . destroy ( )
193
+ } )
148
194
} )
149
195
} )
0 commit comments