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

Allow negative values for margin controls #60347

Merged
merged 16 commits into from
Apr 22, 2024
Merged

Conversation

MaggieCabrera
Copy link
Contributor

@MaggieCabrera MaggieCabrera commented Apr 1, 2024

What?

An alternative to #40464
Closes #32644

Why?

To bring parity from theme.json to the controls. A theme can define negative margins via theme.json but not via the templates, which is when they are most useful.

How?

Looking at the previous conversations we have a few things to consider to achieve this:

  1. Block selection in the editor when blocks overlap each other. The UX can get a little complicated.
  2. The previous attempt to do this was adding a new prop, we don't need this anymore, so we are not adding new APIs to achieve this, we are only altering the minimum value that the input accepts only for the margin spacing controls
  3. We need to update the block support's visualizer to show the negative margin. @jasmussen suggests to use a gray color instead of blue. This could happen in a follow up.

Of all of these, 1 is the most concerning. The idea behind this PR is that we only allow negative values if the user consciously choses to add a minus before the margin values. This PR adds a z-index value to the currently selected block in order to keep it in the front to help with this.

To do:

These can be done on separate PRs

To consider:

  • Should we limit the value that a negative margin can achieve to prevent block navigation issues? I'm hesitant to do this but it has been suggested.

Testing Instructions

Check that you can add negative margins on any blocks that support them such as: group, paragraph, columns, code, cover, separator, spacer...

Check that the frontend and the editor show the same thing

Check that in the editor when you select a block it brings it to the forefront even if it's being overlapped by another. This should not happen in the frontend.

If a theme doesn't have spacingSizes declared (no spacing presets), the above should behave the same way.

Testing Instructions for Keyboard

Screenshots or screencast

@MaggieCabrera MaggieCabrera added [Type] Enhancement A suggestion for improvement. Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json labels Apr 1, 2024
Copy link

github-actions bot commented Apr 1, 2024

Size Change: +456 B (0%)

Total Size: 1.75 MB

