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

Updates to handle when a call to obj.getBoundingClientRect() throws an error or returns an empty object #357

Merged
merged 1 commit into from
Sep 4, 2019

Conversation

nmfriesen
Copy link
Contributor

This update adds a getBoundingClientRect(node) function to dom-geometry
that will call node.getBoundingClientRect() but if it throws an error
(this can happen in IE when the node is not in the DOM) or an empty
object is returned (this can happen in Edge when the node is not in the
DOM) an object with all values set to 0 will be returned. This will
prevent errors when the node is not in the DOM.

fixes #356

error or returns an empty object

This update adds a getBoundingClientRect(node) function to dom-geometry
that will call node.getBoundingClientRect() but if it throws an error
(this can happen in IE when the node is not in the DOM) or an empty
object is returned (this can happen in Edge when the node is not in the
DOM) an object wil all values set to 0 will be returned. This will
prevent errors when the node is not in the DOM.
@wkeese
Copy link
Member

wkeese commented Jun 3, 2019

This seems like a step backwards, if getBoundingClientRect() fails isn't it better to throw an error than to return a non-sensical value?

@nmfriesen
Copy link
Contributor Author

From what I can tell, FireFox and Chrome currently return { x: 0, y: 0, width: 0, height: 0, top: 0, right: 0, bottom: 0, left: 0 } when the node is not on the DOM. I was trying to get the browsers to behave consistently. I leaned towards the option that returned an object in the format that was expected so the calculations that use it could continue without throwing an error.

@wkeese
Copy link
Member

wkeese commented Jun 6, 2019

Hmm, I agree consistency is a good thing.

@dylans
Copy link
Member

dylans commented Sep 4, 2019

As this is a new addition, it will get added for 1.16.0

@dylans dylans merged commit 56b22bb into dojo:master Sep 4, 2019
@dylans dylans added this to the 1.16.0 milestone Sep 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants