Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(target-size): support translucent elements within pseudo-stacking-context ancestors with implicit z-order #4351

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions lib/commons/dom/create-grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ function isStackingContext(vNode, parentVNode) {
}

// elements with an opacity value less than 1.
// See https://www.w3.org/TR/css-color-3/#transparency
if (vNode.getComputedStylePropertyValue('opacity') !== '1') {
return true;
}
Expand Down Expand Up @@ -270,9 +271,7 @@ function createStackingOrder(vNode, parentVNode, treeOrder) {
// that point (step #5 and step #8)
// @see https://www.w3.org/Style/css2-updates/css2/zindex.html
if (isStackingContext(vNode, parentVNode)) {
const index = stackingOrder.findIndex(({ stackLevel }) =>
[ROOT_LEVEL, FLOAT_LEVEL, POSITION_LEVEL].includes(stackLevel)
);
const index = stackingOrder.findIndex(isFakeStackingContext);
if (index !== -1) {
stackingOrder.splice(index, stackingOrder.length - index);
}
Expand Down Expand Up @@ -302,6 +301,23 @@ function createStackingContext(stackLevel, treeOrder, vNode) {
};
}

function isFakeStackingContext(stackingContext) {
const { stackLevel, vNode } = stackingContext;

// elements with opacity < 1 must be treated as their own stacking context,
// even if drawn POSITION_LEVEL layer order.
// See https://www.w3.org/TR/css-color-3/#transparency
if (vNode && vNode.getComputedStylePropertyValue('opacity') !== '1') {
return false;
}

if ([ROOT_LEVEL, FLOAT_LEVEL, POSITION_LEVEL].includes(stackLevel)) {
return true;
}

return false;
}

/**
* Calculate the level of the stacking context.
* @param {VirtualNode} vNode - The virtual node container of the stacking context
Expand All @@ -324,6 +340,15 @@ function getStackLevel(vNode, parentVNode) {
return POSITION_LEVEL;
}

// From https://www.w3.org/TR/css-color-3/#transparency:
//
// > If an element with opacity less than 1 is not positioned, then it is
// > painted on the same layer, within its parent stacking context, as positioned
// > elements with stack level 0.
if (vNode.getComputedStylePropertyValue('opacity') !== '1') {
return POSITION_LEVEL;
}

// Put floated elements above z-index: 0
// (step #5 floating get sorted below step #8 positioned)
if (vNode.getComputedStylePropertyValue('float') !== 'none') {
Expand Down
10 changes: 9 additions & 1 deletion test/integration/rules/target-size/target-size.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</textarea>
</p>

<!-- Nested controls-->
<!-- Nested controls -->
<p>
<a
role="link"
Expand All @@ -53,6 +53,14 @@
</a>
</p>

<!-- Regression test for stacking context behavior from #4350 -->
<div style="margin: 30px; height: 50px">
<div style="position: absolute; transform: scale(1)">
<a href="#" id="pass9">wide enough</a>
<a href="#" id="pass10" style="opacity: 0.6">also wide enough</a>
</div>
</div>

<!-- Failed examples -->
<p>
<button id="fail1">x</button
Expand Down
2 changes: 2 additions & 0 deletions test/integration/rules/target-size/target-size.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
["#pass6"],
["#pass7"],
["#pass8"],
["#pass9"],
["#pass10"],
["#pass-adjacent"],
["#pass-fixed"]
],
Expand Down
Loading