Skip to content

Commit 763eae4

Browse files
authored
Update to focus-trap@8.0.0 with breaking changes (#1801)
* Update to focus-trap@8.0.0 with breaking changes * Fix tests
1 parent 8d8e607 commit 763eae4

4 files changed

Lines changed: 17 additions & 7 deletions

File tree

.changeset/focus-trap-8-upgrade.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"focus-trap-react": major
3+
---
4+
5+
**BREAKING:** Updated [focus-trap](https://github.com/focus-trap/focus-trap/blob/master/CHANGELOG.md#800) dependency to v8.0.0. The breaking change is that `onPostActivate()` is now correctly called after the initial focus node is focused (it was previously called before due to a bug with the initial focus delay). See the focus-trap changelog for more details.

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
"typescript": "^5.9.3"
109109
},
110110
"dependencies": {
111-
"focus-trap": "^7.8.0",
111+
"focus-trap": "^8.0.0",
112112
"tabbable": "^6.4.0"
113113
},
114114
"peerDependencies": {

test/focus-trap-react.test.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,16 @@ describe('FocusTrap', () => {
381381

382382
await pause(3);
383383

384+
// `checkCanFocusTrap` not yet resolved so no post-activate
384385
expect(onActivate).toHaveBeenCalled();
385386
expect(onPostActivate).not.toHaveBeenCalled();
386387

387388
await pause(6);
388389

390+
// `checkCanFocusTrap` should have resolved now, but post-activate
391+
// is still delayed to the next frame (trap behavior)
389392
expect(onActivate).toHaveBeenCalled();
390-
expect(onPostActivate).toHaveBeenCalled();
393+
await waitFor(() => expect(onPostActivate).toHaveBeenCalled());
391394
});
392395

393396
it('Does not call onPostDeactivate() until checkCanReturnFocus() has completed', async () => {
@@ -456,7 +459,9 @@ describe('FocusTrap', () => {
456459
fireEvent.click(activateTrapButton);
457460

458461
expect(onActivate).toHaveBeenCalled();
459-
expect(onPostActivate).toHaveBeenCalled();
462+
463+
// post-activate is always delayed to next frame by the trap
464+
await waitFor(() => expect(onPostActivate).toHaveBeenCalled());
460465
});
461466

462467
it('Will call onPostDeactivate() even if checkCanReturnFocus() is undefined', async () => {

0 commit comments

Comments
 (0)