-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 video block attributes: Autoplay, Controls, Loop, Muted #7672
Conversation
core-blocks/video/edit.js
Outdated
@@ -86,8 +101,37 @@ class VideoEdit extends Component { | |||
/> | |||
</Toolbar> | |||
</BlockControls> | |||
<InspectorControls> | |||
<PanelBody title={ __( 'Video Settings' ) }> |
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.
Does it make sense to label this "Playback Controls", to follow #7322?
Generally, I think "Playback Controls" is more specific than, and thus preferable to, "Video Settings"
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.
Thanks for your feedback. I changed it to Playback Controls
. I think it makes sense for this block to have multiple panels, if we add alternate sources, poster, subtitles, ...
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 looks good. I made a note about maybe making a HOC or something for that toggleAttribute
pattern.
The other two notes I left I addressed as I think this is otherwise good to go and they were minor changes. If you're okay with them then
this.toggleAttribute = this.toggleAttribute.bind( this ); | ||
} | ||
|
||
toggleAttribute( attribute ) { |
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.
Seems like this would make a handy higher-order-component components could use as a sort of mixin, given it's the second place we've used this pattern (after Audio
).
If you could either create a HOC for this and Audio
(and probably other) components to use that'd be neat… or if that's too much of a pain could you at least file an issue with the "code quality" label for it and link to this comment? 😄
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.
Thanks for your comment. I am not a React expert (yet). So I created an issue for this: #7717
core-blocks/video/edit.js
Outdated
<figure className={ className }> | ||
<video controls src={ src } /> | ||
<video | ||
controls={ controls } |
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.
In edit mode, these attributes shouldn't be linked to the output. Check out the Audio
edit for inspiration: https://github.com/WordPress/gutenberg/blob/master/core-blocks/audio/edit.js#L119
For instance: if you enable loop
for the video and then click "play" in the editor the video will play constantly until you click it again. That's an annoying behaviour.
The InspectorControls
tell you what settings are enabled, this is a good example of "what you see [should not be/is not] what you get" 😄
I think this should just stay as <video controls src={ src } />
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.
We can remove Loop
, Controls and Muted should be okay.
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.
Just so you know I think the controls should be changed here, so I'll push a fix and if you agree, again: 🚢
If not please tell me why I'm wrong 😄
core-blocks/video/edit.js
Outdated
@@ -86,6 +101,30 @@ class VideoEdit extends Component { | |||
/> | |||
</Toolbar> | |||
</BlockControls> | |||
<InspectorControls> | |||
<PanelBody title={ __( 'Playback Controls' ) }> |
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.
I know this was already changed, but I actually think "Playback controls" for audio is maybe something I should have caught before and isn't the right fit.
Calling this "playback controls" when "autoplay" and "loop" aren't "controls" per-se is weird, and it also is redundant as you have "Playback Controls > Controls".
Realistically this should just be "Video Options" and the option underneath labelled "Controls" should arguably be "Playback Controls".
I understand |
Thanks for your feedback. I created a HOC issue, I think |
Have you tested it with old posts? |
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.
Have you tested it with old posts? save method produces different output, I bet it might cause all existing Video blocks to be recognized as externally modified by blocks validator.
Shoot, you're right. This will need a deprecated save method, my bad. 😓
@Soean You'll need to accommodate for the markup change in how video blocks are saved now. You can read the doc here: https://github.com/WordPress/gutenberg/blob/master/docs/block-api/block-edit-save.md
By the way, we finally need to write e2e test which ensures that Demo post renders properly - in general there are no dialogs informing that it has changed externally. Filed in #7719. |
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.
I am going to approve as right now using 4 switches is the right pattern. However I think we've reached the point of too many and maybe want to consider other approaches with this many options. That would be done in another issue.
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.
I tested it with the Video block created in master and I can confirm that it works as expected. It looks like you can add new attributes as long as they aren't included in HTML markup by default.
You are doing it great. It will be something special. |
Description
This PR adds 4 additional attributes to the video block.
See: https://developer.mozilla.org/de/docs/Web/HTML/Element/video
Types of changes
Autoplay
andLoop
are just added insave
not inedit
.Autoplay
andLoop
are already in the Classic Editor,Controls
andMuted
are new in WordPress.Controls
is defaulttrue
Related: #7501
Screenshots