Skip to content

Commit bf8111c

Browse files
vgpenaViolet Peñaph-fritschejoshferrell
authored
fix(keyboard): walk through radio group per arrow keys (#1049)
Co-authored-by: Violet Peña <[email protected]> Co-authored-by: Philipp Fritsche <[email protected]> Co-authored-by: Joshua Ferrell <[email protected]>
1 parent bc15a5b commit bf8111c

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/event/behavior/keydown.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const keydownBehavior: {
2828
ArrowDown: (event, target, instance) => {
2929
/* istanbul ignore else */
3030
if (isElementType(target, 'input', {type: 'radio'} as const)) {
31-
return () => walkRadio(instance, target, -1)
31+
return () => walkRadio(instance, target, 1)
3232
}
3333
},
3434
ArrowLeft: (event, target, instance) => {
@@ -46,7 +46,7 @@ const keydownBehavior: {
4646
ArrowUp: (event, target, instance) => {
4747
/* istanbul ignore else */
4848
if (isElementType(target, 'input', {type: 'radio'} as const)) {
49-
return () => walkRadio(instance, target, 1)
49+
return () => walkRadio(instance, target, -1)
5050
}
5151
},
5252
Backspace: (event, target, instance) => {

src/event/radio.ts

+1
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ export function walkRadio(
2828

2929
focusElement(group[i])
3030
instance.dispatchUIEvent(group[i], 'click')
31+
return
3132
}
3233
}

tests/event/behavior/keydown.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,8 @@ cases(
317317
<input type="radio" name="" value="nameless2"/>
318318
<input type="radio" name="group" value="c" disabled/>
319319
<input type="radio" name="group" value="d"/>
320+
<input type="radio" name="group" value="f" aria-disabled />
321+
<input type="radio" name="group" value="e" />
320322
<input type="radio" name="foo"/>
321323
<input type="text" name="group"/>
322324
`,
@@ -360,14 +362,14 @@ cases(
360362
expectedTarget: '//input[@value="a"]',
361363
},
362364
'forward around the corner': {
363-
focus: '//input[@value="d"]',
365+
focus: '//input[@value="e"]',
364366
key: 'ArrowRight',
365367
expectedTarget: '//input[@value="a"]',
366368
},
367369
'backward around the corner': {
368370
focus: '//input[@value="a"]',
369371
key: 'ArrowUp',
370-
expectedTarget: '//input[@value="d"]',
372+
expectedTarget: '//input[@value="e"]',
371373
},
372374
'do nothing on single radio': {
373375
focus: '//input[@name="solo"]',
@@ -378,5 +380,10 @@ cases(
378380
key: 'ArrowRight',
379381
expectedTarget: '//input[@value="nameless2"]',
380382
},
383+
'on radios with aria-disabled': {
384+
focus: '//input[@value="d"]',
385+
key: 'ArrowDown',
386+
expectedTarget: '//input[@value="f"]',
387+
},
381388
},
382389
)

0 commit comments

Comments
 (0)