Filename Size Change
build/block-editor/content-rtl.css 4.53 kB +26 B (+1%)
build/block-editor/content.css 4.53 kB +25 B (+1%)
build/block-editor/index.min.js 256 kB +134 B (0%)
build/block-library/blocks/group/style-rtl.css 103 B +46 B (+81%) 🆘
build/block-library/blocks/group/style.css 103 B +46 B (+81%) 🆘
build/block-library/style-rtl.css 14.8 kB +21 B (0%)
build/block-library/style.css 14.8 kB +21 B (0%)
build/components/index.min.js 220 kB +137 B (0%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 955 B
build/annotations/index.min.js 2.27 kB
build/api-fetch/index.min.js 2.32 kB
build/autop/index.min.js 2.1 kB
build/blob/index.min.js 578 B
build/block-directory/index.min.js 7.26 kB
build/block-directory/style-rtl.css 1.03 kB
build/block-directory/style.css 1.03 kB
build/block-editor/default-editor-styles-rtl.css 395 B
build/block-editor/default-editor-styles.css 395 B
build/block-editor/style-rtl.css 15.7 kB
build/block-editor/style.css 15.7 kB
build/block-library/blocks/archives/editor-rtl.css 61 B
build/block-library/blocks/archives/editor.css 60 B
build/block-library/blocks/archives/style-rtl.css 90 B
build/block-library/blocks/archives/style.css 90 B
build/block-library/blocks/audio/editor-rtl.css 150 B
build/block-library/blocks/audio/editor.css 150 B
build/block-library/blocks/audio/style-rtl.css 122 B
build/block-library/blocks/audio/style.css 122 B
build/block-library/blocks/audio/theme-rtl.css 133 B
build/block-library/blocks/audio/theme.css 133 B
build/block-library/blocks/avatar/editor-rtl.css 116 B
build/block-library/blocks/avatar/editor.css 116 B
build/block-library/blocks/avatar/style-rtl.css 104 B
build/block-library/blocks/avatar/style.css 104 B
build/block-library/blocks/block/editor-rtl.css 305 B
build/block-library/blocks/block/editor.css 305 B
build/block-library/blocks/button/editor-rtl.css 415 B
build/block-library/blocks/button/editor.css 414 B
build/block-library/blocks/button/style-rtl.css 627 B
build/block-library/blocks/button/style.css 626 B
build/block-library/blocks/buttons/editor-rtl.css 337 B
build/block-library/blocks/buttons/editor.css 337 B
build/block-library/blocks/buttons/style-rtl.css 332 B
build/block-library/blocks/buttons/style.css 332 B
build/block-library/blocks/calendar/style-rtl.css 239 B
build/block-library/blocks/calendar/style.css 239 B
build/block-library/blocks/categories/editor-rtl.css 113 B
build/block-library/blocks/categories/editor.css 112 B
build/block-library/blocks/categories/style-rtl.css 124 B
build/block-library/blocks/categories/style.css 124 B
build/block-library/blocks/code/editor-rtl.css 53 B
build/block-library/blocks/code/editor.css 53 B
build/block-library/blocks/code/style-rtl.css 121 B
build/block-library/blocks/code/style.css 121 B
build/block-library/blocks/code/theme-rtl.css 124 B
build/block-library/blocks/code/theme.css 124 B
build/block-library/blocks/columns/editor-rtl.css 108 B
build/block-library/blocks/columns/editor.css 108 B
build/block-library/blocks/columns/style-rtl.css 421 B
build/block-library/blocks/columns/style.css 421 B
build/block-library/blocks/comment-author-avatar/editor-rtl.css 125 B
build/block-library/blocks/comment-author-avatar/editor.css 125 B
build/block-library/blocks/comment-content/style-rtl.css 92 B
build/block-library/blocks/comment-content/style.css 92 B
build/block-library/blocks/comment-template/style-rtl.css 199 B
build/block-library/blocks/comment-template/style.css 198 B
build/block-library/blocks/comments-pagination-numbers/editor-rtl.css 123 B
build/block-library/blocks/comments-pagination-numbers/editor.css 121 B
build/block-library/blocks/comments-pagination/editor-rtl.css 222 B
build/block-library/blocks/comments-pagination/editor.css 209 B
build/block-library/blocks/comments-pagination/style-rtl.css 235 B
build/block-library/blocks/comments-pagination/style.css 231 B
build/block-library/blocks/comments-title/editor-rtl.css 75 B
build/block-library/blocks/comments-title/editor.css 75 B
build/block-library/blocks/comments/editor-rtl.css 840 B
build/block-library/blocks/comments/editor.css 839 B
build/block-library/blocks/comments/style-rtl.css 637 B
build/block-library/blocks/comments/style.css 636 B
build/block-library/blocks/cover/editor-rtl.css 671 B
build/block-library/blocks/cover/editor.css 674 B
build/block-library/blocks/cover/style-rtl.css 1.7 kB
build/block-library/blocks/cover/style.css 1.69 kB
build/block-library/blocks/details/editor-rtl.css 65 B
build/block-library/blocks/details/editor.css 65 B
build/block-library/blocks/details/style-rtl.css 86 B
build/block-library/blocks/details/style.css 86 B
build/block-library/blocks/embed/editor-rtl.css 322 B
build/block-library/blocks/embed/editor.css 322 B
build/block-library/blocks/embed/style-rtl.css 410 B
build/block-library/blocks/embed/style.css 410 B
build/block-library/blocks/embed/theme-rtl.css 133 B
build/block-library/blocks/embed/theme.css 133 B
build/block-library/blocks/file/editor-rtl.css 326 B
build/block-library/blocks/file/editor.css 327 B
build/block-library/blocks/file/style-rtl.css 280 B
build/block-library/blocks/file/style.css 281 B
build/block-library/blocks/file/view.min.js 324 B
build/block-library/blocks/footnotes/style-rtl.css 201 B
build/block-library/blocks/footnotes/style.css 199 B
build/block-library/blocks/form-input/editor-rtl.css 227 B
build/block-library/blocks/form-input/editor.css 227 B
build/block-library/blocks/form-input/style-rtl.css 343 B
build/block-library/blocks/form-input/style.css 343 B
build/block-library/blocks/form-submission-notification/editor-rtl.css 340 B
build/block-library/blocks/form-submission-notification/editor.css 340 B
build/block-library/blocks/form-submit-button/style-rtl.css 69 B
build/block-library/blocks/form-submit-button/style.css 69 B
build/block-library/blocks/form/view.min.js 471 B
build/block-library/blocks/freeform/editor-rtl.css 2.61 kB
build/block-library/blocks/freeform/editor.css 2.61 kB
build/block-library/blocks/gallery/editor-rtl.css 956 B
build/block-library/blocks/gallery/editor.css 960 B
build/block-library/blocks/gallery/style-rtl.css 1.72 kB
build/block-library/blocks/gallery/style.css 1.72 kB
build/block-library/blocks/gallery/theme-rtl.css 108 B
build/block-library/blocks/gallery/theme.css 108 B
build/block-library/blocks/group/editor-rtl.css 647 B
build/block-library/blocks/group/editor.css 647 B
build/block-library/blocks/group/theme-rtl.css 78 B
build/block-library/blocks/group/theme.css 78 B
build/block-library/blocks/heading/style-rtl.css 189 B
build/block-library/blocks/heading/style.css 189 B
build/block-library/blocks/html/editor-rtl.css 336 B
build/block-library/blocks/html/editor.css 337 B
build/block-library/blocks/image/editor-rtl.css 878 B
build/block-library/blocks/image/editor.css 878 B
build/block-library/blocks/image/style-rtl.css 1.6 kB
build/block-library/blocks/image/style.css 1.59 kB
build/block-library/blocks/image/theme-rtl.css 133 B
build/block-library/blocks/image/theme.css 133 B
build/block-library/blocks/image/view.min.js 1.54 kB
build/block-library/blocks/latest-comments/style-rtl.css 357 B
build/block-library/blocks/latest-comments/style.css 357 B
build/block-library/blocks/latest-posts/editor-rtl.css 213 B
build/block-library/blocks/latest-posts/editor.css 212 B
build/block-library/blocks/latest-posts/style-rtl.css 478 B
build/block-library/blocks/latest-posts/style.css 478 B
build/block-library/blocks/list/style-rtl.css 88 B
build/block-library/blocks/list/style.css 88 B
build/block-library/blocks/media-text/editor-rtl.css 306 B
build/block-library/blocks/media-text/editor.css 305 B
build/block-library/blocks/media-text/style-rtl.css 505 B
build/block-library/blocks/media-text/style.css 503 B
build/block-library/blocks/more/editor-rtl.css 431 B
build/block-library/blocks/more/editor.css 431 B
build/block-library/blocks/navigation-link/editor-rtl.css 668 B
build/block-library/blocks/navigation-link/editor.css 669 B
build/block-library/blocks/navigation-link/style-rtl.css 259 B
build/block-library/blocks/navigation-link/style.css 257 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 296 B
build/block-library/blocks/navigation-submenu/editor.css 295 B
build/block-library/blocks/navigation/editor-rtl.css 2.26 kB
build/block-library/blocks/navigation/editor.css 2.26 kB
build/block-library/blocks/navigation/style-rtl.css 2.26 kB
build/block-library/blocks/navigation/style.css 2.25 kB
build/block-library/blocks/navigation/view.min.js 1.03 kB
build/block-library/blocks/nextpage/editor-rtl.css 395 B
build/block-library/blocks/nextpage/editor.css 395 B
build/block-library/blocks/page-list/editor-rtl.css 377 B
build/block-library/blocks/page-list/editor.css 377 B
build/block-library/blocks/page-list/style-rtl.css 175 B
build/block-library/blocks/page-list/style.css 175 B
build/block-library/blocks/paragraph/editor-rtl.css 235 B
build/block-library/blocks/paragraph/editor.css 235 B
build/block-library/blocks/paragraph/style-rtl.css 335 B
build/block-library/blocks/paragraph/style.css 335 B
build/block-library/blocks/post-author/style-rtl.css 175 B
build/block-library/blocks/post-author/style.css 176 B
build/block-library/blocks/post-comments-form/editor-rtl.css 96 B
build/block-library/blocks/post-comments-form/editor.css 96 B
build/block-library/blocks/post-comments-form/style-rtl.css 508 B
build/block-library/blocks/post-comments-form/style.css 508 B
build/block-library/blocks/post-content/editor-rtl.css 74 B
build/block-library/blocks/post-content/editor.css 74 B
build/block-library/blocks/post-date/style-rtl.css 61 B
build/block-library/blocks/post-date/style.css 61 B
build/block-library/blocks/post-excerpt/editor-rtl.css 71 B
build/block-library/blocks/post-excerpt/editor.css 71 B
build/block-library/blocks/post-excerpt/style-rtl.css 141 B
build/block-library/blocks/post-excerpt/style.css 141 B
build/block-library/blocks/post-featured-image/editor-rtl.css 729 B
build/block-library/blocks/post-featured-image/editor.css 727 B
build/block-library/blocks/post-featured-image/style-rtl.css 342 B
build/block-library/blocks/post-featured-image/style.css 342 B
build/block-library/blocks/post-navigation-link/style-rtl.css 215 B
build/block-library/blocks/post-navigation-link/style.css 214 B
build/block-library/blocks/post-template/editor-rtl.css 99 B
build/block-library/blocks/post-template/editor.css 98 B
build/block-library/blocks/post-template/style-rtl.css 409 B
build/block-library/blocks/post-template/style.css 408 B
build/block-library/blocks/post-terms/style-rtl.css 96 B
build/block-library/blocks/post-terms/style.css 96 B
build/block-library/blocks/post-time-to-read/style-rtl.css 69 B
build/block-library/blocks/post-time-to-read/style.css 69 B
build/block-library/blocks/post-title/style-rtl.css 100 B
build/block-library/blocks/post-title/style.css 100 B
build/block-library/blocks/preformatted/style-rtl.css 125 B
build/block-library/blocks/preformatted/style.css 125 B
build/block-library/blocks/pullquote/editor-rtl.css 135 B
build/block-library/blocks/pullquote/editor.css 135 B
build/block-library/blocks/pullquote/style-rtl.css 354 B
build/block-library/blocks/pullquote/style.css 353 B
build/block-library/blocks/pullquote/theme-rtl.css 174 B
build/block-library/blocks/pullquote/theme.css 174 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B
build/block-library/blocks/query-pagination/editor-rtl.css 221 B
build/block-library/blocks/query-pagination/editor.css 211 B
build/block-library/blocks/query-pagination/style-rtl.css 288 B
build/block-library/blocks/query-pagination/style.css 284 B
build/block-library/blocks/query-title/style-rtl.css 63 B
build/block-library/blocks/query-title/style.css 63 B
build/block-library/blocks/query/editor-rtl.css 486 B
build/block-library/blocks/query/editor.css 486 B
build/block-library/blocks/query/view.min.js 958 B
build/block-library/blocks/quote/style-rtl.css 237 B
build/block-library/blocks/quote/style.css 237 B
build/block-library/blocks/quote/theme-rtl.css 233 B
build/block-library/blocks/quote/theme.css 235 B
build/block-library/blocks/read-more/style-rtl.css 140 B
build/block-library/blocks/read-more/style.css 140 B
build/block-library/blocks/rss/editor-rtl.css 149 B
build/block-library/blocks/rss/editor.css 149 B
build/block-library/blocks/rss/style-rtl.css 289 B
build/block-library/blocks/rss/style.css 288 B
build/block-library/blocks/search/editor-rtl.css 184 B
build/block-library/blocks/search/editor.css 184 B
build/block-library/blocks/search/style-rtl.css 690 B
build/block-library/blocks/search/style.css 689 B
build/block-library/blocks/search/theme-rtl.css 114 B
build/block-library/blocks/search/theme.css 114 B
build/block-library/blocks/search/view.min.js 478 B
build/block-library/blocks/separator/editor-rtl.css 146 B
build/block-library/blocks/separator/editor.css 146 B
build/block-library/blocks/separator/style-rtl.css 239 B
build/block-library/blocks/separator/style.css 239 B
build/block-library/blocks/separator/theme-rtl.css 194 B
build/block-library/blocks/separator/theme.css 194 B
build/block-library/blocks/shortcode/editor-rtl.css 323 B
build/block-library/blocks/shortcode/editor.css 323 B
build/block-library/blocks/site-logo/editor-rtl.css 801 B
build/block-library/blocks/site-logo/editor.css 801 B
build/block-library/blocks/site-logo/style-rtl.css 204 B
build/block-library/blocks/site-logo/style.css 204 B
build/block-library/blocks/site-tagline/editor-rtl.css 86 B
build/block-library/blocks/site-tagline/editor.css 86 B
build/block-library/blocks/site-title/editor-rtl.css 116 B
build/block-library/blocks/site-title/editor.css 116 B
build/block-library/blocks/site-title/style-rtl.css 57 B
build/block-library/blocks/site-title/style.css 57 B
build/block-library/blocks/social-link/editor-rtl.css 184 B
build/block-library/blocks/social-link/editor.css 184 B
build/block-library/blocks/social-links/editor-rtl.css 676 B
build/block-library/blocks/social-links/editor.css 675 B
build/block-library/blocks/social-links/style-rtl.css 1.48 kB
build/block-library/blocks/social-links/style.css 1.48 kB
build/block-library/blocks/spacer/editor-rtl.css 350 B
build/block-library/blocks/spacer/editor.css 350 B
build/block-library/blocks/spacer/style-rtl.css 48 B
build/block-library/blocks/spacer/style.css 48 B
build/block-library/blocks/table/editor-rtl.css 395 B
build/block-library/blocks/table/editor.css 395 B
build/block-library/blocks/table/style-rtl.css 639 B
build/block-library/blocks/table/style.css 639 B
build/block-library/blocks/table/theme-rtl.css 152 B
build/block-library/blocks/table/theme.css 152 B
build/block-library/blocks/tag-cloud/style-rtl.css 251 B
build/block-library/blocks/tag-cloud/style.css 253 B
build/block-library/blocks/template-part/editor-rtl.css 431 B
build/block-library/blocks/template-part/editor.css 431 B
build/block-library/blocks/template-part/theme-rtl.css 107 B
build/block-library/blocks/template-part/theme.css 107 B
build/block-library/blocks/term-description/style-rtl.css 111 B
build/block-library/blocks/term-description/style.css 111 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B
build/block-library/blocks/text-columns/editor.css 95 B
build/block-library/blocks/text-columns/style-rtl.css 166 B
build/block-library/blocks/text-columns/style.css 166 B
build/block-library/blocks/verse/style-rtl.css 99 B
build/block-library/blocks/verse/style.css 99 B
build/block-library/blocks/video/editor-rtl.css 552 B
build/block-library/blocks/video/editor.css 555 B
build/block-library/blocks/video/style-rtl.css 185 B
build/block-library/blocks/video/style.css 185 B
build/block-library/blocks/video/theme-rtl.css 133 B
build/block-library/blocks/video/theme.css 133 B
build/block-library/classic-rtl.css 179 B
build/block-library/classic.css 179 B
build/block-library/common-rtl.css 1.11 kB
build/block-library/common.css 1.11 kB
build/block-library/editor-elements-rtl.css 75 B
build/block-library/editor-elements.css 75 B
build/block-library/editor-rtl.css 12.4 kB
build/block-library/editor.css 12.4 kB
build/block-library/elements-rtl.css 54 B
build/block-library/elements.css 54 B
build/block-library/index.min.js 219 kB
build/block-library/reset-rtl.css 472 B
build/block-library/reset.css 472 B
build/block-library/theme-rtl.css 707 B
build/block-library/theme.css 713 B
build/block-serialization-default-parser/index.min.js 1.12 kB
build/block-serialization-spec-parser/index.min.js 2.87 kB
build/blocks/index.min.js 51.6 kB
build/commands/index.min.js 15.2 kB
build/commands/style-rtl.css 953 B
build/commands/style.css 951 B
build/components/style-rtl.css 11.9 kB
build/components/style.css 11.9 kB
build/compose/index.min.js 12.6 kB
build/core-commands/index.min.js 2.77 kB
build/core-data/index.min.js 72.5 kB
build/customize-widgets/index.min.js 11 kB
build/customize-widgets/style-rtl.css 1.36 kB
build/customize-widgets/style.css 1.36 kB
build/data-controls/index.min.js 640 B
build/data/index.min.js 9 kB
build/date/index.min.js 17.9 kB
build/deprecated/index.min.js 451 B
build/dom-ready/index.min.js 324 B
build/dom/index.min.js 4.65 kB
build/edit-post/classic-rtl.css 578 B
build/edit-post/classic.css 578 B
build/edit-post/index.min.js 17.9 kB
build/edit-post/style-rtl.css 4.24 kB
build/edit-post/style.css 4.23 kB
build/edit-site/index.min.js 225 kB
build/edit-site/style-rtl.css 13.9 kB
build/edit-site/style.css 13.9 kB
build/edit-widgets/index.min.js 17.6 kB
build/edit-widgets/style-rtl.css 4.16 kB
build/edit-widgets/style.css 4.16 kB
build/editor/index.min.js 77.9 kB
build/editor/style-rtl.css 6.95 kB
build/editor/style.css 6.95 kB
build/element/index.min.js 4.83 kB
build/escape-html/index.min.js 537 B
build/format-library/index.min.js 8.07 kB
build/format-library/style-rtl.css 493 B
build/format-library/style.css 492 B
build/hooks/index.min.js 1.55 kB
build/html-entities/index.min.js 448 B
build/i18n/index.min.js 3.58 kB
build/interactivity/debug.min.js 16.2 kB
build/interactivity/file.min.js 447 B
build/interactivity/image.min.js 1.67 kB
build/interactivity/index.min.js 13 kB
build/interactivity/navigation.min.js 1.17 kB
build/interactivity/query.min.js 740 B
build/interactivity/router.min.js 2.79 kB
build/interactivity/search.min.js 618 B
build/is-shallow-equal/index.min.js 527 B
build/keyboard-shortcuts/index.min.js 1.3 kB
build/keycodes/index.min.js 1.46 kB
build/list-reusable-blocks/index.min.js 2.11 kB
build/list-reusable-blocks/style-rtl.css 851 B
build/list-reusable-blocks/style.css 851 B
build/media-utils/index.min.js 2.92 kB
build/modules/importmap-polyfill.min.js 12.2 kB
build/notices/index.min.js 948 B
build/nux/index.min.js 1.57 kB
build/nux/style-rtl.css 748 B
build/nux/style.css 744 B
build/patterns/index.min.js 6.47 kB
build/patterns/style-rtl.css 595 B
build/patterns/style.css 595 B
build/plugins/index.min.js 1.8 kB
build/preferences-persistence/index.min.js 2.06 kB
build/preferences/index.min.js 2.85 kB
build/preferences/style-rtl.css 710 B
build/preferences/style.css 712 B
build/primitives/index.min.js 975 B
build/priority-queue/index.min.js 1.52 kB
build/private-apis/index.min.js 1 kB
build/react-i18n/index.min.js 623 B
build/react-refresh-entry/index.min.js 9.47 kB
build/react-refresh-runtime/index.min.js 6.78 kB
build/redux-routine/index.min.js 2.7 kB
build/reusable-blocks/index.min.js 2.73 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/rich-text/index.min.js 10 kB
build/router/index.min.js 1.88 kB
build/server-side-render/index.min.js 1.96 kB
build/shortcode/index.min.js 1.39 kB
build/style-engine/index.min.js 2.03 kB
build/token-list/index.min.js 582 B
build/url/index.min.js 3.74 kB
build/vendors/inert-polyfill.min.js 2.48 kB
build/vendors/react-dom.min.js 41.7 kB
build/vendors/react.min.js 4.02 kB
build/viewport/index.min.js 957 B
build/warning/index.min.js 249 B
build/widgets/index.min.js 7.23 kB
build/widgets/style-rtl.css 1.17 kB
build/widgets/style.css 1.17 kB
build/wordcount/index.min.js 1.02 kB

compressed-size-action

@MaggieCabrera MaggieCabrera self-assigned this Apr 1, 2024
@bgardner
Copy link

bgardner commented Apr 1, 2024

I’m here for this. Hope it gets merged!

@MaggieCabrera
Copy link
Contributor Author

@jasmussen I've been exploring this and it seems like we need to have position relative in the frontend for the overlap to work. The editor has it, so it works, but the frontend doesn't. Should it be applied only when negative margins are present?

Editor

Screenshot 2024-04-02 at 09 53 27

Frontend

Screenshot 2024-04-02 at 09 53 20

@jasmussen
Copy link
Contributor

Great work. I see the problem, only the backgrounds of the groups overlaps when there's no position relative applied:
blending together

gif showing the margin being applied, and the difference between editor and frontend

Applying position relative to both, or to the one with the negative margin applied, makes the visual match expectations:

frontend matching editor

Test content
<!-- wp:group {"style":{"spacing":{"padding":{"top":"var:preset|spacing|10","bottom":"var:preset|spacing|10","left":"var:preset|spacing|10","right":"var:preset|spacing|10"}}},"backgroundColor":"accent-4","layout":{"type":"constrained"}} -->
<div class="wp-block-group has-accent-4-background-color has-background" style="padding-top:var(--wp--preset--spacing--10);padding-right:var(--wp--preset--spacing--10);padding-bottom:var(--wp--preset--spacing--10);padding-left:var(--wp--preset--spacing--10)"><!-- wp:paragraph -->
<p>Group 1</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group -->

<!-- wp:group {"style":{"spacing":{"padding":{"top":"var:preset|spacing|10","bottom":"var:preset|spacing|10","left":"var:preset|spacing|10","right":"var:preset|spacing|10"},"margin":{"top":"-30px"}}},"backgroundColor":"accent","layout":{"type":"constrained"}} -->
<div class="wp-block-group has-accent-background-color has-background" style="margin-top:-30px;padding-top:var(--wp--preset--spacing--10);padding-right:var(--wp--preset--spacing--10);padding-bottom:var(--wp--preset--spacing--10);padding-left:var(--wp--preset--spacing--10)"><!-- wp:paragraph -->
<p>Group 2</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group -->

Seems like there are three paths forward here:

  1. Allow the discrepancy.
  2. Apply position: relative; across the board to every block.
  3. Apply position: relative; as soon as you also apply a negative margin.

1 is not ideal. If you're trying to build a pure block theme with no custom CSS, then it's important the frontend matches the editor.

2 would actually bring the frontend closer to the de-facto state of the editor. In the editor, position: relative; is applied to every block in order to afford the block UI to be correctly positioned, so there's an argument to be made that applying it more broadly is addressing that discrepancy. Nevertheless, this is a bit of a bigger change, so perhaps one to judiciously discuss in a separate context.

3 seems like it might be a goldilocks solution that could unblock this feature from landing. It would be contextual to when you're applying a negative margin, which in my quick testing would solve the issues at hand. The caveat would be that it's important to either apply this with a very low level of specificity (i.e. :where), so that if you explicitly assign the position of a Group block to be sticky, this wouldn't conflict with that. That seems to probably be the tricky bit here.

Another option is to just apply the position: relative; by default to every group block, to fix the stacking issue there, but allow the discrepancy for every other block for the time being?

The elephant in the room here is: negative margins are already possible, only in theme.json — so these stacking issues are already possible.

@MaggieCabrera
Copy link
Contributor Author

@jasmussen how would we target just the blocks with negative margins? add a class? That doesn't seem like something we want to maintain. Maybe do it like layout does it? What other blocks may be affected?

I checked this with a columns block too, and the problem doesn't happen because the columns block has display flex applied.

If we wrap the blocks of our test within a stack or a row, the problem disappears because of this:


<!-- wp:group {"layout":{"type":"flex","orientation":"vertical"}} -->
<div class="wp-block-group"><!-- wp:group {"style":{"spacing":{"padding":{"top":"var:preset|spacing|30","bottom":"var:preset|spacing|30","left":"var:preset|spacing|50","right":"var:preset|spacing|50"}}},"backgroundColor":"contrast-2","layout":{"type":"constrained"}} -->
<div class="wp-block-group has-contrast-2-background-color has-background" style="padding-top:var(--wp--preset--spacing--30);padding-right:var(--wp--preset--spacing--50);padding-bottom:var(--wp--preset--spacing--30);padding-left:var(--wp--preset--spacing--50)"><!-- wp:paragraph -->
<p>Group 1</p>
<!-- /wp:paragraph -->

<!-- wp:separator -->
<hr class="wp-block-separator has-alpha-channel-opacity"/>
<!-- /wp:separator -->

<!-- wp:paragraph -->
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sagittis libero posuere enim pellentesque, a convallis mauris imperdiet. Aenean at lectus eu tortor luctus convallis. Aliquam maximus non lectus vel interdum. Aenean ac consectetur metus. Etiam sodales nec eros non efficitur. Nullam libero urna, auctor vel ultrices sit amet, tincidunt vel lacus. Morbi ut ante risus. Morbi vulputate ante vel elit ultrices semper. Morbi ultricies finibus augue in varius. Interdum et malesuada fames ac ante ipsum primis in faucibus. Sed lectus arcu, ultrices vitae feugiat et, dapibus sit amet elit. Nulla in nisi at ipsum ultrices porttitor euismod nec justo.</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group -->

<!-- wp:group {"style":{"spacing":{"padding":{"top":"var:preset|spacing|30","bottom":"var:preset|spacing|30","left":"var:preset|spacing|50","right":"var:preset|spacing|50"},"margin":{"top":"-65px"}}},"backgroundColor":"base-2","layout":{"type":"constrained"}} -->
<div class="wp-block-group has-base-2-background-color has-background" style="margin-top:-65px;padding-top:var(--wp--preset--spacing--30);padding-right:var(--wp--preset--spacing--50);padding-bottom:var(--wp--preset--spacing--30);padding-left:var(--wp--preset--spacing--50)"><!-- wp:paragraph -->
<p>Group 2</p>
<!-- /wp:paragraph -->

<!-- wp:separator -->
<hr class="wp-block-separator has-alpha-channel-opacity"/>
<!-- /wp:separator -->

<!-- wp:paragraph -->
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sagittis libero posuere enim pellentesque, a convallis mauris imperdiet. Aenean at lectus eu tortor luctus convallis. Aliquam maximus non lectus vel interdum. Aenean ac consectetur metus. Etiam sodales nec eros non efficitur. Nullam libero urna, auctor vel ultrices sit amet, tincidunt vel lacus. Morbi ut ante risus. Morbi vulputate ante vel elit ultrices semper. Morbi ultricies finibus augue in varius. Interdum et malesuada fames ac ante ipsum primis in faucibus. Sed lectus arcu, ultrices vitae feugiat et, dapibus sit amet elit. Nulla in nisi at ipsum ultrices porttitor euismod nec justo.</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group --></div>
<!-- /wp:group -->

It's confusing because CSS is doing what it should do, the discrepancy is because we are adding extra CSS rules in the editor. On the other hand, we want to have a solution that works out of the box for users.

@jasmussen
Copy link
Contributor

Reviewing the overall behavior, here's a GIF, description to follow:

behavior test

  • Two colored groups in succession.
  • Testing the margin control in the inspector to adjust the top margin of the bottommost group.
  • Clicking and dragging inside the input as the shortcut for quick increments/decrements.
  • Selecting each group to bring them to the foreground when selected.
  • Notably, selecting a block inside a group still keeps the parent in the foreground (pushed the has-child-selected addition to fix that).
  • Selecting in the list view allows selecting fully obscured blocks.
  • Using arrowkeys still lets you select each block individually.

This is where past efforts stalled: the fact that you can obscure blocks by applying unfortunate negative margins. However, with a few guard-rails in place which I'll get to, I think this could move forward:

  • This is already possible in theme.json. It's out there, so the limitation in the UI is artificial.
  • The "bring to front" behavior added in this PR works intuitively for the canvas, and for the list view, even when child-blocks of an obscured parent block is selected.
  • This has been a highly requested feature, that expands the range of expression.

The easy guardrail we can add, is to adjust the shift+arrow-keys and click+drag in the range field, so it only works for positive values. Meaning, you'd have to type in a negative value manually. It's not clear that has to happen in this PR, or even initially, it could be a guard rail that gets explored if the overlapping issue becomes a problem.

@jasmussen
Copy link
Contributor

how would we target just the blocks with negative margins? add a class?

Yeah that's the tricky issue. Initially my instinct was to just output position: relative; inline, next to the negative margin, like so:

margin-top:-65px; position: relative; [...]

The problem with that is if you also have position sticky applied on the group block, then the inline CSS wins the specificity battle:

Screenshot 2024-04-02 at 11 42 19

We can make sticky win that battle using an !important, but that's less ideal.

I wonder: since Sticky is currently a group-block-only feature, and that's the primary thing that's affected, should we simply add position relative by default to all groups? Or would that make this "default" value misleading?
position dropdown

Another option is just position: relative on every block, but with low specificity. Or to, as mentioned, allow this discrepancy to happen.

Let me try one other idea in a codepen.

@MaggieCabrera
Copy link
Contributor Author

I think the first thing here is to figure out if other blocks besides group are affected by this. Let me look into that. Like I said, Columns block is not affected, and group when it's set to stack or row isn't either.

@MaggieCabrera
Copy link
Contributor Author

I think the first thing here is to figure out if other blocks besides group are affected by this. Let me look into that. Like I said, Columns block is not affected, and group when it's set to stack or row isn't either.

Another option is to only apply the position relative if the has-background class is present

@jasmussen
Copy link
Contributor

Any block with margin is affected. Here are two paragraphs with backgrounds applied:
paragraphs

I think the question is how/how much we should "solve" it. I'm still looking at some options, and finding that positions sticky, absolute, and relative, they actually all fix the overlapping issue. The problem occurs only with position static. From a quick test pen, position: static:

static

Position: sticky
sticky

Position: relative

relative

Of course in the right context, sticky will scroll with you down the page, as intended, that's less important. Let me keep tinkering a bit.

@jasmussen
Copy link
Contributor

Explorations yielded no smart solutions. Here's where we are:

  • CSS is weird. When there's no position relative, then backgrounds stack but text inside blend together.
  • If we add proper guardrails — i.e. having to manually type in a minus in the margin input, then this to me feels properly shielded from accidental input.
  • A quick fix for the most common use cases would be to simply apply position: relative; to the Group block, which will be overridden by the sticky property if used. Paragraphs can still blend, but so be it.

I'd be happy with the above. Curious what you think, @bgardner!

@annezazu
Copy link
Contributor

annezazu commented Apr 2, 2024

Want to tag in @WordPress/outreach for awareness and feedback. This has just been such a long requested feature and it would be great to get some early thoughts as this gets underway.

@markhowellsmead
Copy link

Adding complex rules like position or zindex using inline CSS is already causing notable problems in several instances, given that inline rules are notoriously difficult to override through theme/plugin CSS. (#40159)

I can definitely see a use for adding layering controls (i.e. zindex) for more complex layouts—e.g. overlapping sticky elements—and I think this should have the priority, so that this logic can then be applied not just to sticky elements but also for use when working with negative margins. I believe that negative margins are just a single aspect of layout tools which allow overlapping elements to be managed in the editor. That may be the better focus, instead of adding a solution for this one requirement now and then having to refactor it down the line.

@jasmussen
Copy link
Contributor

Adding complex rules like position or zindex using inline CSS is already causing notable problems in several instances, given that inline rules are notoriously difficult to override through theme/plugin CSS.

I'd tend to agree at a high level, and this does suggest no new rules on the frontend for blocks as a whole.

However @markhowellsmead would you be opposed to adding position: relative; to the group block itself, always? IMO it seems to almost be implied by being a group: it groups things, so any elements inside should be relative to that group. It would solve 80% of oddities that can occur.

@markhowellsmead
Copy link

markhowellsmead commented Apr 3, 2024

@jasmussen I have added that rule to the group block from time to time in themes I've built for clients and in general terms, this hasn't lead to any major problems. However, developers 100% need to be able to override it, so it either needs to be added with a low specificity using :where, or through an additional semantic class name: in the best-case scenario, only when a negative margin is in use. Off the top of my head, I'm not sure how or if this has a knock-on effect for the new CSS grid feature on the group block.

@jasmussen
Copy link
Contributor

This would indeed be added only to the Group variation of the block, and not to Row, Stack or Grid, and yes we could use where to minimize the specificity.

That seems the path forward then, and then either here or as a followup, any constraints to the number control input that puts 0 as the floor for the "drag to increment/decrement" affordance. Perhaps that should be written up as a separate issue, what do you think @MaggieCabrera? It's technically unrelated to this PR, and is mostly a guardrail that benefits this.

@MaggieCabrera
Copy link
Contributor Author

This would indeed be added only to the Group variation of the block, and not to Row, Stack or Grid, and yes we could use where to minimize the specificity.

That seems the path forward then, and then either here or as a followup, any constraints to the number control input that puts 0 as the floor for the "drag to increment/decrement" affordance. Perhaps that should be written up as a separate issue, what do you think @MaggieCabrera? It's technically unrelated to this PR, and is mostly a guardrail that benefits this.

So what I understand is:

  • We change the position relative to affect only group blocks (not row, stack or grid), using :where.
  • Change the dragging to negative numbers on a follow up
  • Update the visualizer to show the negative margin, also on a separate PR

That sounds good to me.

In general I think with the CSS change this PR would be ready to review and test

@jasmussen
Copy link
Contributor

Yep, that sounds good to me 👍 👍 (the editor only CSS to sort out the stacking, we keep as is)

Hopefully other folks pinged on this PR have a chance to chime in as well, one way or the other.

@colorful-tones
Copy link
Member

colorful-tones commented Apr 3, 2024

I wonder what the challenges or side-effects may be if we consider using a semantic class for this implementation. Example: .wp-position—-relative.

Obviously, that is introducing a whole new class naming convention (.wp-) and likely cause further debate.

I’m battling some insomnia and I’m likely (improperly) conflating this issue with the precarious predicament that has been ongoing with .has-background in #43110.

Essentially, I’m just worried in how we introduce the position: relative so as to try and avoid a future backwards-compatibility/deprecation challenge for Group blocks. However, I trust that @MaggieCabrera, @jasmussen and @markhowellsmead are acutely aware of this in their existing considerations. ❤️

I’m mostly just thinking out loud and should probably try to sleep. 🛌

@MaggieCabrera
Copy link
Contributor Author

So far this looks like it's working as intended for group block now but other blocks are not working as intended, mainly due to the need of position relative as well on them. This is a test adding a columns block:

Editor:

Screenshot 2024-04-03 at 10 38 09

Frontend:

Screenshot 2024-04-03 at 10 38 20

@MaggieCabrera
Copy link
Contributor Author

I wonder what the challenges or side-effects may be if we consider using a semantic class for this implementation. Example: ʼ.wp-position—-relativeʼ.

Obviously, that is introducing a whole new class naming convention (ʼ.wp-ʼ) and likely cause further debate.

I’m battling some insomnia and I’m likely (improperly) conflating this issue with the precarious predicament that has been ongoing with ‘.has-background‘ in #43110.

Essentially, I’m just worried in how we introduce the ʼposition: relativeʼ so as to try and avoid a future backwards-compatibility/deprecation challenge for Group blocks. However, I trust that @MaggieCabrera, @jasmussen and @markhowellsmead are acutely aware of this in their existing considerations. ❤️

I’m mostly just thinking out loud and should probably try to sleep. 🛌

adding a class is probably worse in terms of thinking of backwards compatibility, so if we can avoid that... The current CSS that we have in this PR can be removed in the future if we find a better solution and right now it has the lowest specificity possible

@markhowellsmead
Copy link

I strongly believe that the use of semantic class names for various purposes is a better way to go than direct values placed on elements, but I also recognise that there are cases where values set in the editor have to be placed inline on some elements.

There are a lot of discussions going on around the CSS implementation: a lot of them were summarised under #54033 by @cbirdsong. I also discussed the implementation a couple of years ago at #40159 (comment) and other references I could find are at #41230 and #38719.

@colorful-tones
Copy link
Member

Also, I’ve not read through the entire #32644, but it would be neat to see a follow-up PR that uses List View to allow users to drag and drop nested inner blocks with negative margin values and have it update their z-index values accordingly? 🤔

@markhowellsmead
Copy link

it would be neat to see a follow-up PR that uses List View to allow users to drag and drop nested inner blocks with negative margin values and have it update their z-index values accordingly? 🤔

I don't think that zindex can be set automatically; there are use-cases for blocks in sequential sequences which overlap their predecessors and successive elements.

@markhowellsmead
Copy link

Additional thought on this: it'd be very helpful if the control values/settings could be filterable in the editor, so that theme and plugin devs can block negative values from being set in bespoke cases. We theme and plugin developers are in dire need of more overridability and so this would be a perfect opportunity to add some.

@jasmussen
Copy link
Contributor

All good thoughts! I do want to pull this a little bit back to the PR at hand here, because it's prompted by a very vocal desire to allow negative values in the margin control. What is the smallest possible PR we can land, where we trust any knock-on effects surfaced we can fix in followups can be addressed? IMO, it's this PR, which allows negative values and applies a very low-specificity position: relative; on the group block. What do you think?

Copy link
Contributor

@draganescu draganescu left a comment

Choose a reason for hiding this comment

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

I've manually tested the drag and drop on various grouped blocks with negative margins. This PR doesn't really break it, but it does make it so that drop only appends to the block that has the higher z-index.

I have also managed to place an image block behind a quote block and then I was unable to select the image ...

@scruffian scruffian merged commit aa5cdae into trunk Apr 22, 2024
63 checks passed
@scruffian scruffian deleted the try-negative-margins branch April 22, 2024 15:45
@github-actions github-actions bot added this to the Gutenberg 18.3 milestone Apr 22, 2024
@mirka
Copy link
Member

mirka commented Apr 22, 2024

👋 I noticed that a change to BoxControl was merged with a changelog entry that looks wrong, and has a breaking change that is seemingly unintentional/unnecessary.

Specifically, this change breaks the inputProps prop. And it seems like we could've just passed inputProps={ { min: -Infinity } } without changing the code in BoxControl? I'm not sure I understand the motivation, but we at least need to revert the breaking change part.

@MaggieCabrera
Copy link
Contributor Author

👋 I noticed that a change to BoxControl was merged with a changelog entry that looks wrong, and has a breaking change that is seemingly unintentional/unnecessary.

Specifically, this change breaks the inputProps prop. And it seems like we could've just passed inputProps={ { min: -Infinity } } without changing the code in BoxControl? I'm not sure I understand the motivation, but we at least need to revert the breaking change part.

Hey! I don't know what's broken! Can you please explain?

I did make the revert you are asking, your solution is much more simpler than what I was attempting, but I was basically trying to do the same thing. If you could review and help me with the PR description, since I don't know what we broke in the first place (the component is working in trunk for me): #60984

@millertchris
Copy link

Hey Folks — do we know when this might make it into core?

@bph
Copy link
Contributor

bph commented Jun 6, 2024

Yes. WordPress 6.6 is scheduled to be released July 26, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json Needs Accessibility Feedback Need input from accessibility [Type] Enhancement A suggestion for improvement.
Projects
Development

Successfully merging this pull request may close these issues.

Negative margin in dimension controls