Skip to content

Conversation

LFDanLu
Copy link
Member

@LFDanLu LFDanLu commented Oct 15, 2025

Closes

✅ 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:

If you wanna test the S2 RadioGroup fix, simply go to the S2 storybook and set it to horizontal + rtl. ArrowLeft/Right should move focus to the left and right as expected.

🧢 Your Project:

RSP

@rspbot
Copy link

rspbot commented Oct 16, 2025

@rspbot
Copy link

rspbot commented Oct 16, 2025

@LFDanLu LFDanLu changed the title feat: WIP Add additional patterns to test utils feat: Add CheckBoxGroup/Dialog/RadioGroup test utils Oct 16, 2025
@LFDanLu LFDanLu marked this pull request as ready for review October 16, 2025 21:24
@rspbot
Copy link

rspbot commented Oct 16, 2025

}

if (!this.checkboxgroup.contains(document.activeElement)) {
act(() => checkboxes[0].focus());
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 do this by default? It can sometimes cause behaviour that doesn't match real life. Maybe there should be an option to force focus, but otherwise we throw if they aren't in the checkbox group already?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From feedback for other users and my own experience from converting tests in Quarry to use the test utils, there is often a lot of friction when people are integrating the utils into the flow of their existing test and expect that calling these "toggle/trigger" functions should just work, even if active focus is in a separate place in their app and the real life use case would be to press Tab 4x to get to the checkboxgroup/etc. I think ideally everyones tests would simulate the exact user flows but realistically I'd like there to be as little friction as possible in adoption.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, i was on the fence about it anyways. if they have a test not working at some point down the line, i think we can suggest they alter the flow to a real user one and see if it still happens

if (dialog && document.activeElement !== this._trigger && dialog.contains(document.activeElement)) {
this._dialog = dialog;
} else {
// TODO: is it too brittle to throw here?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems fine? were you running into unexpected cases?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mainly still unsure if timing might throw off this check, but seems ok so far

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, lets remove the TODO

act(() => this._radiogroup.focus());
}

let radioOrientation = this._radiogroup.getAttribute('aria-orientation') || 'horizontal';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like keyboardNavigateToRadio should determine the orientation, no need to pass it in?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya I might refactor this when I refactor some common flows out of the utils into generalized patterns (aka keyboardNavigateToElement might become a common util instead)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, just be mindful of breaking changes 👍🏻


let dialog = getByRole('dialog');
let dialogTrigger = document.activeElement! as HTMLElement;
// TODO: this is a weird case where the popover isn't actually linked to the button, behaving more like a modal
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, should this be attached?

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, should it be a popover? Then again https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/examples/datepicker-dialog/ is similar so maybe not a problem

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we just wait on this and see if anyone brings up a strong feeling. for now we can remove the comment i think

@rspbot
Copy link

rspbot commented Oct 17, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants