Skip to content

Commit f6eaa9b

Browse files
committed
fix: enhance ZeroStylesRichText component to auto-resize iframe
1 parent 6ea51fb commit f6eaa9b

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

adminforth/spa/src/renderers/ZeroStylesRichText.vue

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
</template>
44

55
<script setup lang="ts">
6-
import { onMounted, ref, watch } from 'vue'
6+
import { nextTick, onMounted, ref, watch } from 'vue'
77
import type { AdminForthResourceColumnCommon, AdminForthResourceCommon, AdminUser } from '@/types/Common'
88
import { protectAgainstXSS } from '@/utils'
99
@@ -17,7 +17,7 @@
1717
1818
const iframeRef = ref<HTMLIFrameElement | null>(null)
1919
20-
const renderHtml = () => {
20+
const renderHtml = async () => {
2121
const iframe = iframeRef.value
2222
if (!iframe) return
2323
@@ -26,11 +26,23 @@
2626
2727
iframe.style.border = "none"
2828
iframe.style.width = "100%"
29-
iframe.style.height = "400px"
3029
3130
doc.open()
3231
doc.write(protectAgainstXSS(props.record[props.column.name]) || '')
3332
doc.close()
33+
34+
await nextTick()
35+
36+
iframe.onload = () => {
37+
try {
38+
const iframeBody = iframe.contentWindow?.document.body
39+
if (iframeBody) {
40+
iframe.style.height = iframeBody.scrollHeight + 'px'
41+
}
42+
} catch (e) {
43+
console.warn("Can't auto-resize iframe:", e)
44+
}
45+
}
3446
}
3547
3648

0 commit comments

Comments
 (0)