@@ -299,3 +299,81 @@ cases(
299299 } ,
300300 } ,
301301)
302+
303+ cases (
304+ 'walk through radio group per arrow keys' ,
305+ ( { focus, key, expectedTarget} ) => {
306+ const { getEvents, eventWasFired, xpathNode} = render (
307+ `
308+ <input type="radio" name="group" value="a"/>
309+ <fieldset disabled>
310+ <input type="radio" name="group" value="b"/>
311+ </fieldset>
312+ <input type="radio" name="solo"/>
313+ <input type="radio" value="nameless1"/>
314+ <input type="radio" name="" value="nameless2"/>
315+ <input type="radio" name="group" value="c" disabled/>
316+ <input type="radio" name="group" value="d"/>
317+ <input type="radio" name="foo"/>
318+ <input type="text" name="group"/>
319+ ` ,
320+ { focus} ,
321+ )
322+
323+ const active = document . activeElement as Element
324+ dispatchUIEvent ( createConfig ( ) , active , 'keydown' , { key} )
325+
326+ if ( expectedTarget ) {
327+ const target = xpathNode ( expectedTarget )
328+ expect ( getEvents ( 'click' ) [ 0 ] ) . toHaveProperty ( 'target' , target )
329+ expect ( getEvents ( 'input' ) [ 0 ] ) . toHaveProperty ( 'target' , target )
330+ expect ( target ) . toHaveFocus ( )
331+ expect ( target ) . toBeChecked ( )
332+ } else {
333+ expect ( eventWasFired ( 'click' ) ) . toBe ( false )
334+ expect ( eventWasFired ( 'input' ) ) . toBe ( false )
335+ expect ( active ) . toHaveFocus ( )
336+ }
337+ } ,
338+ {
339+ 'per ArrowDown' : {
340+ focus : '//input[@value="a"]' ,
341+ key : 'ArrowDown' ,
342+ expectedTarget : '//input[@value="d"]' ,
343+ } ,
344+ 'per ArrowLeft' : {
345+ focus : '//input[@value="d"]' ,
346+ key : 'ArrowLeft' ,
347+ expectedTarget : '//input[@value="a"]' ,
348+ } ,
349+ 'per ArrowRight' : {
350+ focus : '//input[@value="a"]' ,
351+ key : 'ArrowRight' ,
352+ expectedTarget : '//input[@value="d"]' ,
353+ } ,
354+ 'per ArrowUp' : {
355+ focus : '//input[@value="d"]' ,
356+ key : 'ArrowUp' ,
357+ expectedTarget : '//input[@value="a"]' ,
358+ } ,
359+ 'forward around the corner' : {
360+ focus : '//input[@value="d"]' ,
361+ key : 'ArrowRight' ,
362+ expectedTarget : '//input[@value="a"]' ,
363+ } ,
364+ 'backward around the corner' : {
365+ focus : '//input[@value="a"]' ,
366+ key : 'ArrowUp' ,
367+ expectedTarget : '//input[@value="d"]' ,
368+ } ,
369+ 'do nothing on single radio' : {
370+ focus : '//input[@name="solo"]' ,
371+ key : 'ArrowRight' ,
372+ } ,
373+ 'on radios without name' : {
374+ focus : '//input[@value="nameless1"]' ,
375+ key : 'ArrowRight' ,
376+ expectedTarget : '//input[@value="nameless2"]' ,
377+ } ,
378+ } ,
379+ )
0 commit comments