diff --git a/react-responsive-modal/__tests__/index.test.tsx b/react-responsive-modal/__tests__/index.test.tsx index a2021677..4c10bc7d 100644 --- a/react-responsive-modal/__tests__/index.test.tsx +++ b/react-responsive-modal/__tests__/index.test.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import { render, fireEvent, waitFor } from '@testing-library/react'; +import { fireEvent, render, waitFor } from '@testing-library/react'; import { Modal } from '../src'; describe('modal', () => { @@ -441,6 +441,55 @@ describe('modal', () => { }); }); + describe('prop: focusTrapOptions', () => { + describe('default settings', () => { + it('should focus first tabbable element', () => { + const { queryByTestId } = render( + null}> + + modal content + + + ); + expect(queryByTestId('first-item')).toHaveFocus(); + }); + }); + + describe('when focusOn is firstFocusableElement', () => { + it('should focus first tabbable element', () => { + const { queryByTestId } = render( + null} + focusTrapOptions={{ focusOn: 'firstFocusableElement' }} + > + + modal content + + + ); + expect(queryByTestId('first-item')).toHaveFocus(); + }); + }); + + describe('when focusOn is modalRoot', () => { + it('should focus modal root', () => { + const { queryByTestId } = render( + null} + focusTrapOptions={{ focusOn: 'modalRoot' }} + > + + modal content + + + ); + expect(queryByTestId('modal')).toHaveFocus(); + }); + }); + }); + describe('prop: onEscKeyDown', () => { it('should be called when esc key is pressed', async () => { const onEscKeyDown = jest.fn();