Skip to content

Commit 57cf0fa

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

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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)