SandBox

This component provides an isolated environment for arbitrary HTML via iframes.

View on Storybook

View source on GitHub

Import

import { SandBox } from '@wordpress/components';

Props

NameTypeDefaultRequiredDescription
allowSameOriginbooleanfalse

Whether to include allow-same-origin in the iframe’s sandbox attribute. When true, nested iframes (such as third-party embeds) can access their own origin’s cookies and storage.

Only enable this for content that is NOT directly user-controlled, such as server-fetched oEmbed previews.

@default false

htmlstring

The HTML to render in the body of the iframe document.

@default ”

titlestring

The <title> of the iframe document.

@default ”

typestring

The CSS class name to apply to the <html> and <body> elements of the iframe.

stylesstring[]

An array of CSS strings to inject into the <head> of the iframe document.

@default []

scriptsstring[]

An array of script URLs to inject as <script> tags into the bottom of the <body> of the iframe document.

@default []

onFocusReact.DOMAttributes< HTMLIFrameElement >[ 'onFocus' ]

The onFocus callback for the iframe.

tabIndexHTMLElement[ 'tabIndex' ]

The tabindex the iframe should receive.

@default 0

Examples

Default

const Default = () => <SandBox onFocus={fn()} html="<p>Arbitrary HTML content</p>" />;