Skip to content

[actions] Handling of "display:contents" element as origin #1887

Open
@whimboo

Description

@whimboo

Similar to issue #1642 (display: none) an element that has a style of display: contents defined doesn't have a bounding box and retrieving the coordinates will fail. In Firefox we currently raise a move target out of bounds error when trying to move the pointer to the element specified as origin.

Here a HTML testcase:

<div>Example text, and button here:
  <button style="display: contents" onclick="alert('clicked')">click me</button>
</div>

In case of this example a possible solution to still get the bounding client rect would be to create a Range object for the button, which itself has the bounding client rect information that we need:

const button = document.querySelector("button");

const range = document.createRange();
range.selectNodeContents(button);

const rect = range.getBoundingClientRect();
console.log(rect);

The output in the console will be:

DOMRect { x: 208.85000610351562, y: 8.600006103515625, width: 51.09999084472656, height: 16, top: 8.600006103515625, right: 259.9499969482422, bottom: 24.600006103515625, left: 208.85000610351562 }

This also seems to work when the affected element has DOM nodes as children:

<div style="display: content">Text with DOM nodes:
  <span>Text</span>
  <span>more</span>
</div>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions