Skip to content

Commit e67fc65

Browse files
authored
fix: handle noscript and template in dom.isVisible (#1257)
1 parent 26fa49a commit e67fc65

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

lib/commons/dom/is-visible.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* global dom */
2-
/* eslint complexity: ["error", 18] */
2+
/* eslint complexity: ["error", 20] */
33

44
/**
55
* Determines if an element is hidden with the clip rect technique
@@ -56,8 +56,7 @@ dom.isVisible = function(el, screenReader, recursed) {
5656

5757
if (
5858
style.getPropertyValue('display') === 'none' ||
59-
nodeName.toUpperCase() === 'STYLE' ||
60-
nodeName.toUpperCase() === 'SCRIPT' ||
59+
['STYLE', 'SCRIPT', 'NOSCRIPT', 'TEMPLATE'].includes(nodeName) ||
6160
(!screenReader && isClipped(style.getPropertyValue('clip'))) ||
6261
(!recursed &&
6362
// visibility is only accurate on the first element

test/commons/dom/is-visible.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
describe('dom.isVisible', function() {
22
'use strict';
3+
34
var fixture = document.getElementById('fixture');
5+
var fixtureSetup = axe.testUtils.fixtureSetup;
46
var shadowSupported = axe.testUtils.shadowSupport.v1;
57
var fakeNode = {
68
nodeType: Node.ELEMENT_NODE,
@@ -78,6 +80,33 @@ describe('dom.isVisible', function() {
7880
assert.isTrue(axe.commons.dom.isVisible(document));
7981
});
8082

83+
it('should return false on STYLE tag', function() {
84+
var fixture = fixtureSetup(
85+
'<style id="target"> @import "https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.css"; .green { background-color: green; } </style>'
86+
);
87+
var node = fixture.querySelector('#target');
88+
var actual = axe.commons.dom.isVisible(node);
89+
assert.isFalse(actual);
90+
});
91+
92+
it('should return false on NOSCRIPT tag', function() {
93+
var fixture = fixtureSetup(
94+
'<noscript id="target"><p class="invisible"><img src="/piwik/piwik.php?idsite=1" alt="" /></p></noscript>'
95+
);
96+
var node = fixture.querySelector('#target');
97+
var actual = axe.commons.dom.isVisible(node);
98+
assert.isFalse(actual);
99+
});
100+
101+
it('should return false on TEMPLATE tag', function() {
102+
var fixture = fixtureSetup(
103+
'<template id="target"><div>Name:</div></template>'
104+
);
105+
var node = fixture.querySelector('#target');
106+
var actual = axe.commons.dom.isVisible(node);
107+
assert.isFalse(actual);
108+
});
109+
81110
it('should return true if positioned staticly but top/left is set', function() {
82111
fixture.innerHTML =
83112
'<div id="target" style="top: -9999px; left: -9999px;' +

0 commit comments

Comments
 (0)