Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix radio keyboard events #1199

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/event/behavior/keydown.ts
Expand Up @@ -28,7 +28,7 @@ const keydownBehavior: {
ArrowDown: (event, target, instance) => {
/* istanbul ignore else */
if (isElementType(target, 'input', {type: 'radio'} as const)) {
return () => walkRadio(instance, target, -1)
return () => walkRadio(instance, target, 1)
}
},
ArrowLeft: (event, target, instance) => {
Expand All @@ -46,7 +46,7 @@ const keydownBehavior: {
ArrowUp: (event, target, instance) => {
/* istanbul ignore else */
if (isElementType(target, 'input', {type: 'radio'} as const)) {
return () => walkRadio(instance, target, 1)
return () => walkRadio(instance, target, -1)
}
},
Backspace: (event, target, instance) => {
Expand Down
1 change: 1 addition & 0 deletions src/event/radio.ts
Expand Up @@ -28,5 +28,6 @@ export function walkRadio(

focusElement(group[i])
instance.dispatchUIEvent(group[i], 'click')
return
}
}
13 changes: 10 additions & 3 deletions tests/event/behavior/keydown.ts
Expand Up @@ -317,7 +317,9 @@ cases(
<input type="radio" name="" value="nameless2"/>
<input type="radio" name="group" value="c" disabled/>
<input type="radio" name="group" value="d"/>
<input type="radio" name="foo"/>
<input type="radio" name="group" value="f" aria-disabled />
<input type="radio" name="group" value="e" />
<input type="radio" name="foo"/>
<input type="text" name="group"/>
`,
{focus},
Expand Down Expand Up @@ -360,14 +362,14 @@ cases(
expectedTarget: '//input[@value="a"]',
},
'forward around the corner': {
focus: '//input[@value="d"]',
focus: '//input[@value="e"]',
key: 'ArrowRight',
expectedTarget: '//input[@value="a"]',
},
'backward around the corner': {
focus: '//input[@value="a"]',
key: 'ArrowUp',
expectedTarget: '//input[@value="d"]',
expectedTarget: '//input[@value="e"]',
},
'do nothing on single radio': {
focus: '//input[@name="solo"]',
Expand All @@ -378,5 +380,10 @@ cases(
key: 'ArrowRight',
expectedTarget: '//input[@value="nameless2"]',
},
'on radios with aria-disabled': {
focus: '//input[@value="d"]',
key: 'ArrowDown',
expectedTarget: '//input[@value="f"]',
},
},
)