Skip to content

Commit 7c29101

Browse files
authored
Trigger resize when a Bootstrap tab is shown (#180)
1 parent 8925380 commit 7c29101

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
* Fixed an issue with plotly graphs sometimes not getting fully removed from the DOM. (#178)
1111
* Fixed an issue with ipyleaflet erroring out when attempting to read the `.model_id` property of a closed widget object. (#179)
12+
* Fixed an issue where altair charts would sometimes render to a 0 height after being shown, hidden, and then shown again. (#180)
1213

1314
## [0.4.2] - 2024-12-18
1415

js/src/output.ts

+12
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,18 @@ $(document).on("shiny:disconnected", () => {
252252
manager.clear_state();
253253
});
254254

255+
// When in filling layout, some widgets (specifically, altair) incorrectly think their
256+
// height is 0 after it's shown, hidden, then shown again. As a workaround, trigger a
257+
// resize event when a tab is shown.
258+
// TODO: This covers the 95% use case, but it's definitely not an ideal way to handle
259+
// this situation. A more robust solution would use IntersectionObserver to detect when
260+
// the widget becomes visible. Or better yet, we'd get altair to handle this situation
261+
// better.
262+
// https://github.com/posit-dev/py-shinywidgets/issues/172
263+
document.addEventListener('shown.bs.tab', event => {
264+
window.dispatchEvent(new Event('resize'));
265+
})
266+
255267
// Our version of https://github.com/jupyter-widgets/widget-cookiecutter/blob/9694718/%7B%7Bcookiecutter.github_project_name%7D%7D/js/lib/extension.js#L8
256268
function setBaseURL(x: string = '') {
257269
const base_url = document.querySelector('body').getAttribute('data-base-url');

0 commit comments

Comments
 (0)