Skip to content

Commit

Permalink
Call Streamlit.setFrameHeight to set frame height correctly (#237)
Browse files Browse the repository at this point in the history
* Call Streamlit.setFrameHeight to set frame height correctly

* Add test
  • Loading branch information
raethlein authored Nov 14, 2024
1 parent 0997559 commit 82812fc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions streamlit_folium/frontend/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ async function onRender(event: Event) {
})
}
finalizeOnRender()
Streamlit.setFrameHeight()
}

// Attach our `onRender` handler to Streamlit's render event.
Expand Down
24 changes: 24 additions & 0 deletions tests/test_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,3 +391,27 @@ def test_layer_control_dynamic_update(page: Page):
.get_by_role("img")
.locator("path")
).to_be_visible()


def test_frame_height_matches_content_height(page: Page):
"""Make sure that the frame height matches the document height to confirm that
Streamlit.setFrameHeight was called correctly."""

iframe = page.get_by_test_id("stCustomComponentV1")
iframe_html = page.frame_locator("[data-testid=stCustomComponentV1]").locator(
"html"
)

# Wait for the iframe to load and have a height - otherwise the test will be flaky
page.wait_for_function(
"el => window.getComputedStyle(el).height !== '0px'",
arg=iframe.element_handle(),
)

# Now make sure that the heights match
iframe_height = iframe.evaluate("el => window.getComputedStyle(el).height")
iframe_html_height = iframe_html.evaluate(
"el => window.getComputedStyle(el).height"
)

assert iframe_height == iframe_html_height

Check failure on line 417 in tests/test_frontend.py

View workflow job for this annotation

GitHub Actions / build (3.12)

test_frame_height_matches_content_height[chromium] AssertionError: assert '724px' == '720px' - 720px ? ^ + 724px ? ^

0 comments on commit 82812fc

Please sign in to comment.