Skip to content

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

Merged
merged 11 commits into from
Jul 9, 2025
Merged

Conversation

snowystinger
Copy link
Member

@snowystinger snowystinger commented Jul 4, 2025

Closes #3883, #6496

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

🧢 Your Project:

@rspbot
Copy link

rspbot commented Jul 4, 2025

@snowystinger snowystinger changed the title fix: radio tab navigation in a focusscope fix: radiogroup navigation Jul 5, 2025
@rspbot
Copy link

rspbot commented Jul 5, 2025

yihuiliao
yihuiliao previously approved these changes Jul 7, 2025
@@ -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) {
Copy link
Member

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.

@rspbot
Copy link

rspbot commented Jul 7, 2025

@rspbot
Copy link

rspbot commented Jul 7, 2025

@rspbot
Copy link

rspbot commented Jul 7, 2025

&& (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)) {
Copy link
Member

@devongovett devongovett Jul 8, 2025

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?

Copy link
Member Author

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

Copy link
Member Author

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

@rspbot
Copy link

rspbot commented Jul 8, 2025

} else {
let radioList = element.form?.elements?.namedItem(element.name) as RadioNodeList;
radios = [...(radioList ?? [])] as HTMLInputElement[];
}
Copy link
Member

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.

devongovett
devongovett previously approved these changes Jul 8, 2025
Copy link
Member

@devongovett devongovett left a 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?

yihuiliao
yihuiliao previously approved these changes Jul 8, 2025
@snowystinger snowystinger dismissed stale reviews from yihuiliao and devongovett via 8b7ae3f July 8, 2025 22:25
@rspbot
Copy link

rspbot commented Jul 8, 2025

@rspbot
Copy link

rspbot commented Jul 8, 2025

yihuiliao
yihuiliao previously approved these changes Jul 8, 2025
@rspbot
Copy link

rspbot commented Jul 8, 2025

@snowystinger snowystinger enabled auto-merge July 9, 2025 00:03
@snowystinger snowystinger added this pull request to the merge queue Jul 9, 2025
Merged via the queue into main with commit 8f0ba04 Jul 9, 2025
31 checks passed
@snowystinger snowystinger deleted the fix-radio-tab-navigation-in-focusscope branch July 9, 2025 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FocusScope breaks native radio input behavior within a fieldset
4 participants