w3c / w3c/webdriver

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

Open
#1,887 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs-discussion Perform Actions
Dominant language
HTML
Stars
718
Forks
228
PR merge metrics
No merged PRs in 30d

Description

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>

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 by comparing this report with issue #1642 and reproduce the HTML examples in Firefox, including the JavaScript Range.getBoundingClientRect() case. Trace how a display: contents element is handled as a pointer origin and verify that the resulting coordinates avoid the reported move target out of bounds error.

Written by the indexing model from the issue text.

Assessment

Tech stack
html, javascript
Domain
api, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.