From 429b34a268fdc8b2d1278b22bee6ad9b0f94ed06 Mon Sep 17 00:00:00 2001 From: Rishit Gupta Date: Sun, 23 Feb 2025 13:30:13 +0530 Subject: [PATCH] Video Block: Disable autoplay when video is not muted (#69232) Co-authored-by: Rishit30G Co-authored-by: Mamaduka Co-authored-by: hanneslsm Co-authored-by: yogeshbhutkar Co-authored-by: Infinite-Null Co-authored-by: carolinan --- .../block-library/src/video/edit-common-settings.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/block-library/src/video/edit-common-settings.js b/packages/block-library/src/video/edit-common-settings.js index 96d59d7e2f7269..312586259efe14 100644 --- a/packages/block-library/src/video/edit-common-settings.js +++ b/packages/block-library/src/video/edit-common-settings.js @@ -22,6 +22,7 @@ const VideoSettings = ( { setAttributes, attributes } ) => { const autoPlayHelpText = __( 'Autoplay may cause usability issues for some users.' ); + const getAutoplayHelp = Platform.select( { web: useCallback( ( checked ) => { return checked ? autoPlayHelpText : null; @@ -32,7 +33,11 @@ const VideoSettings = ( { setAttributes, attributes } ) => { const toggleFactory = useMemo( () => { const toggleAttribute = ( attribute ) => { return ( newValue ) => { - setAttributes( { [ attribute ]: newValue } ); + setAttributes( { + [ attribute ]: newValue, + // Set muted when autoplay changes + ...( attribute === 'autoplay' && { muted: newValue } ), + } ); }; }; @@ -56,7 +61,7 @@ const VideoSettings = ( { setAttributes, attributes } ) => { isShownByDefault hasValue={ () => !! autoplay } onDeselect={ () => { - setAttributes( { autoplay: false } ); + setAttributes( { autoplay: false, muted: false } ); } } > { label={ __( 'Muted' ) } onChange={ toggleFactory.muted } checked={ !! muted } + disabled={ autoplay } + help={ + autoplay ? __( 'Muted because of Autoplay.' ) : null + } />