testing-library / testing-library/user-event

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

Open
#1,145 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
2.3k
Forks
258
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked CodeSandbox reproduction and the userEvent click implementation for version 14.4.3. Verify how visibility and interactability checks handle the button styled with visibility:hidden, then confirm that clicking it no longer succeeds as described in the issue and that the documentation behavior is consistent.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.