Skip to content

Commit

Permalink
fix(isHidden): position fixed always return true
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Mar 2, 2023
1 parent 2b304bb commit 0041bd1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
24 changes: 22 additions & 2 deletions src/isHidden.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,31 @@ exports = function(
overflow = false
} = {}
) {
const computedStyle = getComputedStyle(el);

if (display) {
return el.offsetParent === null;
const tagName = el.tagName;
if (
tagName === 'BODY' ||
tagName === 'HTML' ||
computedStyle.position === 'fixed'
) {
if (computedStyle.display === 'none') {
return true;
} else {
let cur = el;
while ((cur = cur.parentElement)) {
const computedStyle = getComputedStyle(cur);
if (computedStyle.display === 'none') {
return true;
}
}
}
} else if (el.offsetParent === null) {
return true;
}
}

const computedStyle = getComputedStyle(el);
if (visibility && computedStyle.visibility === 'hidden') {
return true;
}
Expand Down
11 changes: 10 additions & 1 deletion test/isHidden.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@ it('display', function() {
const $display = $dom.find('.display');
expect(isHidden($display.get(0), options)).to.be.true;
$display.append('<div class="inner"></div>');
expect(isHidden($display.find('.inner').get(0), options)).to.be.true;
const $inner = $display.find('.inner');
expect(isHidden($inner.get(0), options)).to.be.true;

// position: fixed
$inner.css('position', 'fixed');
expect(isHidden($inner.get(0), options)).to.be.true;
$display.css('display', 'block');
expect(isHidden($inner.get(0), options)).to.be.false;
$inner.css('display', 'none');
expect(isHidden($inner.get(0), options)).to.be.true;
});

it('visibility', function() {
Expand Down

0 comments on commit 0041bd1

Please sign in to comment.