Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Displayed and visible not affected by parent styles #47

Open
aleksre opened this issue Jul 31, 2020 · 4 comments
Open

Displayed and visible not affected by parent styles #47

aleksre opened this issue Jul 31, 2020 · 4 comments

Comments

@aleksre
Copy link

aleksre commented Jul 31, 2020

While I can understand that determining if an element is actually "displayed" or "visible" in a document can be tricky, the current implementation seems overly naive, failing to identify an element hidden through ancestry:

<div style="display: none">
  <span>Hidden?</span>
</div>
expect(document.querySelector('span')).to.be.displayed; // Tests passes, but the element is not displayed

IMO, both visible and displayed should return false if any ancestor element is styled with display: none.

@nathanboktae
Copy link
Owner

Yes that does make sense. I'd be a breaking change though; it can be included in the next major version (I'd like to make chai-dom an ES Module, see #38)

@aleksre
Copy link
Author

aleksre commented Aug 4, 2020

Thanks. Looking forward to it!

@jimsimon
Copy link

jimsimon commented Jul 9, 2021

This could be implemented now as a new Assertion and not be a breaking change. Maybe call it viewable?

@muratcorlu
Copy link

I agree that the current API is misleading and not very helpful. Can we consider to use jQuery's :visible selector approach?

	return !!( elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length );

...which looks convincing enough about element's visibility.

Elements are considered visible if they consume space in the document. Visible elements have a width or height that is greater than zero.
https://api.jquery.com/visible-selector/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants