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

Block library: Add text align support to List block #16792

Closed
wants to merge 4 commits into from

Conversation

gziolo
Copy link
Member

@gziolo gziolo commented Jul 29, 2019

Description

Partially implements #15096.

This PR adds text alignment support to the List block:

Screenshot 2019-04-22 at 08 05 00

There is a different order on the screen above but it should be tackled seperately as it's baked in the RichText implementation.

How has this been tested?

Add List block, set one of the existing text alignments and ensure that text alignment changes. In addition, inspect HTML output in the Code editor and ensure it looks like the following:

<!-- wp:list {"textAlign":"right"} -->
<ul class="has-text-align-right"><li>Welcome to WordPress.</li><li>This is your first post.</li><li>Edit or delete it, then start writing!</li></ul>
<!-- /wp:list -->

Screenshots

Screen Shot 2019-07-29 at 15 46 15
Screen Shot 2019-07-29 at 15 46 20
Screen Shot 2019-07-29 at 15 46 26

Types of changes

New feature/Enhancement.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.

@gziolo gziolo added Needs Design Feedback Needs general design feedback. [Block] List Affects the List Block [Type] Enhancement A suggestion for improvement. labels Jul 29, 2019
@gziolo gziolo self-assigned this Jul 29, 2019
@gziolo gziolo added the [Package] Block library /packages/block-library label Jul 29, 2019
@gziolo
Copy link
Member Author

gziolo commented Jul 29, 2019

There is a different order on the screen above but it should be tackled seperately as it's baked in the RichText implementation.

@ellatrix, is there any plan to move List controls out of RichText component?

@@ -463,7 +463,7 @@ RichTextContainer.Content = ( { value, tagName: Tag, multiline, ...props } ) =>
const content = <RawHTML>{ html }</RawHTML>;

if ( Tag ) {
return <Tag { ...omit( props, [ 'format' ] ) }>{ content }</Tag>;
return <Tag className={ className || undefined } { ...omit( props, [ 'format' ] ) }>{ content }</Tag>;
Copy link
Member Author

Choose a reason for hiding this comment

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

@ellatrix - this is necessary to avoid the case where <ul class="">...</ul> is saved in the post content. Does it make sense?

Copy link
Member

Choose a reason for hiding this comment

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

Why does the parent not pass undefined? What value is it passing?

Copy link
Member Author

Choose a reason for hiding this comment

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

it passes an empty string:

classnames() === '';

Copy link
Member

Choose a reason for hiding this comment

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

Ok, but then it should be handled by the parent, as the parent uses classnames, not RichText? E.g. classnames() || null.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this is one approach but then all blocks need to do it which is suboptimal. I prefer we have it covered.

I can add this logic to the List block if you strongly disagree.

@ellatrix
Copy link
Member

@gziolo I'll have a look today. Ideally they should move to the list block, yes.

@ellatrix
Copy link
Member

@gziolo #16536 moves the list controls as part of a refactoring.

@ellatrix
Copy link
Member

Btw, does text alignment make sense at all on a list block? Shouldn't the bullets and everything move as well then?

@gziolo
Copy link
Member Author

gziolo commented Jul 31, 2019

Btw, does text alignment make sense at all on a list block? Shouldn't the bullets and everything move as well then?

That's a very good question, I don't like how it looks as well. That's why I asked for design feedback. @mapk, @kjellr or @karmatosed - what do you think?

@kjellr
Copy link
Contributor

kjellr commented Jul 31, 2019

Yeah, I think the bullets would need to move as well — for example, when using a RTL language the bullets move over to the right side:

Screen Shot 2019-07-31 at 8 03 52 AM

For center aligned lists, the bullets should just appear inline:

Screen Shot 2019-07-31 at 8 06 58 AM

... But really, I don't think alternate alignments are all that common for the list block. I like including it in here for consistency's sake, but I don't think it'll be regularly used. If it's not a big deal implement these bullets, go for it. Otherwise, I think it's probably fine to leave alignment out for this block.

@draganescu
Copy link
Contributor

draganescu commented Jul 31, 2019

Aside from the change on which you have discussed with @ellatrix, the code seems ok, but the result of using text align is questionable especially if using indent as well:

Screenshot 2019-07-31 at 15 18 15

Screenshot 2019-07-31 at 15 18 02

@gziolo gziolo removed the Needs Design Feedback Needs general design feedback. label Jul 31, 2019
@gziolo
Copy link
Member Author

gziolo commented Jul 31, 2019

I have something like this working locally, I will push it soon:

Screen Shot 2019-07-31 at 14 29 03
Screen Shot 2019-07-31 at 14 40 45
Screen Shot 2019-07-31 at 14 41 47

@gziolo
Copy link
Member Author

gziolo commented Jul 31, 2019

422c987 contains all styling changes presented on screenshots presented in the previous comment. I think it looks better than I anticipated. I had to play a bit with the margin applied by default but I managed to skip it when text alignment is applied.

@ellatrix
Copy link
Member

Do you think nesting + aligning will work well? In the example above the text length of the nested items is shorter, so it looks like it's nested, but that will not always be the case. You may have some duplicate numbers without any indentation.

@gziolo
Copy link
Member Author

gziolo commented Aug 1, 2019

Do you think nesting + aligning will work well? In the example above the text length of the nested items is shorter, so it looks like it's nested, but that will not always be the case. You may have some duplicate numbers without any indentation.

I don't think this option will be super popular but it seems like we should offer it for consistency. There is a live preview of the effect so people can decide whether it makes sense in their particular case. I'm sure we can't anticipate all the reasons why people might want to use this capability. Theme authors might also have some good ideas about how this could be styled to make their design more compelling.

@shaunandrews
Copy link
Contributor

This seems like a bad idea. Just because other text-based blocks have alignment, doesn’t mean lists need it. Are there any real world use-cases for centered or right aligned lists? (And RTL doesn’t count, as the block should do that automatically.)

@mapk
Copy link
Contributor

mapk commented Aug 2, 2019

I'd like to echo the concerns of the others here and say that while this consistency is nice, I can't really imagine a real-world use case that works aesthetically. I suggest NOT including alignment controls on the List block.

@kjellr
Copy link
Contributor

kjellr commented Aug 2, 2019

That seems fine to me, too. It looks weird, and I don't think we've heard from anyone really asking for this feature. 👍

@gziolo
Copy link
Member Author

gziolo commented Aug 5, 2019

Thanks for all your feedback. Let's close this PR and update the original issues with what we agreed upon here 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] List Affects the List Block [Package] Block library /packages/block-library [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants