Skip to content

Commit

Permalink
Bug 1949953 - Show offset parent of fixed position elements if not ro…
Browse files Browse the repository at this point in the history
…ot. r=devtools-reviewers,nchevobbe

Shows in DevTools > Layout > Box Model > Box Model Properties.

Differential Revision: https://phabricator.services.mozilla.com/D239268
  • Loading branch information
jamesnw committed Feb 27, 2025
1 parent 3f0a673 commit 903705e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@ class BoxModelProperties extends PureComponent {

if (
propertyName === "position" &&
this.props.boxModel.offsetParent &&
value !== "static" &&
value !== "fixed" &&
this.props.boxModel.offsetParent
// A fixed position element's offsetParent is the <body> element if its
// containing block is the viewport. We only show the offsetParent for
// fixed position elements if the offsetParent is not the viewport. This
// can occur if the element has an ancestor that creates a fixed position
// containing block, for instance with a `transform` declaration.
(value !== "fixed" || this.props.boxModel.offsetParent.tagName !== "BODY")
) {
return {
referenceElement: this.props.boxModel.offsetParent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const TEST_URI = `
<div id="static"></div>
<div id="no_parent" style="position: absolute"></div>
<div id="fixed" style="position: fixed"></div>
<div id="transform" style="transform: translate(0,0)">
<div id="transform-fixed" style="position: fixed"></div>
</div>
`;

const OFFSET_PARENT_SELECTOR =
Expand All @@ -39,6 +42,10 @@ const res1 = [
selector: "#fixed",
offsetParentValue: null,
},
{
selector: "#transform-fixed",
offsetParentValue: "div#transform",
},
];

const updates = [
Expand Down

0 comments on commit 903705e

Please sign in to comment.