Skip to content

Commit

Permalink
fix(color-contrast): handle text that is outside overflow: hidden anc…
Browse files Browse the repository at this point in the history
…estor
  • Loading branch information
straker committed Mar 5, 2024
1 parent c5e11de commit 4b5ab70
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/commons/dom/get-visible-child-text-rects.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,14 @@ const getVisibleChildTextRects = memoize(
* @see https://github.com/dequelabs/axe-core/issues/2178
* @see https://github.com/dequelabs/axe-core/issues/2483
* @see https://github.com/dequelabs/axe-core/issues/2681
*
* also need to resize the nodeRect to fit within the bounds of any overflow: hidden ancestors.
*
* @see https://github.com/dequelabs/axe-core/issues/4253
*/
return clientRects.length ? clientRects : [nodeRect];
return clientRects.length
? clientRects
: filterHiddenRects([nodeRect], overflowHiddenNodes);
}
);
export default getVisibleChildTextRects;
Expand Down
16 changes: 16 additions & 0 deletions test/commons/dom/get-visible-child-text-rects.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,20 @@ describe('dom.getVisibleChildTextRects', () => {

assert.lengthOf(actual, 2);
});

it('changes nodeRect size if all text rects got outside ancestor overflow', () => {
fixtureSetup(`
<div style="overflow: hidden; width: 50px;">
<div style="overflow: hidden; width: 25px">
<div id="target" style="padding-left: 65px;">Hello World</div>
</div>
</div>
`);
const node = fixture.querySelector('#target');
const actual = getVisibleChildTextRects(node);
const rect = getClientRects(node)[0];
const expected = new DOMRect(rect.left, rect.top, 25, rect.height);

assertRectsEqual(actual, [expected]);
});
});

0 comments on commit 4b5ab70

Please sign in to comment.