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

Add muted message via direct DOM manipulation #6573

Conversation

delawski
Copy link
Collaborator

@delawski delawski commented Aug 27, 2021

Summary

This is a rather rough alternative to the approach proposed in #6547. Here we're manipulating the DOM imperatively inside the useLayoutEffect hook in order to inject the message in the correct place.

Screenshot 2021-08-27 at 14 43 54

This should be tested quite throughly.

Checklist

  • My code is tested and passes existing tests.
  • My code follows the Engineering Guidelines (updates are often made to the guidelines, check it out periodically).

@github-actions
Copy link
Contributor

github-actions bot commented Aug 27, 2021

Plugin builds for 3755725 are ready 🛎️!

* @return {ReactElement} Inspector Controls.
*/
export const setUpVideoInspectorControls = ( props ) => {
const { isSelected, attributes: { autoplay, muted } } = props;
export const VideoInspectorControls = ( props ) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This works perfectly but my only concern is how fragile this would be going forward whenever the video block is to be updated in the future. @delawski could you add an E2E test to verify that the message is shown under the muted toggle? That way we can catch whenever something goes awry with the DOM mutation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is a very good idea! I'll take set up an E2E test for that 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

An E2E test has been added in 3755725.


message.current = document.createElement( 'p' );
message.current.classList.add( 'amp-video-autoplay-notice' );
message.current.textContent = __( 'Autoplay will mute the video player by default in AMP mode.', 'amp' );
Copy link
Member

@westonruter westonruter Aug 27, 2021

Choose a reason for hiding this comment

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

Suggested change
message.current.textContent = __( 'Autoplay will mute the video player by default in AMP mode.', 'amp' );
message.current.textContent = __( 'Autoplay will cause the video to be muted in many browsers to prevent a poor user experience. It will be muted in AMP for this reason as well.', 'amp' );

See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video#:~:text=In%20some%20browsers%20(e.g.%20Chrome%2070.0)%20autoplay%20doesn%27t%20work%20if%20no%20muted%20attribute%20is%20present.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Addressed in 9c80afd

@westonruter
Copy link
Member

This appears to be working quite well:

muted-notice.mov

* we traverse through the DOM tree to finally find out the
* "Muted" toggle container.
*/
const blockInspector = [ ...document.querySelectorAll( '.edit-post-sidebar .block-editor-block-card__description' ) ]
Copy link
Member

@westonruter westonruter Aug 27, 2021

Choose a reason for hiding this comment

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

QUESTION: why no jQuery?

😉

Copy link
Contributor

@pierlon pierlon Aug 27, 2021

Choose a reason for hiding this comment

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

Why use jQuery when few vanilla JS do trick? 😉

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was really hard to resist the temptation 😅

@westonruter westonruter added this to the v2.1.4 milestone Aug 30, 2021
@delawski
Copy link
Collaborator Author

I'm merging this one into the previous feature branch so that this can be reviewed as a whole.

@delawski delawski merged commit 602eb7e into bug/4635-disable-mute-when-autoplay Aug 30, 2021
@delawski delawski deleted the bug/4635-disable-mute-when-autoplay-2 branch August 30, 2021 15:18
@westonruter westonruter modified the milestones: v2.1.4, v2.2 Aug 30, 2021
@westonruter westonruter modified the milestones: v2.2, v2.3 Dec 15, 2021
@westonruter westonruter modified the milestones: v2.3, v2.4 Dec 23, 2021
@westonruter westonruter removed this from the v2.4 milestone Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants