-
Notifications
You must be signed in to change notification settings - Fork 384
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
Add muted message via direct DOM manipulation #6573
Conversation
Plugin builds for 3755725 are ready 🛎️!
|
* @return {ReactElement} Inspector Controls. | ||
*/ | ||
export const setUpVideoInspectorControls = ( props ) => { | ||
const { isSelected, attributes: { autoplay, muted } } = props; | ||
export const VideoInspectorControls = ( props ) => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 👍
There was a problem hiding this comment.
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' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 9c80afd
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' ) ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QUESTION: why no jQuery?
😉
There was a problem hiding this comment.
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? 😉
There was a problem hiding this comment.
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 😅
I'm merging this one into the previous feature branch so that this can be reviewed as a whole. |
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.This should be tested quite throughly.
Checklist