diff --git a/src/mantine-core/src/components/FocusTrap/FocusTrap.test.tsx b/src/mantine-core/src/components/FocusTrap/FocusTrap.test.tsx index 5e22b52442a..6b7801d58e2 100644 --- a/src/mantine-core/src/components/FocusTrap/FocusTrap.test.tsx +++ b/src/mantine-core/src/components/FocusTrap/FocusTrap.test.tsx @@ -49,6 +49,71 @@ describe('@mantine/core/FocusTrap', () => { expect(document.body).toHaveFocus(); }); + it('traps focus on shift + tab', async () => { + render( + +
+ + + +
+
+ ); + + await wait(10); + expect(screen.getByRole('textbox')).toHaveFocus(); + + userEvent.tab(); + expect(screen.getByRole('button')).toHaveFocus(); + + userEvent.tab({ shift: true }); + await wait(10); + expect(screen.getByRole('textbox')).toHaveFocus(); + + userEvent.tab({ shift: true }); + await wait(10); + expect(screen.getByRole('radio')).toHaveFocus(); + }); + + it('traps focus on shift + tab and handles Radio Groups', async () => { + render( + +
+ + + + + + + +
+
+ ); + + await wait(10); + expect(screen.getByLabelText('Option One')).toHaveFocus(); + + userEvent.tab(); + expect(screen.getByRole('button')).toHaveFocus(); + + userEvent.tab({ shift: true }); + await wait(10); + expect(screen.getByLabelText('Option Three')).toHaveFocus(); + + userEvent.tab({ shift: true }); + await wait(10); + expect(screen.getByRole('button')).toHaveFocus(); + }); + it('manages aria-hidden attributes', () => { const adjacentDiv = document.createElement('div'); adjacentDiv.setAttribute('data-testid', 'adjacent');