From 4bcab8c18d6f20c742821ce325cd753089c7ee94 Mon Sep 17 00:00:00 2001 From: Jeff McRiffey Date: Wed, 22 Jan 2020 23:55:12 -0500 Subject: [PATCH] fix(click): click no longer blurs when focus changes during onClick event (#208) --- __tests__/react/click.js | 26 ++++++++++++++++++++++++++ src/index.js | 15 ++++++++++++--- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/__tests__/react/click.js b/__tests__/react/click.js index 7d8d6d51..a7a7edf9 100644 --- a/__tests__/react/click.js +++ b/__tests__/react/click.js @@ -198,6 +198,32 @@ describe("userEvent.click", () => { expect(b).toHaveFocus(); }); + it("does not lose focus when click updates focus", () => { + const FocusComponent = () => { + const inputRef = React.useRef(); + const focusInput = () => inputRef.current.focus(); + + return ( + + + + + ); + }; + const { getByTestId, getByText } = render(); + + const input = getByTestId("input"); + const button = getByText("Update Focus"); + + expect(input).not.toHaveFocus(); + + userEvent.click(button); + expect(input).toHaveFocus(); + + userEvent.click(button); + expect(input).toHaveFocus(); + }); + it.each(["input", "textarea"])( "gives focus to <%s> when clicking a