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 video block attributes: Autoplay, Controls, Loop, Muted #7672

Merged
merged 5 commits into from
Jul 12, 2018

Conversation

Soean
Copy link
Member

@Soean Soean commented Jul 2, 2018

Description

This PR adds 4 additional attributes to the video block.

  • Autoplay
  • Controls
  • Loop
  • Muted

See: https://developer.mozilla.org/de/docs/Web/HTML/Element/video

Types of changes

  • Autoplay and Loop are just added in save not in edit.
  • Autoplay and Loop are already in the Classic Editor, Controls and Muted are new in WordPress.
  • Controls is default true

Related: #7501

Screenshots

bildschirmfoto 2018-07-03 um 09 26 34

@Soean Soean added [Feature] Blocks Overall functionality of blocks [Feature] Media Anything that impacts the experience of managing media labels Jul 2, 2018
@@ -86,8 +101,37 @@ class VideoEdit extends Component {
/>
</Toolbar>
</BlockControls>
<InspectorControls>
<PanelBody title={ __( 'Video Settings' ) }>
Copy link
Member

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"

Copy link
Member Author

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, ...

@danielbachhuber danielbachhuber added the Needs Design Feedback Needs general design feedback. label Jul 2, 2018
@Soean Soean added the [Type] Copy Issues or PRs that need copy editing assistance label Jul 2, 2018
Copy link
Member

@tofumatt tofumatt left a 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 :shipit:

this.toggleAttribute = this.toggleAttribute.bind( this );
}

toggleAttribute( attribute ) {
Copy link
Member

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? 😄

Copy link
Member Author

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

<figure className={ className }>
<video controls src={ src } />
<video
controls={ controls }
Copy link
Member

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 } />

Copy link
Member Author

@Soean Soean Jul 5, 2018

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.

Copy link
Member

@tofumatt tofumatt left a 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 😄

@@ -86,6 +101,30 @@ class VideoEdit extends Component {
/>
</Toolbar>
</BlockControls>
<InspectorControls>
<PanelBody title={ __( 'Playback Controls' ) }>
Copy link
Member

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".

@tofumatt
Copy link
Member

tofumatt commented Jul 5, 2018

I understand autoplay and loop are enabled in the classic editor as you say, but there are usability issues with enabling them in the editing experience, and it's still easy to see them enabled in the sidebar, so I think it's worth changing that UX.

@Soean Soean mentioned this pull request Jul 5, 2018
@Soean
Copy link
Member Author

Soean commented Jul 5, 2018

Thanks for your feedback. I created a HOC issue, I think controls and Muted preview should be fine in the editor.

@gziolo
Copy link
Member

gziolo commented Jul 5, 2018

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.

Copy link
Member

@tofumatt tofumatt left a 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

@gziolo
Copy link
Member

gziolo commented Jul 5, 2018

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.

Copy link
Member

@karmatosed karmatosed left a 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.

@karmatosed karmatosed removed the Needs Design Feedback Needs general design feedback. label Jul 11, 2018
@Soean
Copy link
Member Author

Soean commented Jul 11, 2018

@gziolo @tofumatt
There is no change for old posts with videos, because there was only controls before, which is now default and the three new attributes Loop, Autoplay and Muted are default toggled off.
I tested with an old video bock and there was no problem.

Copy link
Member

@gziolo gziolo left a 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.

@gziolo gziolo added this to the 3.3 milestone Jul 12, 2018
@gziolo gziolo merged commit 72dcdcf into master Jul 12, 2018
@gziolo gziolo deleted the update/video-block-attributes branch July 12, 2018 09:27
@StaggerLeee
Copy link

You are doing it great. It will be something special.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blocks Overall functionality of blocks [Feature] Media Anything that impacts the experience of managing media [Type] Copy Issues or PRs that need copy editing assistance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants