From 64773f6d1eb3e2489d67c2b7b1b7e298a3eedd9c Mon Sep 17 00:00:00 2001 From: KHeo Date: Mon, 6 Jan 2020 16:43:38 +0900 Subject: [PATCH] Fix transform + overflow error. --- packages/driver/src/dom/visibility.js | 25 +++++++++--- .../integration/dom/visibility_spec.js | 38 +++++++++++++++++++ 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/packages/driver/src/dom/visibility.js b/packages/driver/src/dom/visibility.js index 6e197e70de66..0984dde6cf98 100644 --- a/packages/driver/src/dom/visibility.js +++ b/packages/driver/src/dom/visibility.js @@ -97,18 +97,31 @@ const elHasNoEffectiveWidthOrHeight = ($el) => { // display:none elements, and generally any elements that are not directly rendered, // an empty list is returned. + const el = $el[0] + const style = getComputedStyle(el) + const transform = style.getPropertyValue('transform') + const width = elOffsetWidth($el) + const height = elOffsetHeight($el) + const overflowHidden = elHasOverflowHidden($el) + + return isZeroLengthAndTransformNone(width, height, transform) || + isZeroLengthAndOverflowHidden(width, height, overflowHidden) || + (el.getClientRects().length <= 0) +} + +const isZeroLengthAndTransformNone = (width, height, transform) => { // From https://github.com/cypress-io/cypress/issues/5974, // we learned that when an element has non-'none' transform style value like "translate(0, 0)", // it is visible even with `height: 0` or `width: 0`. // That's why we're checking `transform === 'none'` together with elOffsetWidth/Height. - const el = $el[0] - const style = getComputedStyle(el) - const transform = style.getPropertyValue('transform') + return (width <= 0 && transform === 'none') || + (height <= 0 && transform === 'none') +} - return (elOffsetWidth($el) <= 0 && transform === 'none') || - (elOffsetHeight($el) <= 0 && transform === 'none') || - ($el[0].getClientRects().length <= 0) +const isZeroLengthAndOverflowHidden = (width, height, overflowHidden) => { + return (width <= 0 && overflowHidden) || + (height <= 0 && overflowHidden) } const elHasNoOffsetWidthOrHeight = ($el) => { diff --git a/packages/driver/test/cypress/integration/dom/visibility_spec.js b/packages/driver/test/cypress/integration/dom/visibility_spec.js index ff8ee84721a0..5aca5f26913a 100644 --- a/packages/driver/test/cypress/integration/dom/visibility_spec.js +++ b/packages/driver/test/cypress/integration/dom/visibility_spec.js @@ -920,6 +920,44 @@ describe('src/cypress/dom/visibility', () => { expect(el.find('#tr-p-2')).to.be.hidden }) + + describe('invisible when overflow: hidden', () => { + it('height: 0 + overflow', () => { + const el = add('

Test

') + + expect(el.find('#h0th')).to.be.hidden + }) + + it('height: 0 + overflow-x', () => { + const el = add('

Test

') + + expect(el.find('#h0th')).to.be.hidden + }) + + it('height: 0 + overflow-y', () => { + const el = add('

Test

') + + expect(el.find('#h0th')).to.be.hidden + }) + + it('width: 0 + overflow', () => { + const el = add('

Test

') + + expect(el.find('#h0th')).to.be.hidden + }) + + it('width: 0 + overflow-x', () => { + const el = add('

Test

') + + expect(el.find('#h0th')).to.be.hidden + }) + + it('width: 0 + overflow-y', () => { + const el = add('

Test

') + + expect(el.find('#h0th')).to.be.hidden + }) + }) }) it('is hidden when outside parents transform scale', function () {