Skip to content

userEvent.click doesn't ignore hidden elements as the documentation says #1145

@haocheng6

Description

@haocheng6

Reproduction example

https://codesandbox.io/s/user-event-invisible-button-xpw2kf

Prerequisites

  1. Render an invisble button:
<button onClick={() => setClicked(true)} style={{visibility: 'hidden'}}>
  Click me!
</button>
  1. Select the button.
  2. Click the button using the click function of userEvent.

Expected behavior

The click function shouldn't work on invisible HTML elements. Maybe an error should be thrown in that case.

Actual behavior

Even though the documentation says

It adds visibility and interactability checks along the way and manipulates the DOM just like a user interaction in the browser would. It factors in that the browser e.g. wouldn't let a user click a hidden element or type in a disabled text box.

the click function still works on the invisible button.

User-event version

14.4.3

Environment

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions