Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

support for SVG elements #91

Closed
khusamov opened this issue Apr 24, 2022 · 9 comments
Closed

support for SVG elements #91

khusamov opened this issue Apr 24, 2022 · 9 comments

Comments

@khusamov
Copy link

khusamov commented Apr 24, 2022

Will there be support for SVG elements or not?

Now the error appears. Since the SVG element is not compatible with the HTML element.

TS2322: Type '(instance: HTMLElement | null) => void' is not assignable to type 'LegacyRef<SVGSVGElement>'.   
Type '(instance: HTMLElement | null) => void' is not assignable to type '(instance: SVGSVGElement | null) => void'.     
Types of parameters 'instance' and 'instance' are incompatible.       
Type 'SVGSVGElement | null' is not assignable to type 'HTMLElement | null'.         
Type 'SVGSVGElement' is missing the following properties from type 'HTMLElement': 
accessKey, accessKeyLabel, autocapitalize, dir, and 19 more.
@ZeeCoder
Copy link
Owner

Seems like the TS types will need to change from using HTMLElement to simply Element, as ResizeObserver itself can observe any Element.

github-actions bot pushed a commit that referenced this issue May 15, 2022
# [9.0.0](v8.0.0...v9.0.0) (2022-05-15)

### Bug Fixes

* Added some fixes for React 18. ([852d976](852d976)), closes [#90](#90) [#91](#91) [#92](#92)

### BREAKING CHANGES

* The lib now takes "Element", not only "HTMLElement", to
be consistent with ResizeObserver.
@github-actions
Copy link

🎉 This issue has been resolved in version 9.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@khusamov
Copy link
Author

Thank you very much!

@khusamov
Copy link
Author

I checked working with SVG. Does not work. The height variable is always zero.

@ZeeCoder
Copy link
Owner

I checked working with SVG. Does not work. The height variable is always zero.

Could you please provide reproduction in codesandbox?
it would be even better if you could check using raw ResizeObserver first, as it's known to be a bit quirky with svgs.

@ZeeCoder ZeeCoder reopened this May 21, 2022
@khusamov
Copy link
Author

https://codesandbox.io/s/use-resize-observer-hsxycd?file=/src/App.tsx

It is required to display a square in the middle of the browser. But instead of the browser dimensions, the dimensions of the square are substituted in height, width.

@ZeeCoder
Copy link
Owner

Here's a slightly modified version of that sandbox:
https://codesandbox.io/s/use-resize-observer-forked-29q3fg?file=/src/App.tsx

As you can see the hook reports the same exact values that a raw ResizeObserver reports, so I see no issues with the hook based on this example.

@khusamov
Copy link
Author

Why doesn't it return the dimensions of the SVG container?

@ZeeCoder
Copy link
Owner

Not 100% sure, the ResizeObserver spec around SVGs is a bit weird.

Here's some stuff I found, hope it helps:

Also I wonder if you could just wrap your SVG in a div and measure that instead?
Might help you depending on your exact use-case.

Repository owner locked and limited conversation to collaborators May 24, 2022
@ZeeCoder ZeeCoder converted this issue into discussion #94 May 24, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

2 participants