Skip to content

When clicking outside input should blur #832

@piecyk

Description

@piecyk
  • @testing-library/user-event version: 14.0.0-beta.7
  • Testing Framework and version: jest 27.4.7
  • DOM Environment: jsdom

Relevant code or config

import "@testing-library/jest-dom";
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";

test("input should blur when clicking outside", () => {
  render(
    <div>
      <input type="text" data-testid="input-id" />
      <div data-testid="outside-id"></div>
    </div>
  );

  const input = screen.getByTestId("input-id");
  input.focus();
  expect(input).toHaveFocus();
  userEvent.type(input, "1,2");

  userEvent.click(screen.getByTestId("outside-id"));
  // input.blur();
  expect(input).not.toHaveFocus();
});

What you did:

When testing @testing-library/user-event 14 beta, notice that one of my test fails because when clicking outside input don't lose focus. It's working in 13.5.0

What happened:

Test fails as input element has focus after clicking outside.

Reproduction repository:

https://codesandbox.io/s/clickoutside-x5f3q?file=/src/ClickOutside.test.js

Problem description:

When clicking outside input should blur

Suggested solution:

Input should blur

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions