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

Wrong width() of html elements inside SVG foreign object #5011

Closed
jcubic opened this issue Feb 9, 2022 · 2 comments
Closed

Wrong width() of html elements inside SVG foreign object #5011

jcubic opened this issue Feb 9, 2022 · 2 comments

Comments

@jcubic
Copy link

jcubic commented Feb 9, 2022

Description

I'm not sure if you want this to be reported (because of #4741) but .width() don't return the same value as .getBoundingClientRect() for html DOM nodes inside SVG. But I don't use SVG elements, but HTML elements inside foreign object. The size works but it return different value than getBoundingClientRect().

At least jQuery should work the same as native API for this case.

Link to test case

Here is a link to a demo that uses my library jQuery Terminal that is inside SVG.
https://codepen.io/jcubic/pen/abVJrob?editors=0010

Additional info

There are two types of issues, one with padding/margins/scrollbar that is way bigger because 1px in SVG is not the same as 1px on the screen (). But the main issue is that .width() returns completely wrong results, that's why my library thinks that the screen is much smaller (the long line wrapping is done in JavaScript).

Let me know if this is something you would like to handle/fix in jQuery and if you want simpler reproduction.

@Shakti111
Copy link

ok

@mgol
Copy link
Member

mgol commented Feb 25, 2022

Thanks for the report. However, jQuery .width() is supposed to return the computed CSS width of the element and not the actual size on the screen so the output is as expected.

This is so unnatural because the CSS dimensions seem to refer to viewBox and not regular pixel values. However, that's just an SVG quirk and I don't see a good way to address that while still being true to the docs. Especially that we don't fully support SVGs per https://github.com/jquery/jquery/wiki/Won't-Fix#svg-or-vml and the issue you linked.

@mgol mgol closed this as completed Feb 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants