Skip to content

Commit

Permalink
suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
straker committed Aug 15, 2023
1 parent 093026c commit c4cd3cf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/commons/dom/get-target-rects.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import findNearbyElms from './find-nearby-elms';
import isInTabOrder from './is-in-tab-order';
import { splitRects, hasVisualOverlap } from '../math';
import memoize from '../../core/utils/memoize';

Expand All @@ -14,8 +15,9 @@ function getTargetRects(vNode) {
const nodeRect = vNode.boundingClientRect;
const overlappingVNodes = findNearbyElms(vNode).filter(vNeighbor => {
return (
hasVisualOverlap(vNode, vNeighbor) &&
vNeighbor.getComputedStylePropertyValue('pointer-events') !== 'none' &&
hasVisualOverlap(vNode, vNeighbor)
!isDescendantNotInTabOrder(vNode, vNeighbor)
);
});

Expand All @@ -28,3 +30,9 @@ function getTargetRects(vNode) {
);
return splitRects(nodeRect, obscuringRects);
}

function isDescendantNotInTabOrder(vAncestor, vNode) {
return (
vAncestor.actualNode.contains(vNode.actualNode) && !isInTabOrder(vNode)
);
}
23 changes: 23 additions & 0 deletions test/commons/dom/get-target-rects.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ describe('get-target-rects', () => {
assert.deepEqual(rects, [vNode.actualNode.getBoundingClientRect()]);
});

it('ignores non-tabbable descendants of the target', () => {
const vNode = queryFixture(`
<button id="target" style="width: 30px; height: 40px; position: absolute; left: 10px; top: 5px">
<div style="position: absolute; left: 5px; top: 5px; width: 50px; height: 50px;"></div>
</button>
`);
const rects = getTargetRects(vNode);
assert.deepEqual(rects, [vNode.actualNode.getBoundingClientRect()]);
});

it('returns each unobscured area', () => {
const vNode = queryFixture(`
<button id="target" style="width: 30px; height: 40px; position: absolute; left: 10px; top: 5px">x</button>
Expand All @@ -56,4 +66,17 @@ describe('get-target-rects', () => {
const rects = getTargetRects(vNode);
assert.lengthOf(rects, 0);
});

it('returns subset rect of the target with tabbable descendant', () => {
const vNode = queryFixture(`
<button id="target" style="width: 30px; height: 40px; position: absolute; left: 10px; top: 5px">
<div tabindex="0" style="position: absolute; left: 5p; top: 5px; width: 50px; height: 50px;"></div>
</button>
`);
const rects = getTargetRects(vNode);
assert.deepEqual(rects, [
new DOMRect(10, 5, 30, 7),
new DOMRect(10, 5, 8, 40)
]);
});
});
2 changes: 2 additions & 0 deletions test/integration/full/target-size/target-size.html
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@
</span>
</div>
<div>
<!-- this should technically fail the target-size rule if we were implementing the size based on the largest inscribed square -->
<span class="passed h6 w10 rnd-50">
<span class="failed h2 w2 mt2 ml4"></span>
</span>
Expand Down Expand Up @@ -642,6 +643,7 @@
</span>
</div>
<div>
<!-- this should technically fail the target-size rule if we were implementing the size based on the largest inscribed square -->
<span class="passed h6 w10 rnd-0-100">
<span class="passed h4 w4 mt1 ml1"></span>
</span>
Expand Down

0 comments on commit c4cd3cf

Please sign in to comment.