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

Widget does not initialize with correct width #6

Open
SIRHAMY opened this issue Oct 16, 2022 · 4 comments
Open

Widget does not initialize with correct width #6

SIRHAMY opened this issue Oct 16, 2022 · 4 comments

Comments

@SIRHAMY
Copy link

SIRHAMY commented Oct 16, 2022

Overview

I'm embedding the widget in my Svelte site. The widget seems to initially be the correct size then it re-renders to the incorrect size (thinks it's fullscreen but not).

It will then re-size to the correct size if I manually resize my screen but otherwise is incorrect.

What I expect to happen

  • Widget should be able to inherit the correct width from whatever div it gets loaded into

What actually happens

  • Widget seems to load in with incorrect size -> I can track this down to size="hide"
  • If I resize the screen then it will change itself to size="sm" which seems to fix the problem

Repro

How to repro:

You can also repro in svelte repl:

Code:

<div style="width: 440px">
	<script src="https://climateclock.world/widget-v2.js" async></script>
		<climate-clock />
</div>

image

@SIRHAMY
Copy link
Author

SIRHAMY commented Oct 16, 2022

To be fair, it does seem like the widget loads with the correct width in normal HTML so this may actually be a Svelte / SvelteKit issue with iframe sizing / setting the correct params.

Working code in codepen:

<div style="width: 440px">
	<script src="https://climateclock.world/widget-v2.js" async></script>
		<climate-clock />
</div>

image

@raeabileah
Copy link

raeabileah commented Oct 17, 2022 via email

@shwaydogg
Copy link
Collaborator

@SIRHAMY If you want a quick CSS fix you could apply the following CCS to make it wider. Without looking deeper i think the JS is checking the width of the full view port and using that decide the display settings rather than the size of the element. We will be deprecating this version of the widget in the near future, let me know if you'd be interested in working on the next iteration with more features! If so you can jump on our slack here and message me: https://join.slack.com/t/climate-clock/shared_invite/zt-1ieksunf4-1UI2PAwN78JLlNgaMN7Rug

position: fixed;
    width: 70%;
    left: 15%;

@adrian-the-git
Copy link
Collaborator

For any who stumble into this, the viewport size is only referenced to determine whether the window was resized, because we couldn't yet use ResizeObserver. The widget is supposed to size itself to its container, and if it doesn't, that's a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants