Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video Block: Disable autoplay when video is not muted #69232

Merged
merged 5 commits into from
Feb 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading