I am having a pretty simple few lines to determine the computed width and height of a DOM element. Or so I thought:
const computedStyle = window.getComputedStyle(element, null);
// const width = computedStyle.getPropertyValue('width');
const width = computedStyle['width'];
console.log(width); // 'auto'
console.log("computed", computedStyle);
However, when I log the value for width, I am getting 'auto', no matter if I access it directly as a property or through the getPropertyValue getter. But when I just check the value in the log of the entire computedStyle object, I am getting the following:
which is clearly not the same.
What is the problem here? Does it have to do with the dynamic nature of getComputedStyle, aka is 'auto' the initial value (the above lines get called in the componentDidRender lifecycle event of a Stencil web component) and the width on computedStyle actually was updated after being shown initially?