Skip to content

Conversation

@ockham
Copy link
Contributor

@ockham ockham commented Jul 10, 2019

Fixes #13007.
Fixes #13008, too 😎

Changes proposed in this Pull Request:

Paid Blocks Nudge: Fix Border by Injecting has-warning Style

Prior to this PR, we used custom styling for the jetpack-paid-block__wrapper class, using padding and negative margins. This lead to visual glitches such as #13007:

Screenshot 2019-07-05 at 15 56 01

As documented there, this is because that kind of styling doesn't play well with Gutenberg's own, which is using absolute positioning on :before selectors such as

  • .block-editor-block-list__layout .block-editor-block-list__block .block-editor-block-list__block-edit:before
  • .block-editor-block-list__layout .block-editor-block-list__block.is-selected>.block-editor-block-list__block-edit:before
  • .block-editor-block-list__layout .block-editor-block-list__block.has-warning .block-editor-block-list__block-edit:before

So ideally, we want to piggy-back on those selectors -- the has-warning ones in particular, since they do precisely what we want (also on a conceptual level). However, that's not easy from within the block, since those selectors apply to the block wrapper. Class names for that wrapper are pretty much hard-wired, and there aren't really any props to that element that we could (or should) modify to enforce the styling we want.

But fortunately, there's a filter to modify those wrappers 🎉

This PR thus uses that filter to inject the has-warning class, fixing #13007, and allowing us to drop a bunch of custom styling.

However, the has-warning selector also adds styling to prevent user interactivity with the given block (see #13019 (comment) for details), so we need to override that behavior, since we want to ensure the user can continue to interact with the block. To that end, we add another class name, is-interactive for increase specificity, and override the styling that would otherwise prevent user interactions.

Is this a new feature or does it add/remove features to an existing part of Jetpack?

Modifies the existing paid plan nudge.

Testing instructions:

  • Switch to this branch locally, build Jetpack (yarn build), and start Docker (yarn docker:up)
  • Now add the following line to any file in docker/mu-plugins, e.g. a newly created 0-blocks-upgrade.php (needs to start with <?php): define ( 'JETPACK_SHOW_BLOCK_UPGRADE_NUDGE', true );
  • Make sure you're connected to WP.com, and on a free plan
  • Start a new post, and insert the 'Simple Payments' block
  • Select the block, and enter some information into its text fields.
  • Unselect the block again
  • Verify that the visual glitch seen in the above screenshot is fixed.
  • Verify that you can still select and edit the block.
  • Finally, verify that Premium block nudge: turn banner blue when multiple blocks are selected #13008 is also fixed by this PR 🎉

Proposed changelog entry for your changes:

(Covered by whatever we add for #12823)

@ockham ockham added [Status] Needs Review This PR is ready for review. [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack labels Jul 10, 2019
@ockham ockham requested review from a team July 10, 2019 11:15
@ockham ockham self-assigned this Jul 10, 2019
@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello ockham! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer, review, and approve D30305-code before merging this PR. Thank you!

@jetpackbot
Copy link
Collaborator

jetpackbot commented Jul 10, 2019

Thank you for the great PR description!

When this PR is ready for review, please apply the [Status] Needs Review label. If you are an a11n, please have someone from your team review the code if possible. The Jetpack team will also review this PR and merge it to be included in the next Jetpack release.

Scheduled Jetpack release: August 6, 2019.
Scheduled code freeze: July 30, 2019

Generated by 🚫 dangerJS against 5f9b77a

@matticbot
Copy link
Contributor

ockham, Your synced wpcom patch D30305-code has been updated.

@matticbot
Copy link
Contributor

ockham, Your synced wpcom patch D30305-code has been updated.

Copy link
Member

@simison simison left a comment

Choose a reason for hiding this comment

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

I'm now getting this class for every block:
image

Furthermore, I cannot edit fields in simple payments block which defeats the purpose of us letting users to try it out.

@ockham
Copy link
Contributor Author

ockham commented Jul 10, 2019

Ugh my bad. I'll try to find a fix...

@simison
Copy link
Member

simison commented Jul 10, 2019

Might be easiest to keep this implementation and override the background color + layer that stops pointer interactions?

@matticbot
Copy link
Contributor

ockham, Your synced wpcom patch D30305-code has been updated.

@ockham
Copy link
Contributor Author

ockham commented Jul 10, 2019

Might be easiest to keep this implementation and override the background color + layer that stops pointer interactions?

Exactly my plan 👍

@matticbot
Copy link
Contributor

ockham, Your synced wpcom patch D30305-code has been updated.

@ockham
Copy link
Contributor Author

ockham commented Jul 10, 2019

@matticbot
Copy link
Contributor

ockham, Your synced wpcom patch D30305-code has been updated.

@ockham ockham requested a review from simison July 10, 2019 17:01
@ockham ockham dismissed simison’s stale review July 10, 2019 17:02

Issue found in review should be fixed now

if ( requiredPlan ) {
addFilter(
'editor.BlockListBlock',
`jetpack/${ name }-with-has-warning-is-interactive-class-names`,
Copy link
Member

Choose a reason for hiding this comment

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

Haha that's a mouthful!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, same for the component name 😬 Happy to change it something more palatable!

simison
simison previously approved these changes Jul 11, 2019
Copy link
Member

@simison simison left a comment

Choose a reason for hiding this comment

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

Looking good and works fabulously well!

BlockListBlock => props => (
<BlockListBlock
{ ...props }
className={ props.name === name ? 'has-warning is-interactive' : '' }
Copy link
Member

Choose a reason for hiding this comment

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

is-interactive isn't a core class, right? Therefore I'd jetpack-prefix it. Not a blocker tho.

Copy link
Contributor

@zinigor zinigor left a comment

Choose a reason for hiding this comment

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

Works well for me, the border appears as it should.

@zinigor zinigor added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review This PR is ready for review. labels Jul 11, 2019
@ockham ockham merged commit 78ed77c into master Jul 12, 2019
@ockham ockham deleted the fix/paid-block-border branch July 12, 2019 06:19
@matticbot matticbot added [Status] Needs Changelog and removed [Status] Ready to Merge Go ahead, you can push that green button! labels Jul 12, 2019
@jeherve jeherve added this to the 7.6 milestone Jul 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack Touches WP.com Files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Premium block nudge: turn banner blue when multiple blocks are selected Premium block flows: border/spacing adjustments

7 participants