Skip to content

Commit

Permalink
feat: broadcast height to parents - useful when iframed
Browse files Browse the repository at this point in the history
  • Loading branch information
jongomez committed Nov 6, 2023
1 parent 55d4bda commit 298a96d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions packages/lsd-react/.storybook/preview-head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<script>
function sendHeightToParent() {
const height =
document.documentElement.scrollHeight || document.body.scrollHeight
window.parent.postMessage(
{
type: 'iframeResize',
height: height,
},
'*',
)
}

document.addEventListener('DOMContentLoaded', function () {
// Send initial height.
sendHeightToParent()

// Ensure the interval is set only once.
if (!window.heightIntervalSet) {
window.heightIntervalSet = setInterval(sendHeightToParent, 1000)
}
})
</script>

0 comments on commit 298a96d

Please sign in to comment.