Skip to content

"isVisible" is incorrectly assessed for the absolutely positioned elements if the ancestor has overflow and static position #28638

@klarzynskik

Description

@klarzynskik

Current behavior

It appears "isVisible" is incorrectly assessed for the absolutely positioned elements if the ancestor has an overflow and static position. For example, for the following document the #visible-button is considered as not-visible:

<body>
  <div style="height: 200px; position: relative; display: flex">
    <div style="border: 5px solid red">
      <div
        id="breaking-container"
        style="overflow: auto; border: 5px solid green"
      >
        <div>
          <h1>Example</h1>
          <div style="position: absolute; bottom: 5px">
            <button id="visible-button" style="position: relative">
              Try me
            </button>
          </div>
        </div>
      </div>
    </div>
  </div>
</body>

Here's the screenshot from the test:

button shown as not visible despite being there

It appears that in this case, while assessing the isVisible, the button goes particularly into the isHidddenByAncestors. Then while calculating the elIsOutOfBoundsOfAncestorsOverflow for the #breaking-container div element from the example, the canClipContent is incorrectly assessed. That element has a default position: static, thus does not affect the visibility of the button. However, this is not checked in the canClipContent, resulting in the incorrectly assessed visibility via calculating the button's position compared to that div.

The documentation in that particular states that:

Any of its ancestors hides overflow*
AND the element is position: relative
AND it is positioned outside that ancestor's bounds

However, as mentioned above, I think that this should be true only if the considered ancestor's position is not static.

Desired behavior

Element visibility is correctly assessed.

Test code to reproduce

Here's the repository: https://github.com/klarzynskik/cypress-visibility-issue-demo

The simplest example is the following code:

<div id="breaking-container" style="overflow: auto">
      <div>
        <div style="position: absolute; bottom: 5px">
          <button id="visible-button">Try me</button>
        </div>
      </div>
</div>

Cypress Version

13.6.2

Node version

18.16.1

Operating System

macOS 13.4.1

Debug Logs

No response

Other

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions