mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-16 04:04:06 +02:00
iframe example - use an onLoad callback instead of the ref (#4758)
* 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:
@@ -12,6 +12,7 @@ const getIframeBody = () => {
|
|||||||
.its('body')
|
.its('body')
|
||||||
// automatically retries until body is loaded
|
// automatically retries until body is loaded
|
||||||
.should('not.be.undefined')
|
.should('not.be.undefined')
|
||||||
|
.should('not.be.null')
|
||||||
.then(cy.wrap)
|
.then(cy.wrap)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@@ -105,14 +105,13 @@ const MarkButton = ({ format, icon }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const IFrame = ({ children, ...props }) => {
|
const IFrame = ({ children, ...props }) => {
|
||||||
const [contentRef, setContentRef] = useState(null)
|
const [iframeBody, setIframeBody] = useState(null)
|
||||||
const mountNode =
|
const handleLoad = e => {
|
||||||
contentRef &&
|
setIframeBody(e.target.contentDocument.body)
|
||||||
contentRef.contentWindow &&
|
}
|
||||||
contentRef.contentWindow.document.body
|
|
||||||
return (
|
return (
|
||||||
<iframe {...props} ref={setContentRef}>
|
<iframe srcDoc={`<!DOCTYPE html>`} {...props} onLoad={handleLoad}>
|
||||||
{mountNode && createPortal(React.Children.only(children), mountNode)}
|
{iframeBody && createPortal(children, iframeBody)}
|
||||||
</iframe>
|
</iframe>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user