Skip to content

Cannot tab in react-modal #820

Closed
Closed
@danny-does-stuff

Description

@danny-does-stuff
  • @testing-library/user-event version: 12.0.2

  • Testing Framework and version: Jest, whatever version CodeSandbox uses

  • DOM Environment: jsdom, whatever version CodeSandbox uses

Relevant code or config

import Modal from 'react-modal';

function ModalTest() {
  return (
      <Modal isOpen={true}>
         <button>button 1</button>
          <button>button 2</button>
      </Modal>;
}

it('should allow tabbing inside of a modal', () => {
  const { getByText } = render(<ModalTest {...props} />);

  const button1 = getByText("button 1");
  const button2 = getByText("button 2");

  expect(button1).toBeInTheDocument();
  expect(button2).toBeInTheDocument();

  button1.focus();
  expect(button1).toHaveFocus();
  userEvent.tab();
  // fails right here
  expect(button2).toHaveFocus();
});

What you did:

  1. Render a Modal from react-modal with some tabbable elements
  2. Try to tab between elements using userEvent.tab()

What happened:
3. The focused element does not change 😢

image

Reproduction repository:
https://codesandbox.io/s/xenodochial-mestorf-qx6j8?file=/src/__tests__/index.js

Problem description:
Tabbing does not work properly when inside of a react-modal.

Additional notes:

I'm aware the issue could be in the react-modal library, so I made a companion issue over there (clicky). I'm also thinking I could just need more understanding of how the focus trapping is working in react-modal / user-event so I can get them to play together nicely.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions