improve iframe maxheight scrolling

This commit is contained in:
Philipp Kühn 2021-02-02 22:20:16 +01:00 committed by Hans Pagel
parent f27ead9b06
commit c3e1f4d6ee
6 changed files with 21 additions and 9 deletions

View File

@ -3,7 +3,6 @@
border-radius: 0.75rem;
&__preview {
padding: 1.25rem;
border-top-left-radius: inherit;
border-top-right-radius: inherit;
border-bottom-width: 0;

View File

@ -5,7 +5,7 @@
</div>
<iframe
class="demo-frame__iframe"
v-resize.quiet="{ scrolling: true }"
v-resize.quiet="{ scrolling: 'omit' }"
:src="`/demos/${name}?${query}`"
width="100%"
height="0"
@ -79,6 +79,7 @@ export default {
&.is-inline {
border-radius: 0.75rem;
background-color: rgba($colorBlack, 0.03);
margin: -1.25rem;
}
&__loader-wrapper {

View File

@ -145,7 +145,6 @@ export default {
background-color: white;
border: 1px solid rgba(black, 0.1);
border-radius: 0.5rem;
margin-bottom: 1rem;
&__menu {
display: flex;

View File

@ -28,9 +28,20 @@ export default function (Vue, { head }) {
iframeResize({
...value,
messageCallback(messageData) {
if (messageData.message === 'resize') {
el.iFrameResizer.resize()
if (messageData.message.type !== 'resize') {
return
}
const style = window.getComputedStyle(el.parentElement)
const maxHeight = parseInt(style.getPropertyValue('max-height'), 10)
if (messageData.message.height > maxHeight) {
el.setAttribute('scrolling', 'auto')
} else {
el.setAttribute('scrolling', 'no')
}
el.iFrameResizer.resize()
},
}, el)
})

View File

@ -31,9 +31,12 @@ export default {
},
mounted() {
this.resizeObserver = new window.ResizeObserver(() => {
this.resizeObserver = new window.ResizeObserver(items => {
if (window.parentIFrame) {
window.parentIFrame.sendMessage('resize')
window.parentIFrame.sendMessage({
type: 'resize',
height: items[0].contentRect.height,
})
}
})

View File

@ -1,4 +1,3 @@
.demo-page {
// max-width: 40rem;
// margin: 2rem auto;
padding: 1.25rem;
}