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 7, 2023
1 parent 55d4bda commit 31c2c9e
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 31c2c9e

Please sign in to comment.