Skip to content

Don’t auto-select a pullquote text colour for regular style#10792

Merged
johngodley merged 3 commits into
masterfrom
fix/pullquote-auto-colour
Nov 6, 2018
Merged

Don’t auto-select a pullquote text colour for regular style#10792
johngodley merged 3 commits into
masterfrom
fix/pullquote-auto-colour

Conversation

@johngodley
Copy link
Copy Markdown
Contributor

@johngodley johngodley commented Oct 19, 2018

The pullquote block auto-selects an appropriate text colour based on the main colour. This is designed to give a good contrast. However it assumes the quote has a 'solid colour' style where the main colour is the background, with the text overlayed:

edit_post_ wordpress_latest _wordpress

If the pullquote uses the 'regular colour' style the background is white (or whatever the theme uses), and the main colour changes the top and bottom border:

edit_post_ wordpress_latest _wordpress

The colour calculated for the main colour background can often give a poor contrast ratio on this white background.

For example, if you create a pull quote with regular style and pick red as the main colour it sets the text colour to light grey (the calculated text colour for red). In the above solid colour quote this gives good contrast, but on a regular colour quote with white background it gives poor contrast:

edit_post_ wordpress_latest _wordpress

This PR restricts the auto-colour selection to the 'solid colour' style only. I'm not sure if this fits the intended purpose of the block, but it fixes the problem in this instance.

Also fixes the situation where clicking 'clear' on the main colour sets a text colour.

Fixes #10568

How has this been tested?

  1. Create a pull quote block
  2. Open block settings
  3. Set main colour to red
  4. Confirm the text colour does not change
  5. Clear the text colour
  6. Clear the main colour and verify that the text colour is not set

Checklist:

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

Regular style uses the theme background, but the auto-selected colour assumes the main colour is the background. This can often lead to a very poor colour choice.
@johngodley johngodley added [Feature] Blocks Overall functionality of blocks [Status] In Progress Tracking issues with work in progress labels Oct 19, 2018
This prevents clearing of the main colour from setting the text colour
@johngodley johngodley removed the [Status] In Progress Tracking issues with work in progress label Oct 19, 2018
Copy link
Copy Markdown
Member

@jorgefilipecosta jorgefilipecosta left a comment

Choose a reason for hiding this comment

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

Thank you for this change @johngodley this generally works well on my tests 👍 There is only an edge case that I think we may be able to improve.


setMainColor( colorValue );
if ( ! textColor.color || this.wasTextColorAutomaticallyComputed ) {
if ( shouldSetTextColor || this.wasTextColorAutomaticallyComputed ) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If we go the solid color style we pick the main color, and then we change to the regular style, each time we change the main color the text color continue to change.
I think maybe we can solve this by updating shouldSetTextColor to be isSolidColorStyle && colorValue && ( ! textColor.color || this.wasTextColorAutomaticallyComputed );

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah yes, nice! Updated

If you picked the solid style and set a main colour and then switched to regular style and picked a main colour it would continue to change the text colour. This moves the wasTextColorAutomaticallyComputed check so this doesn’t happen
Copy link
Copy Markdown
Member

@jorgefilipecosta jorgefilipecosta left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@johngodley johngodley added this to the 4.3 milestone Nov 6, 2018
@johngodley johngodley merged commit ead88a1 into master Nov 6, 2018
@johngodley johngodley deleted the fix/pullquote-auto-colour branch November 6, 2018 09:32
@mtias mtias added the [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). label Nov 12, 2018
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 [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pull Quote: Selecting Red & Black as main color changes text color, too.

3 participants