Skip to content

Commit 42fa3ec

Browse files
committed
Close #172: Trigger resize when a Bootstrap tab is shown
1 parent 8925380 commit 42fa3ec

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

js/src/output.ts

+11
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,17 @@ $(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. TODO: This covers the 95% use case, but it's
258+
// definitely not an ideal way to handle this situation. A more robust solution would
259+
// use IntersectionObserver to detect when the widget becomes visible. Or better yet,
260+
// we'd get altair to handle this situation better.
261+
// https://github.com/posit-dev/py-shinywidgets/issues/172
262+
document.addEventListener('shown.bs.tab', event => {
263+
window.dispatchEvent(new Event('resize'));
264+
})
265+
255266
// Our version of https://github.com/jupyter-widgets/widget-cookiecutter/blob/9694718/%7B%7Bcookiecutter.github_project_name%7D%7D/js/lib/extension.js#L8
256267
function setBaseURL(x: string = '') {
257268
const base_url = document.querySelector('body').getAttribute('data-base-url');

0 commit comments

Comments
 (0)