Skip to content

Commit 51f9631

Browse files
fix: User Event tab retargeting bug (#8700)
Co-authored-by: Yihui Liao <[email protected]>
1 parent d847036 commit 51f9631

File tree

5 files changed

+16
-12
lines changed

5 files changed

+16
-12
lines changed

.yarn/patches/@testing-library-user-event-npm-14.6.1-5da7e1d4e2.patch

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ index 39a24b8f2ccdc52739d130480ab18975073616cb..0c3f5199401c15b90230c25a02de364e
1111
}
1212
UI.clearInitialValue(el);
1313
}
14+
diff --git a/dist/cjs/event/behavior/keydown.js b/dist/cjs/event/behavior/keydown.js
15+
index 55027cb256f66b808d17280dc01bc55a796a1032..993d5de5a838a711d7ae009344354772a42ed0c1 100644
16+
--- a/dist/cjs/event/behavior/keydown.js
17+
+++ b/dist/cjs/event/behavior/keydown.js
18+
@@ -110,7 +110,7 @@ const keydownBehavior = {
19+
},
20+
Tab: (event, target, instance)=>{
21+
return ()=>{
22+
- const dest = getTabDestination.getTabDestination(target, instance.system.keyboard.modifiers.Shift);
23+
+ const dest = getTabDestination.getTabDestination(document.activeElement, instance.system.keyboard.modifiers.Shift);
24+
focus.focusElement(dest);
25+
if (selection.hasOwnSelection(dest)) {
26+
UI.setUISelection(dest, {
1427
diff --git a/dist/cjs/utils/focus/getActiveElement.js b/dist/cjs/utils/focus/getActiveElement.js
1528
index d25f3a8ef67e856e43614559f73012899c0b53d7..4ed9ee45565ed438ee9284d8d3043c0bd50463eb 100644
1629
--- a/dist/cjs/utils/focus/getActiveElement.js

packages/@react-spectrum/list/test/ListViewDnd.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2425,7 +2425,6 @@ describe('ListView', function () {
24252425

24262426
tree.rerender(<DragBetweenListsComplex secondListDnDOptions={{...mockUtilityOptions, onRootDrop: null, onInsert: null}} />);
24272427
await user.tab({shift: true});
2428-
await user.tab({shift: true});
24292428
await beginDrag(tree);
24302429
await user.tab();
24312430
// Should automatically jump to the folder target since we didn't provide onRootDrop and onInsert

packages/@react-spectrum/table/test/TableDnd.test.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,7 +2145,6 @@ describe('TableView', function () {
21452145
});
21462146
act(() => jest.runAllTimers());
21472147
await user.tab({shift: true});
2148-
await user.tab({shift: true});
21492148
await user.keyboard('{ArrowLeft}');
21502149

21512150
// Drop on folder in same table
@@ -2301,10 +2300,6 @@ describe('TableView', function () {
23012300
await user.keyboard('{Escape}');
23022301

23032302
tree.rerender(<DragBetweenTablesComplex secondTableDnDOptions={{...mockUtilityOptions, onRootDrop: null, onInsert: null}} />);
2304-
await user.tab({shift: true});
2305-
await user.tab({shift: true});
2306-
await user.keyboard('{ArrowLeft}');
2307-
await user.keyboard('{ArrowRight}');
23082303

23092304
let grids = tree.getAllByRole('grid');
23102305
let rowgroup = within(grids[0]).getAllByRole('rowgroup')[1];

packages/react-aria-components/test/GridList.test.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -782,10 +782,7 @@ describe('GridList', () => {
782782
expect(document.activeElement).toBe(items[1]);
783783

784784
await user.tab();
785-
expect(document.activeElement).toBe(buttonRef.current);
786-
787-
await user.tab();
788-
expect(document.activeElement).toBe(document.body);
785+
expect(document.body).toHaveFocus();
789786
});
790787

791788
it('should support rendering a TagGroup with tabbing navigation inside a GridListItem', async () => {

yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10219,10 +10219,10 @@ __metadata:
1021910219

1022010220
"@testing-library/user-event@patch:@testing-library/user-event@npm%3A14.6.1#~/.yarn/patches/@testing-library-user-event-npm-14.6.1-5da7e1d4e2.patch":
1022110221
version: 14.6.1
10222-
resolution: "@testing-library/user-event@patch:@testing-library/user-event@npm%3A14.6.1#~/.yarn/patches/@testing-library-user-event-npm-14.6.1-5da7e1d4e2.patch::version=14.6.1&hash=13cf21"
10222+
resolution: "@testing-library/user-event@patch:@testing-library/user-event@npm%3A14.6.1#~/.yarn/patches/@testing-library-user-event-npm-14.6.1-5da7e1d4e2.patch::version=14.6.1&hash=3511b9"
1022310223
peerDependencies:
1022410224
"@testing-library/dom": ">=7.21.4"
10225-
checksum: 10c0/ede32fec9345bb5e5c19a5abcb647d8c4704239f3f5417afe2914c1397067dae7ce547e46adfd4027c913f5735c0651ec530c73bdc5c7ea955efa860cc6a9dd9
10225+
checksum: 10c0/5a3e378cfdcad1ae09b73141ba9ea5adb0e7ed0d9f6bf1c4ba3631c91554414c4f2ab255c23f08425d2d398daa11d745ead8ef7ba0d1de76e19252db0b5dbba3
1022610226
languageName: node
1022710227
linkType: hard
1022810228

0 commit comments

Comments
 (0)