Skip to content

Commit

Permalink
Video Block: Disable autoplay when video is not muted (#69232)
Browse files Browse the repository at this point in the history
Co-authored-by: Rishit30G <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: hanneslsm <[email protected]>
Co-authored-by: yogeshbhutkar <[email protected]>
Co-authored-by: Infinite-Null <[email protected]>
Co-authored-by: carolinan <[email protected]>
  • Loading branch information
7 people authored Feb 23, 2025
1 parent c3151e8 commit cca7615
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/block-library/src/video/edit-common-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 } ),
} );
};
};

Expand All @@ -56,7 +61,7 @@ const VideoSettings = ( { setAttributes, attributes } ) => {
isShownByDefault
hasValue={ () => !! autoplay }
onDeselect={ () => {
setAttributes( { autoplay: false } );
setAttributes( { autoplay: false, muted: false } );
} }
>
<ToggleControl
Expand Down Expand Up @@ -95,6 +100,10 @@ const VideoSettings = ( { setAttributes, attributes } ) => {
label={ __( 'Muted' ) }
onChange={ toggleFactory.muted }
checked={ !! muted }
disabled={ autoplay }
help={
autoplay ? __( 'Muted because of Autoplay.' ) : null
}
/>
</ToolsPanelItem>
<ToolsPanelItem
Expand Down

1 comment on commit cca7615

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in cca7615.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/13481062785
📝 Reported issues:

Please sign in to comment.