Skip to content

Commit

Permalink
fix(click): correct focus changes based on mouseDown result (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyamkin committed Jan 28, 2020
1 parent d9a7bdc commit ed59735
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
18 changes: 18 additions & 0 deletions __tests__/react/click.js
Expand Up @@ -321,4 +321,22 @@ describe("userEvent.click", () => {
userEvent.click(getByText("Submit"));
expect(onSubmit).not.toHaveBeenCalled();
});

it.each(["input", "textarea"])(
"should not give focus for <%s> when mouseDown is prevented",
type => {
const { getByTestId } = render(
React.createElement(type, {
"data-testid": "element",
onMouseDown: (evt) => {
evt.preventDefault();
},
})
);

userEvent.click(getByTestId("element"));

expect(getByTestId("element")).not.toHaveFocus();
}
);
});
6 changes: 4 additions & 2 deletions src/index.js
Expand Up @@ -44,8 +44,10 @@ function clickBooleanElement(element) {
function clickElement(element) {
fireEvent.mouseOver(element);
fireEvent.mouseMove(element);
fireEvent.mouseDown(element);
element.focus();
const continueDefaultHandling = fireEvent.mouseDown(element);
if (continueDefaultHandling) {
element.focus();
}
fireEvent.mouseUp(element);
fireEvent.click(element);

Expand Down

0 comments on commit ed59735

Please sign in to comment.