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

Fix default text alignment #1496

Closed
wants to merge 1 commit into from
Closed

Fix default text alignment #1496

wants to merge 1 commit into from

Conversation

ellatrix
Copy link
Member

This PR makes the left text align button active when there is no text alignment set, and also removes the attribute when the alignment is set to left.

@ellatrix ellatrix requested a review from dmsnell June 27, 2017 12:14
return toSave;
}

return Object.assign( toSave, { [ key ]: allValue } );
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice to break this into two PRs: one that modifies the behavior of the left alignment; one that changes what it means to save attributes.

To this point I haven't heard discussion about whether we should save null values and while I could see value in trimming them out, I think it's worth making sure we don't want to save them.

In any case, was there a reason to not only change the condition but also change the code structure?

Copy link
Member Author

Choose a reason for hiding this comment

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

You mean switching away from ! ( ... ) ? ... : ...? I found it easier to read, sorry. :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Regarding striping out null, I find it a bit strange to define as undefined and it doesn't seem to play well with React. Also, they strip out null as well.

Copy link
Member Author

@ellatrix ellatrix Jun 27, 2017

Choose a reason for hiding this comment

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

E.g. style={ { textAlign: align } } when it updates from a string to undefined, it won't update at all. When it changes to null, it does.

Copy link
Member

Choose a reason for hiding this comment

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

I found it easier to read, sorry.

let's leave personal styling to separate PRs? I mean, it's fine, but I find the ternary easier to read in that it indicates that the return value is dependent on the condition ¯\_(ツ)_/¯

Copy link
Member

Choose a reason for hiding this comment

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

I find it a bit strange to define as undefined and it doesn't seem to play well with React. Also, they strip out null as well.

what do you mean here? React doesn't touch null values passed through as props.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry for commenting in multiple comments: #1496 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

Sorry for commenting in multiple comments: #1496 (comment)

?? I don't know what you are apologizing for but I was not offended 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

For the confusing multiple comments that might pop up with a delay. :)

@ellatrix ellatrix force-pushed the fix/default-text-align branch from c2ede0c to 9cba931 Compare June 27, 2017 13:27
@ellatrix ellatrix force-pushed the fix/default-text-align branch from 9cba931 to 58ec593 Compare June 27, 2017 13:29
@ellatrix
Copy link
Member Author

Okay, let's keep undefined. :)

@ellatrix ellatrix requested a review from jasmussen June 27, 2017 13:29
@jasmussen
Copy link
Contributor

This PR makes the left text align button active when there is no text alignment set, and also removes the attribute when the alignment is set to left.

Interestingly, @youknowriad actually made a PR just like this way back in the day, because I had the same instinct as you had. Then I realized that both the old WordPress editor, as well as Google Docs and many others behaved this way: by default, text has no alignment. And even if that "no alignment" happens to be the same as left aligned visually, selecting that text and pressing "left align" applies an explicit left alignment where none was before.

As a result, I'm not actually completely sure what we should do here, and I could go either way.

On one hand, the behavior currently in master matches most other text editors.

On the other hand, we are recasting paragraphs as blocks, and the alignments to be "global" to that block, and so perhaps this begs a rethinking of the behavior.

Any thoughts, @melchoyce @folletto?

@folletto
Copy link
Contributor

I did a quick benchmark.

Google Docs does it on a brand new document (even if it's then possible to deselect it and nothing changes):

screen shot 2017-06-27 at 14 48 30

Pages does it:

screen shot 2017-06-27 at 14 48 00

Word does it (old version I have):

screen shot 2017-06-27 at 14 48 03

My take is that it was a technicality as you touched too: if it was selected it explicitly added a text-align rule to override anything the stylesheet would have done later in the theme, while if not selected it just inherited. This avoid the scenario where we assume "it's left aligned" and then the theme justifies it (or centers it).

So if I currently explicitly left-align in WP Admin:

screen shot 2017-06-27 at 14 54 19

And if I don't:

screen shot 2017-06-27 at 14 54 09

It's yet again one of the quirks due to the high flexibility of WordPress editor and themes, and inheriting from the complexity of CSS.

My take would be to try if possible without too much overriding going on to be explicit and do left-align by default (toggled), regardless of what the theme will do later.

I can see three options:

  1. We allow to "deselect" an alignment (and default there).
  2. We default to left-align — in practice removing explicit "left-align" inline CSS style.
  3. We default to left-align, but we allow a hidden state triggered when the alignment is clicked twice (the icon might change in a left align with a lock, or something).

For ease of release, I'd probably go by keeping the current behaviour (unselected = no explicit style, assumes theme is left-aligning / inheritance), and explore alternatives after Gutenberg ships.

@ellatrix
Copy link
Member Author

For ease of release, I'd probably go by keeping the current behaviour (unselected = no explicit style, assumes theme is left-aligning / inheritance), and explore alternatives after Gutenberg ships.

I agree. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants