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

Support 'preload' attribute for Audio Block #7590

Merged
merged 5 commits into from
Jul 11, 2018
Merged

Conversation

danielbachhuber
Copy link
Member

Description

Adds UI for managing preload attribute of the Audio Block:

image

This is for feature parity with the [audio] shortcode:

image

The default value is 'None'. Selecting 'Auto' or 'Metadata' will add preload="auto" or preload="meta" to the <audio> element, respectively.

Fixes #6581
Previously #7322

How has this been tested?

  1. Add an Audio Block to the editor. View that it has no preload attribute set by default:

image

image

  1. Switch back to Visual mode, select "Auto", and then view that preload='auto' is set:

image

image

  1. Save the post and verify the <audio> element includes preload="auto":

image

Types of changes

Enhancement to existing feature.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.

@danielbachhuber danielbachhuber added [Feature] Blocks Overall functionality of blocks Backwards Compatibility Issues or PRs that impact backwards compatability labels Jun 27, 2018
@danielbachhuber danielbachhuber added this to the 3.2 milestone Jun 27, 2018
@danielbachhuber danielbachhuber requested a review from a team June 27, 2018 20:11
@danielbachhuber danielbachhuber added the Needs Design Feedback Needs general design feedback. label Jun 27, 2018
{
name: __( 'None' ),
key: 'none',
attributeValue: undefined,
Copy link
Member Author

Choose a reason for hiding this comment

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

attributeValue: undefined,

Worth noting I was stuck on this for a little bit. Originally, I tried attributeValue: false but ended up with preload="false" in the saved <audio> attribute.

Copy link
Member

Choose a reason for hiding this comment

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

If null works I might think that is ever-so-slightly more semantically correct? If it worked I think it might be nicer, but yeah this is fine 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

null didn't work in my original testing.

@danielbachhuber
Copy link
Member Author

Flagged Needs Design Feedback to get approval on this UI:

image

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 think we need to think about the actual UI here. I'll add a note to make a mockup here but let's not merge this as currently we don't use this tab/button combination anywhere and ideally we'd not be adding it. I know WP core does but it's not super effective as a pattern.

One thought though before mocking up, why not a drop down? Can you select more than one or just one? Also what do these settings mean to everyone? I ask as exposing them in the UI like this for the block seems like it needs an explanation.

@danielbachhuber danielbachhuber modified the milestones: 3.2, 3.3 Jul 4, 2018
@danielbachhuber
Copy link
Member Author

I'll add a note to make a mockup here but let's not merge this as currently we don't use this tab/button combination anywhere and ideally we'd not be adding it.

Ok, I've moved to the 3.3 milestone.

One thought though before mocking up, why not a drop down? Can you select more than one or just one?

Personally, I prefer the current UI because I can see all potential options. You can only select one option. It's similar to the existing Text Settings UI:

image

I ask as exposing them in the UI like this for the block seems like it needs an explanation.

It's for feature-parity with the Classic Editor.

@karmatosed
Copy link
Member

Let's leave it in with tab button UI but also let's add a description as it's kind of not as intuitive what this means compared to text settings.

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

Thinking about this a bit more let's combine to one group, no sections and stay with drop down it does make far more sense here.

2018-07-05 at 12 00

Also let's have a description if that makes sense or a smaller one can be thought of.

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.

I have a thought about how to label these without needing more description text. I think the issue is we're just being too close to HTML attribute with these labels.

<ButtonGroup aria-label={ __( 'Preload' ) }>
{ map( [
{
name: __( 'Auto' ),
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 "auto" is the HTML value for this, but we don't have to follow the HTML attributes to a T.

I think a more instructive/helpful label here would be "Content" (as that's what you're instructing the browser to preload) or, if you want more text: "Preload Content". If you really want the HTML value in brackets you could do "Content (Auto)" but I think "Content would suffice and then nix the need for a description beneath.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not particularly keen to bikeshed the labels at this point.

If you'd like to take the changes through the copy review process, then please do.

Copy link
Member

Choose a reason for hiding this comment

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

I've filed #7726 because it's this way in the classic editor, but I didn't mean to bike shed. I think this existing control text is unclear and this is an easy win.

attributeValue: 'auto',
},
{
name: __( 'Metadata' ),
Copy link
Member

Choose a reason for hiding this comment

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

"Metadata only" might be a better label especially if my other suggestion was implemented.

return (
<figure>
<audio controls="controls" src={ src } autoPlay={ autoplay } loop={ loop } />
<audio controls="controls" src={ src } autoPlay={ autoplay } loop={ loop } preload={ preload } />
Copy link
Member

@tofumatt tofumatt Jul 5, 2018

Choose a reason for hiding this comment

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

This will need a deprecated save function, right? (https://github.com/WordPress/gutenberg/blob/master/docs/block-api/deprecated-blocks.md)

Or will this load fine because it's just adding the binary attributes?

Copy link
Member Author

Choose a reason for hiding this comment

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

The latter, to my knowledge. The markup doesn't change structure; this is only a progressive enhancement.

Copy link
Member

Choose a reason for hiding this comment

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

Oh right, cool. 👍 (Sorry I'm still a bit new to block validation!)

@danielbachhuber
Copy link
Member Author

Thinking about this a bit more let's combine to one group, no sections and stay with drop down it does make far more sense here.

@karmatosed My <SelectControl> ends up looking like this:

image

How do I make it look like yours?

@@ -105,6 +105,7 @@ class AudioEdit extends Component {
<SelectControl
label={ __( 'Preload' ) }
value={ undefined !== preload ? preload : 'none' }
// `undefined` is required for the preload attribute to be unset.
Copy link
Member

Choose a reason for hiding this comment

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

Cheers! 👍

@karmatosed
Copy link
Member

@danielbachhuber no worries, let's see what we can do. How about we start with having it not 'in' the description. You seem to be missing the separator?

@karmatosed
Copy link
Member

One point to consider would be is this 'advanced' if that's case we could put in with the CSS input class. What do you think?

@danielbachhuber
Copy link
Member Author

How about we start with having it not 'in' the description. You seem to be missing the separator?

How do I add a separator?

@danielbachhuber
Copy link
Member Author

@karmatosed @tofumatt Could I get clear and specific feedback on how you'd like me to finish this pull request?

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.

Tested locally, including going from a post with existing audio to this one and it all worked for me.

The code makes sense. The removal of PanelBody makes sense to me but it means the "Preload" label is really tight against the Audio block description:

screenshot 2018-07-05 15 18 06

It might make sense to bring it back. Compare it to:

screenshot 2018-07-05 15 22 57

Which I think is nicer. I think that's what @karmatosed is talking about here.


I'd be fine putting "preload" in advanced controls, frankly. Let's just do that–it's not a playback control so restoring the "Playback controls" to how they were before and moving "Preload" under Advanced makes sense to me.

label={ __( 'Preload' ) }
value={ undefined !== preload ? preload : 'none' }
// `undefined` is required for the preload attribute to be unset.
onChange={ ( value ) => setAttributes( { preload: 'none' !== value ? value : undefined } ) }
Copy link
Member

Choose a reason for hiding this comment

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

For readability, could you enclose the value here in parens?

This reads, at a glance, like { preload: 'none' } because the constant is first in the conditional check and I think that reduces readability. preload: ( 'none' !== value ? value : undefined ) seems a clear way to indicate this isn't { preload: 'none' }.

@tofumatt
Copy link
Member

tofumatt commented Jul 5, 2018

(Sorry, I posted the same screenshot twice if you saw this via email. Updated the review body to show the different ones. I blame Finder for my sort being weird 😉)

@danielbachhuber
Copy link
Member Author

t might make sense to bring it back. Compare it to:

Which I think is nicer. I think that's what @karmatosed is talking about here.

@karmatosed Are you 👍 on @tofumatt's proposed implementation?

@danielbachhuber danielbachhuber added the Needs Design Feedback Needs general design feedback. label Jul 5, 2018
@karmatosed
Copy link
Member

karmatosed commented Jul 10, 2018

All blocks should really have that header block as @tofumatt points out. I also think we can change the order around a bit. What about this?

artboard

As to if this is an advanced setting or not.. I am unsure still (happy to be swayed). Let's have what I suggest as a middle ground and iterate from there once the PR is in.

@danielbachhuber
Copy link
Member Author

I also think we can change the order around a bit. What about this?

Works for me. The block now looks like this with eed2f1b:

image

@danielbachhuber danielbachhuber requested a review from a team July 11, 2018 11:21
@danielbachhuber danielbachhuber removed the Needs Design Feedback Needs general design feedback. label Jul 11, 2018
@tofumatt tofumatt dismissed karmatosed’s stale review July 11, 2018 16:52

UI is now implemented as requested :-)

@tofumatt
Copy link
Member

I made a little tweak (d1f7062) because I found the constant-first ternary check was tough to follow. I think we should eschew constant-first styles especially as we're inconsistent about them, but that's not for this issue 😆

If you're okay with that, then 🚢, looks great!

@danielbachhuber danielbachhuber merged commit 4f5af69 into master Jul 11, 2018
@danielbachhuber danielbachhuber deleted the 6581-preload-audio branch July 11, 2018 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backwards Compatibility Issues or PRs that impact backwards compatability [Feature] Blocks Overall functionality of blocks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants