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

CheckboxControl: replace margin overrides with new opt-in prop #45434

Merged
merged 2 commits into from
Nov 3, 2022

Conversation

brookewp
Copy link
Contributor

@brookewp brookewp commented Nov 1, 2022

What?

Replacing margin overrides with new opt-in prop __nextHasNoMarginBottom for useages of CheckboxControl in the Gutenberg codebase.

Why?

Part of this project: #38730
The tl;dr is BaseControl has a margin-bottom which makes it difficult to reuse and results in inconsistent use.

How?

By removing margin overrides in the CSS and adding the prop __nextHasNoMarginBottom.

To note, CheckboxControl in packages/edit-navigation/src/components/sidebar/manage-locations.js wasn't updated. I couldn't find this on the front end so I'm unsure if it's being used. It looks like it might be a paused project.

Testing Instructions

To test this, you'll need to look for the following checkboxes and ensure that the margin is the same as before (margin-bottom of 0) for the div with class components-base-control__field. Screenshots below are how it looks in core right now.

  1. Create a new post and then go through the steps for each component:

For BlockManagerCategory and BlockTypesChecklist

  1. Click on three dots in the top right corner of post editor
  2. Then select 'Preferences'
  3. Click on 'Blocks' and scroll down to 'Visible Blocks'
  4. Ensure that the margins for the checkboxes are set to 0 as they were before for both the category and subcategories under 'Visible Blocks'

Screen Shot 2022-10-31 at 6 23 16 PM

ForPostSticky and PostPendingStatus

  1. Click on 'Post' in sidebar
  2. Ensure that the margins for the checkboxes are set to 0 as they were before for both 'Stick to the top of blog' and 'Pending Review'

Screen Shot 2022-10-31 at 6 22 54 PM

For HierarchicalTermSelector

  1. Under 'Post' in the sidebar click on 'Categories'
  2. Click 'Add new category' and add test category
  3. Ensure that the margins for the checkboxes are set to 0 as they were before for listed categories

Screen Shot 2022-10-31 at 6 29 00 PM

For PostComments and PostPingbacks

  1. Under 'Post' in the sidebar click on 'Discussion'
  2. Ensure that the margins for the checkboxes are set to 0 as they were before for 'Allow comments' and 'Allow pingbacks & trackbacks'

Screen Shot 2022-10-31 at 6 23 06 PM

For EntityRecordItem

  1. Add Navigation block to editor
  2. Add link to menu
  3. Click on 'Publish'
  4. Ensure that the margins for the checkboxes are set to 0 as they were before under 'Navigation Menus'

Screen Shot 2022-10-31 at 6 22 41 PM

For BlockLockModal

  1. Add any block (can use the Navigation block from above) to the editor
  2. Click on the three dots and then on 'Lock'
  3. Ensure that the margins for the checkboxes in modal are set to 0 as they were before

Screen Shot 2022-10-31 at 6 22 09 PM

For PostPublishPanel

  1. Make a change to the post
  2. Click on 'Publish'
  3. Ensure that the margins for the checkboxes are set to 0 as they were before for 'Always show pre-publish checks'

Screen Shot 2022-10-31 at 6 23 37 PM

Screenshots or screencast

@codesandbox
Copy link

codesandbox bot commented Nov 1, 2022

CodeSandbox logoCodeSandbox logo  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

@ciampo ciampo requested review from mirka, ciampo and chad1008 November 1, 2022 07:42
@ciampo ciampo added [Type] Enhancement A suggestion for improvement. [Package] Components /packages/components labels Nov 1, 2022
Copy link
Member

@mirka mirka 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 the amazing testing instructions, it was a breeze to review!

Everything looks good, we can merge once you update the snapshots and add a changelog.

Comment on lines 22 to 24
.components-base-control__field {
align-items: center;
display: flex;
Copy link
Member

Choose a reason for hiding this comment

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

Not in this PR, but a good follow-up for these would be to move the Icon out of the CheckboxControl label (it doesn't make sense), and move these flex styles into the parent element so we can remove these hacky overrides on components-base-control__field.

(Same with block-manager)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mirka when I initially read your comment, I assumed it was related to accessibility. I've just tested with my screen reader and looked a bit into it, but I couldn't find anything. Would you mind sharing why it is best to move the icon out of the label (aside from the opportunity to remove the CSS overrides)?

Copy link
Member

Choose a reason for hiding this comment

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

Correct, it's not an a11y issue, just that there is no reason for the aria-hidden icon to be in the label. The main motivation is to remove the CSS override. I'll add some context in case some of it was missing:

Any consumer usage that reaches into and overrides the internal styling of a wp-component is inherently brittle. If BaseControl changes its structure or styling at some point, these BlockLock overrides could break in unexpected ways. We've been discouraging style hacks like this, since it actively harms our ability to make changes to wp-components without things breaking all over the place. It's doubly harmful because third-party devs often turn to the Gutenberg source code to learn how they should be building things.

So when things look like you might want to override internal wp-component styling, the decision flow would roughly be like:

  1. Can I accomplish the same thing without adding a style hack? If so, that is always better.
  2. Is this a common design pattern that will appear multiple times in the Gutenberg app? If so, consider proposing a change to the wp-component in question so it can flexibly handle more use cases out of the box.
  3. If no to either of those questions, consider building your own component from scratch, or modifying your design so it works within the existing component limitations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the detailed explanation! Very helpful! 🙌

@brookewp brookewp force-pushed the update/margin-checkbox-control branch from e6470f9 to 99ac2c3 Compare November 2, 2022 23:46
@brookewp brookewp marked this pull request as ready for review November 3, 2022 00:12
@brookewp brookewp requested a review from ellatrix as a code owner November 3, 2022 00:12
@brookewp brookewp requested review from mirka and removed request for ciampo, ellatrix and chad1008 November 3, 2022 00:55
Copy link
Member

@mirka mirka left a comment

Choose a reason for hiding this comment

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

Ah never mind about the changelog, this PR doesn't need one 😄

Good to go then! 🚀

@mirka mirka merged commit 3325937 into WordPress:trunk Nov 3, 2022
@github-actions github-actions bot added this to the Gutenberg 14.6 milestone Nov 3, 2022
@mirka mirka mentioned this pull request Nov 3, 2022
49 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants