testing-library / user-event

🐕 Simulate user events
https://testing-library.com/user-event
MIT License
2.19k stars 249 forks source link

Fix radio keyboard events #1199

Open joshferrell opened 8 months ago

joshferrell commented 8 months ago

What: There is currently an issue with the behavior of radio inputs and the user-event library. Because the walkRadio method does not break out of the loop when iterating through options, it can sometimes skip over the correct option.

There's also an issue where the direction that the arrow up and arrow down keys were swapped. Arrow down should increment and arrow up should decrement.

Fixes issue: https://github.com/testing-library/user-event/issues/1198

Why:

There was an issue with the robustness of the tests where going through the radio options, only A and D were possible. So the tests were just flipping between the only two available radio options. Adding an additional radio input breaks the tests.

How:

I've updated the tests to include an additional radio input to ensure that behavior is correct. I've also added an additional tests to ensure that radio inputs behave correctly for aria-disabled as they should still be focusable. This matches the browser behavior.

Checklist:

codesandbox-ci[bot] commented 8 months ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.