@testing-library/user-event
Advanced tools
Comparing version 8.0.3 to 8.0.4
@@ -201,2 +201,28 @@ import React from "react"; | ||
it("does not lose focus when click updates focus", () => { | ||
const FocusComponent = () => { | ||
const inputRef = React.useRef(); | ||
const focusInput = () => inputRef.current.focus(); | ||
return ( | ||
<React.Fragment> | ||
<input data-testid="input" ref={inputRef} /> | ||
<button onClick={focusInput}>Update Focus</button> | ||
</React.Fragment> | ||
); | ||
}; | ||
const { getByTestId, getByText } = render(<FocusComponent />); | ||
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"])( | ||
@@ -203,0 +229,0 @@ "gives focus to <%s> when clicking a <label> with htmlFor", |
@@ -147,2 +147,8 @@ "use strict"; | ||
function blurFocusedElement(element, focusedElement, wasAnotherElementFocused) { | ||
if (wasAnotherElementFocused && element.ownerDocument.activeElement === element) { | ||
focusedElement.blur(); | ||
} | ||
} | ||
const userEvent = { | ||
@@ -174,3 +180,3 @@ click(element) { | ||
wasAnotherElementFocused && focusedElement.blur(); | ||
blurFocusedElement(element, focusedElement, wasAnotherElementFocused); | ||
}, | ||
@@ -199,3 +205,3 @@ | ||
wasAnotherElementFocused && focusedElement.blur(); | ||
blurFocusedElement(element, focusedElement, wasAnotherElementFocused); | ||
}, | ||
@@ -225,3 +231,3 @@ | ||
wasAnotherElementFocused && focusedElement.blur(); | ||
blurFocusedElement(element, focusedElement, wasAnotherElementFocused); | ||
}, | ||
@@ -228,0 +234,0 @@ |
{ | ||
"name": "@testing-library/user-event", | ||
"version": "8.0.3", | ||
"version": "8.0.4", | ||
"description": "Simulate user events for react-testing-library", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -257,2 +257,3 @@ <div align="center"> | ||
<td align="center"><a href="https://github.com/maheshjag"><img src="https://avatars0.githubusercontent.com/u/1705603?v=4" width="100px;" alt=""/><br /><sub><b>MJ</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=maheshjag" title="Documentation">๐</a></td> | ||
<td align="center"><a href="https://github.com/jmcriffey"><img src="https://avatars0.githubusercontent.com/u/2831294?v=4" width="100px;" alt=""/><br /><sub><b>Jeff McRiffey</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=jmcriffey" title="Code">๐ป</a> <a href="https://github.com/testing-library/user-event/commits?author=jmcriffey" title="Tests">โ ๏ธ</a></td> | ||
</tr> | ||
@@ -259,0 +260,0 @@ </table> |
@@ -102,2 +102,11 @@ import { fireEvent } from "@testing-library/dom"; | ||
function blurFocusedElement(element, focusedElement, wasAnotherElementFocused) { | ||
if ( | ||
wasAnotherElementFocused && | ||
element.ownerDocument.activeElement === element | ||
) { | ||
focusedElement.blur(); | ||
} | ||
} | ||
const userEvent = { | ||
@@ -127,3 +136,3 @@ click(element) { | ||
wasAnotherElementFocused && focusedElement.blur(); | ||
blurFocusedElement(element, focusedElement, wasAnotherElementFocused); | ||
}, | ||
@@ -150,3 +159,3 @@ | ||
wasAnotherElementFocused && focusedElement.blur(); | ||
blurFocusedElement(element, focusedElement, wasAnotherElementFocused); | ||
}, | ||
@@ -178,3 +187,3 @@ | ||
wasAnotherElementFocused && focusedElement.blur(); | ||
blurFocusedElement(element, focusedElement, wasAnotherElementFocused); | ||
}, | ||
@@ -181,0 +190,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12863285
2167
268