1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-04-21 13:51:59 +02:00

iframe example - use an onLoad callback instead of the ref ()

* use an onLoad callback instead of the ref

* expect body to not be null on the iframe test

* remove onLoad prop
This commit is contained in:
Adrian 2022-01-11 00:21:20 +01:00 committed by GitHub
parent 8daa77e9fa
commit e3a325f8a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions
cypress/integration/examples
site/examples

@ -12,6 +12,7 @@ const getIframeBody = () => {
.its('body')
// automatically retries until body is loaded
.should('not.be.undefined')
.should('not.be.null')
.then(cy.wrap)
)
}

@ -105,14 +105,13 @@ const MarkButton = ({ format, icon }) => {
}
const IFrame = ({ children, ...props }) => {
const [contentRef, setContentRef] = useState(null)
const mountNode =
contentRef &&
contentRef.contentWindow &&
contentRef.contentWindow.document.body
const [iframeBody, setIframeBody] = useState(null)
const handleLoad = e => {
setIframeBody(e.target.contentDocument.body)
}
return (
<iframe {...props} ref={setContentRef}>
{mountNode && createPortal(React.Children.only(children), mountNode)}
<iframe srcDoc={`<!DOCTYPE html>`} {...props} onLoad={handleLoad}>
{iframeBody && createPortal(children, iframeBody)}
</iframe>
)
}