Skip to content

Commit cca7615

Browse files
Rishit30GRishit30GMamadukahanneslsmyogeshbhutkar
authored
Video Block: Disable autoplay when video is not muted (#69232)
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]>
1 parent c3151e8 commit cca7615

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

packages/block-library/src/video/edit-common-settings.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const VideoSettings = ( { setAttributes, attributes } ) => {
2222
const autoPlayHelpText = __(
2323
'Autoplay may cause usability issues for some users.'
2424
);
25+
2526
const getAutoplayHelp = Platform.select( {
2627
web: useCallback( ( checked ) => {
2728
return checked ? autoPlayHelpText : null;
@@ -32,7 +33,11 @@ const VideoSettings = ( { setAttributes, attributes } ) => {
3233
const toggleFactory = useMemo( () => {
3334
const toggleAttribute = ( attribute ) => {
3435
return ( newValue ) => {
35-
setAttributes( { [ attribute ]: newValue } );
36+
setAttributes( {
37+
[ attribute ]: newValue,
38+
// Set muted when autoplay changes
39+
...( attribute === 'autoplay' && { muted: newValue } ),
40+
} );
3641
};
3742
};
3843

@@ -56,7 +61,7 @@ const VideoSettings = ( { setAttributes, attributes } ) => {
5661
isShownByDefault
5762
hasValue={ () => !! autoplay }
5863
onDeselect={ () => {
59-
setAttributes( { autoplay: false } );
64+
setAttributes( { autoplay: false, muted: false } );
6065
} }
6166
>
6267
<ToggleControl
@@ -95,6 +100,10 @@ const VideoSettings = ( { setAttributes, attributes } ) => {
95100
label={ __( 'Muted' ) }
96101
onChange={ toggleFactory.muted }
97102
checked={ !! muted }
103+
disabled={ autoplay }
104+
help={
105+
autoplay ? __( 'Muted because of Autoplay.' ) : null
106+
}
98107
/>
99108
</ToolsPanelItem>
100109
<ToolsPanelItem

0 commit comments

Comments
 (0)