I've created a web component and am attempting to add a ResizeObserver to the element.
ResizeObserver is added on connectedCallback which appears to fire only once upon the element being added to the DOM, but never again when the element resizes.
I would expect that the ResizeObserver would be fired when the component is forced to resize by it's parent element. I've checked and watched the element size in the developer tools, and it definitely resizes.
I have also tested the same code with standard HTML element (id: #foo) and the callback works. So I can only assume the problem is related to the shadow DOM.
the specification says:
I can confirm that point #1 happens.
I expect that point #5 should happen, but it never does. If Inspect the element, it's size is not 0,0 and does resize with the page.
I've gone over the MDN documentation for web components and ResizeObserver and a number of other websites and as far as I understand, I have everything correct.
Here is a JSFiddle of the code: https://jsfiddle.net/h15e48fx/1/
The custom element style defaultes to display: inline.
Setting it to display: block causes the ResizeObserver to fire when the component resizes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With