-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix: radiogroup navigation #8488
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
Conversation
Build successful! 🎉 |
Build successful! 🎉 |
@@ -338,7 +352,15 @@ function useFocusContainment(scopeRef: RefObject<Element[] | null>, contain?: bo | |||
|
|||
e.preventDefault(); | |||
if (nextElement) { | |||
focusElement(nextElement, true); | |||
while (nextElement.tagName === 'INPUT' && nextElement.getAttribute('type') === 'radio' && (nextElement as HTMLInputElement).form) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we build this logic into focusable tree walker so it works in other places too? Basically just reject radios that aren't the current one so it continues to the next one.
Build successful! 🎉 |
…dobe/react-spectrum into fix-radio-tab-navigation-in-focusscope
Build successful! 🎉 |
Build successful! 🎉 |
&& (node as Element).tagName === 'INPUT' | ||
&& (node as HTMLInputElement).getAttribute('type') === 'radio') { | ||
// If the radio is in a form, we can get all the other radios by name | ||
if ((node as HTMLInputElement).form && !isTabbableRadio(node as HTMLInputElement)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this mean if the radio group is outside a form it doesn't work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, lemme see if i can get something a little better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, that should take care of it, so long as two radio groups can't have the same name some other way other than forms
Build successful! 🎉 |
} else { | ||
let radioList = element.form?.elements?.namedItem(element.name) as RadioNodeList; | ||
radios = [...(radioList ?? [])] as HTMLInputElement[]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah interesting, I hadn't considered that two radio groups in different forms with the same name are separate, but when outside a form the name must be unique. HTML is fun.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be nice to have a story for testing?
Co-authored-by: Devon Govett <[email protected]>
Build successful! 🎉 |
Build successful! 🎉 |
Build successful! 🎉 |
Closes #3883, #6496
✅ Pull Request Checklist:
📝 Test Instructions:
🧢 Your Project: