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; border-radius: 0.75rem;
&__preview { &__preview {
padding: 1.25rem;
border-top-left-radius: inherit; border-top-left-radius: inherit;
border-top-right-radius: inherit; border-top-right-radius: inherit;
border-bottom-width: 0; border-bottom-width: 0;

View File

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

View File

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

View File

@@ -28,9 +28,20 @@ export default function (Vue, { head }) {
iframeResize({ iframeResize({
...value, ...value,
messageCallback(messageData) { messageCallback(messageData) {
if (messageData.message === 'resize') { if (messageData.message.type !== 'resize') {
el.iFrameResizer.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) }, el)
}) })

View File

@@ -31,9 +31,12 @@ export default {
}, },
mounted() { mounted() {
this.resizeObserver = new window.ResizeObserver(() => { this.resizeObserver = new window.ResizeObserver(items => {
if (window.parentIFrame) { 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 { .demo-page {
// max-width: 40rem; padding: 1.25rem;
// margin: 2rem auto;
} }