diff --git a/packages/components/CHANGELOG.md b/packages/components/CHANGELOG.md
index 869b3cf2e41f4f..9ae15cb596843b 100644
--- a/packages/components/CHANGELOG.md
+++ b/packages/components/CHANGELOG.md
@@ -19,6 +19,7 @@
- `GradientPicker`: Add `selectedSlug` prop for slug-based selection and pass the selected preset's slug to `onChange`, so two presets sharing a gradient keep their identity ([#80554](https://github.com/WordPress/gutenberg/pull/80554)).
- `SandBox`: Add `allowPopups` prop to opt into `allow-popups` in the iframe's sandbox attribute ([#69617](https://github.com/WordPress/gutenberg/pull/69617)).
+- `SandBox`: Add `allowForms` prop to opt into `allow-forms` in the iframe's sandbox attribute ([#76471](https://github.com/WordPress/gutenberg/pull/76471)).
- Validated form controls: Only move focus to the invalid control for trusted `invalid` events (form submission, `reportValidity()`). Consumers can now dispatch a synthetic `invalid` event to reveal a control's error message without disturbing the user's place in the form ([#80685](https://github.com/WordPress/gutenberg/pull/80685)).
### Bug Fixes
diff --git a/packages/components/src/sandbox/index.tsx b/packages/components/src/sandbox/index.tsx
index ece32df2ec80b4..1de1e5c8b4f7cf 100644
--- a/packages/components/src/sandbox/index.tsx
+++ b/packages/components/src/sandbox/index.tsx
@@ -268,6 +268,7 @@ function IsolatedSandBox( {
onFocus,
tabIndex,
allowPopups = false,
+ allowForms = false,
}: SandBoxContentProps ) {
const ref = useRef< HTMLIFrameElement >( null );
const [ width, setWidth ] = useState( 0 );
@@ -275,6 +276,7 @@ function IsolatedSandBox( {
const sandbox = clsx( 'allow-scripts', 'allow-presentation', {
'allow-popups': allowPopups,
+ 'allow-forms': allowForms,
} );
const srcDoc = useMemo(
@@ -393,6 +395,7 @@ function SameOriginSandBox( {
onFocus,
tabIndex,
allowPopups = false,
+ allowForms = false,
}: SandBoxContentProps ) {
const ref = useRef< HTMLIFrameElement >( null );
const [ width, setWidth ] = useState( 0 );
@@ -404,6 +407,7 @@ function SameOriginSandBox( {
'allow-presentation',
{
'allow-popups': allowPopups,
+ 'allow-forms': allowForms,
}
);
diff --git a/packages/components/src/sandbox/stories/index.story.tsx b/packages/components/src/sandbox/stories/index.story.tsx
index 77ff4cbfa83b21..9617436b0f7ee6 100644
--- a/packages/components/src/sandbox/stories/index.story.tsx
+++ b/packages/components/src/sandbox/stories/index.story.tsx
@@ -36,4 +36,11 @@ const Template: StoryFn< typeof SandBox > = ( args ) =>
Arbitrary HTML content
', + allowForms: false, +}; + +export const WithForm = Template.bind( {} ); +WithForm.args = { + html: '', + allowForms: true, }; diff --git a/packages/components/src/sandbox/test/index.tsx b/packages/components/src/sandbox/test/index.tsx index 0c216a820c04a6..c103ca14d7b0e4 100644 --- a/packages/components/src/sandbox/test/index.tsx +++ b/packages/components/src/sandbox/test/index.tsx @@ -70,6 +70,27 @@ describe( 'SandBox', () => { ); } ); + it( 'should not include allow-forms by default', () => { + render(