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

Design Tools: Add a Position block support (including sticky), decoupled from layout #46142

Merged
merged 13 commits into from
Jan 10, 2023

Conversation

andrewserong
Copy link
Contributor

@andrewserong andrewserong commented Nov 29, 2022

Related

What?

Fixes: #30121 (note this PR is still a WIP, so the "fixes" label here is simply to associate this PR with the open issue)

This PR is an alternative to #44723, and adds support for sticky position, decoupled from the Layout panel and whether or not a block has layout support. It explores ideas from the discussion in #46032

Why?

Sticky / fixed position will be valuable for sticky headers and footers, and creative pattern applications. However, it is likely to be used infrequently, and needs to be de-emphasised in the UI. This PR is an exploration of the ideas in #46032, to see what the most minimal version of the feature might look like.

How?

Testing Instructions

Note: sticky position will stick to the top of the direct parent block. If at first it appears not to be working, ensure that the parent block is tall enough / has enough content to be scrolled.

  1. Open up the block editor, add a group block and put a paragraph inside it, and give the group block a background color
  2. In the inspector controls, under Position, set the position to Sticky
  3. Scroll down, and the block should stick to the top of the screen
  4. Publish the post or page, and on the site frontend, the block should stick to the top as you scroll, and factor in the height of the logged-in admin bar when it is visible

Screenshots or screencast

The position control situated under Position:

image

A screengrab of selecting the control from the Position panel:

2022-12-02 16 34 11

@andrewserong andrewserong added [Status] In Progress Tracking issues with work in progress [Type] Experimental Experimental feature or API. [Feature] Layout Layout block support, its UI controls, and style output. labels Nov 29, 2022
@andrewserong andrewserong self-assigned this Nov 29, 2022
@github-actions
Copy link

github-actions bot commented Nov 29, 2022

Size Change: +2.4 kB (0%)

Total Size: 1.32 MB

Filename Size Change
build/block-editor/content-rtl.css 2.96 kB +252 B (+9%) 🔍
build/block-editor/content.css 2.96 kB +251 B (+9%) 🔍
build/block-editor/index.min.js 184 kB +2.26 kB (+1%)
build/block-editor/style-rtl.css 14.6 kB -185 B (-1%)
build/block-editor/style.css 14.6 kB -192 B (-1%)
build/block-library/index.min.js 198 kB +399 B (0%)
build/components/index.min.js 203 kB +77 B (0%)
build/components/style-rtl.css 11.6 kB -1 B (0%)
build/components/style.css 11.6 kB -2 B (0%)
build/data/index.min.js 7.69 kB -476 B (-6%)
build/edit-post/index.min.js 34.6 kB -13 B (0%)
build/edit-site/index.min.js 64.9 kB +25 B (0%)
build/edit-site/style-rtl.css 9.08 kB +12 B (0%)
build/edit-site/style.css 9.08 kB +13 B (0%)
build/editor/index.min.js 44.1 kB +7 B (0%)
build/widgets/index.min.js 7.31 kB +35 B (0%)
build/widgets/style-rtl.css 1.18 kB -32 B (-3%)
build/widgets/style.css 1.18 kB -32 B (-3%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 993 B
build/annotations/index.min.js 2.78 kB
build/api-fetch/index.min.js 2.27 kB
build/autop/index.min.js 2.15 kB
build/blob/index.min.js 487 B
build/block-directory/index.min.js 7.16 kB
build/block-directory/style-rtl.css 1.04 kB
build/block-directory/style.css 1.04 kB
build/block-editor/default-editor-styles-rtl.css 403 B
build/block-editor/default-editor-styles.css 403 B
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 138 B
build/block-library/blocks/audio/theme.css 138 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 84 B
build/block-library/blocks/avatar/style.css 84 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 485 B
build/block-library/blocks/button/editor.css 485 B
build/block-library/blocks/button/style-rtl.css 532 B
build/block-library/blocks/button/style.css 532 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 84 B
build/block-library/blocks/categories/editor.css 83 B
build/block-library/blocks/categories/style-rtl.css 100 B
build/block-library/blocks/categories/style.css 100 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 406 B
build/block-library/blocks/columns/style.css 406 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 612 B
build/block-library/blocks/cover/editor.css 613 B
build/block-library/blocks/cover/style-rtl.css 1.57 kB
build/block-library/blocks/cover/style.css 1.56 kB
build/block-library/blocks/embed/editor-rtl.css 293 B
build/block-library/blocks/embed/editor.css 293 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 138 B
build/block-library/blocks/embed/theme.css 138 B
build/block-library/blocks/file/editor-rtl.css 300 B
build/block-library/blocks/file/editor.css 300 B
build/block-library/blocks/file/style-rtl.css 253 B
build/block-library/blocks/file/style.css 254 B
build/block-library/blocks/file/view.min.js 353 B
build/block-library/blocks/freeform/editor-rtl.css 2.44 kB
build/block-library/blocks/freeform/editor.css 2.44 kB
build/block-library/blocks/gallery/editor-rtl.css 984 B
build/block-library/blocks/gallery/editor.css 988 B
build/block-library/blocks/gallery/style-rtl.css 1.55 kB
build/block-library/blocks/gallery/style.css 1.55 kB
build/block-library/blocks/gallery/theme-rtl.css 122 B
build/block-library/blocks/gallery/theme.css 122 B
build/block-library/blocks/group/editor-rtl.css 654 B
build/block-library/blocks/group/editor.css 654 B
build/block-library/blocks/group/style-rtl.css 57 B
build/block-library/blocks/group/style.css 57 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 76 B
build/block-library/blocks/heading/style.css 76 B
build/block-library/blocks/html/editor-rtl.css 332 B
build/block-library/blocks/html/editor.css 333 B
build/block-library/blocks/image/editor-rtl.css 829 B
build/block-library/blocks/image/editor.css 828 B
build/block-library/blocks/image/style-rtl.css 627 B
build/block-library/blocks/image/style.css 630 B
build/block-library/blocks/image/theme-rtl.css 137 B
build/block-library/blocks/image/theme.css 137 B
build/block-library/blocks/latest-comments/style-rtl.css 298 B
build/block-library/blocks/latest-comments/style.css 298 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 266 B
build/block-library/blocks/media-text/editor.css 263 B
build/block-library/blocks/media-text/style-rtl.css 507 B
build/block-library/blocks/media-text/style.css 505 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 716 B
build/block-library/blocks/navigation-link/editor.css 715 B
build/block-library/blocks/navigation-link/style-rtl.css 115 B
build/block-library/blocks/navigation-link/style.css 115 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 299 B
build/block-library/blocks/navigation-submenu/editor.css 299 B
build/block-library/blocks/navigation/editor-rtl.css 2.13 kB
build/block-library/blocks/navigation/editor.css 2.14 kB
build/block-library/blocks/navigation/style-rtl.css 2.22 kB
build/block-library/blocks/navigation/style.css 2.2 kB
build/block-library/blocks/navigation/view-modal.min.js 2.81 kB
build/block-library/blocks/navigation/view.min.js 447 B
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 376 B
build/block-library/blocks/page-list/editor.css 376 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 174 B
build/block-library/blocks/paragraph/editor.css 174 B
build/block-library/blocks/paragraph/style-rtl.css 279 B
build/block-library/blocks/paragraph/style.css 281 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 501 B
build/block-library/blocks/post-comments-form/style.css 501 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 73 B
build/block-library/blocks/post-excerpt/editor.css 73 B
build/block-library/blocks/post-excerpt/style-rtl.css 69 B
build/block-library/blocks/post-excerpt/style.css 69 B
build/block-library/blocks/post-featured-image/editor-rtl.css 586 B
build/block-library/blocks/post-featured-image/editor.css 584 B
build/block-library/blocks/post-featured-image/style-rtl.css 318 B
build/block-library/blocks/post-featured-image/style.css 318 B
build/block-library/blocks/post-navigation-link/style-rtl.css 153 B
build/block-library/blocks/post-navigation-link/style.css 153 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 282 B
build/block-library/blocks/post-template/style.css 282 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-title/style-rtl.css 100 B
build/block-library/blocks/post-title/style.css 100 B
build/block-library/blocks/preformatted/style-rtl.css 103 B
build/block-library/blocks/preformatted/style.css 103 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 326 B
build/block-library/blocks/pullquote/style.css 325 B
build/block-library/blocks/pullquote/theme-rtl.css 167 B
build/block-library/blocks/pullquote/theme.css 167 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 440 B
build/block-library/blocks/query/editor.css 440 B
build/block-library/blocks/quote/style-rtl.css 213 B
build/block-library/blocks/quote/style.css 213 B
build/block-library/blocks/quote/theme-rtl.css 223 B
build/block-library/blocks/quote/theme.css 226 B
build/block-library/blocks/read-more/style-rtl.css 132 B
build/block-library/blocks/read-more/style.css 132 B
build/block-library/blocks/rss/editor-rtl.css 202 B
build/block-library/blocks/rss/editor.css 204 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 165 B
build/block-library/blocks/search/editor.css 165 B
build/block-library/blocks/search/style-rtl.css 409 B
build/block-library/blocks/search/style.css 406 B
build/block-library/blocks/search/theme-rtl.css 114 B
build/block-library/blocks/search/theme.css 114 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 234 B
build/block-library/blocks/separator/style.css 234 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 474 B
build/block-library/blocks/shortcode/editor.css 474 B
build/block-library/blocks/site-logo/editor-rtl.css 490 B
build/block-library/blocks/site-logo/editor.css 490 B
build/block-library/blocks/site-logo/style-rtl.css 203 B
build/block-library/blocks/site-logo/style.css 203 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 674 B
build/block-library/blocks/social-links/editor.css 673 B
build/block-library/blocks/social-links/style-rtl.css 1.4 kB
build/block-library/blocks/social-links/style.css 1.39 kB
build/block-library/blocks/spacer/editor-rtl.css 332 B
build/block-library/blocks/spacer/editor.css 332 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 457 B
build/block-library/blocks/table/editor.css 457 B
build/block-library/blocks/table/style-rtl.css 651 B
build/block-library/blocks/table/style.css 650 B
build/block-library/blocks/table/theme-rtl.css 157 B
build/block-library/blocks/table/theme.css 157 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 404 B
build/block-library/blocks/template-part/editor.css 404 B
build/block-library/blocks/template-part/theme-rtl.css 101 B
build/block-library/blocks/template-part/theme.css 101 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 691 B
build/block-library/blocks/video/editor.css 694 B
build/block-library/blocks/video/style-rtl.css 179 B
build/block-library/blocks/video/style.css 179 B
build/block-library/blocks/video/theme-rtl.css 139 B
build/block-library/blocks/video/theme.css 139 B
build/block-library/classic-rtl.css 162 B
build/block-library/classic.css 162 B
build/block-library/common-rtl.css 1.05 kB
build/block-library/common.css 1.05 kB
build/block-library/editor-elements-rtl.css 75 B
build/block-library/editor-elements.css 75 B
build/block-library/editor-rtl.css 11.7 kB
build/block-library/editor.css 11.7 kB
build/block-library/elements-rtl.css 54 B
build/block-library/elements.css 54 B
build/block-library/reset-rtl.css 478 B
build/block-library/reset.css 478 B
build/block-library/style-rtl.css 12.4 kB
build/block-library/style.css 12.4 kB
build/block-library/theme-rtl.css 698 B
build/block-library/theme.css 703 B
build/block-serialization-default-parser/index.min.js 1.13 kB
build/block-serialization-spec-parser/index.min.js 2.83 kB
build/blocks/index.min.js 50.4 kB
build/compose/index.min.js 12.3 kB
build/core-data/index.min.js 15.9 kB
build/customize-widgets/index.min.js 11.7 kB
build/customize-widgets/style-rtl.css 1.41 kB
build/customize-widgets/style.css 1.41 kB
build/data-controls/index.min.js 663 B
build/date/index.min.js 32.1 kB
build/deprecated/index.min.js 518 B
build/dom-ready/index.min.js 336 B
build/dom/index.min.js 4.71 kB
build/edit-navigation/index.min.js 16.2 kB
build/edit-navigation/style-rtl.css 4.12 kB
build/edit-navigation/style.css 4.13 kB
build/edit-post/classic-rtl.css 571 B
build/edit-post/classic.css 571 B
build/edit-post/style-rtl.css 7.45 kB
build/edit-post/style.css 7.44 kB
build/edit-widgets/index.min.js 16.8 kB
build/edit-widgets/style-rtl.css 4.46 kB
build/edit-widgets/style.css 4.47 kB
build/editor/style-rtl.css 3.69 kB
build/editor/style.css 3.68 kB
build/element/index.min.js 4.93 kB
build/escape-html/index.min.js 548 B
build/experiments/index.min.js 882 B
build/format-library/index.min.js 7.2 kB
build/format-library/style-rtl.css 598 B
build/format-library/style.css 597 B
build/hooks/index.min.js 1.66 kB
build/html-entities/index.min.js 454 B
build/i18n/index.min.js 3.79 kB
build/is-shallow-equal/index.min.js 535 B
build/keyboard-shortcuts/index.min.js 1.79 kB
build/keycodes/index.min.js 1.88 kB
build/list-reusable-blocks/index.min.js 2.13 kB
build/list-reusable-blocks/style-rtl.css 865 B
build/list-reusable-blocks/style.css 865 B
build/media-utils/index.min.js 2.94 kB
build/notices/index.min.js 977 B
build/plugins/index.min.js 1.95 kB
build/preferences-persistence/index.min.js 2.23 kB
build/preferences/index.min.js 1.35 kB
build/primitives/index.min.js 960 B
build/priority-queue/index.min.js 1.59 kB
build/react-i18n/index.min.js 702 B
build/react-refresh-entry/index.min.js 8.44 kB
build/react-refresh-runtime/index.min.js 7.31 kB
build/redux-routine/index.min.js 2.75 kB
build/reusable-blocks/index.min.js 2.26 kB
build/reusable-blocks/style-rtl.css 283 B
build/reusable-blocks/style.css 283 B
build/rich-text/index.min.js 10.8 kB
build/server-side-render/index.min.js 2.09 kB
build/shortcode/index.min.js 1.52 kB
build/style-engine/index.min.js 1.53 kB
build/token-list/index.min.js 650 B
build/url/index.min.js 3.7 kB
build/vendors/inert-polyfill.min.js 2.48 kB
build/vendors/react-dom.min.js 41.8 kB
build/vendors/react.min.js 4.02 kB
build/viewport/index.min.js 1.09 kB
build/warning/index.min.js 280 B
build/wordcount/index.min.js 1.06 kB

compressed-size-action

@andrewserong
Copy link
Contributor Author

Update: based on discussion over in #46032, I thought I'd have a go at using a CustomSelectControl for the UI. Here's how it's currently looking:

2022-12-01-custom-select-control.mp4
@andrewserong
Copy link
Contributor Author

Update: based on discussions over in #46032 (reply in thread), I thought I'd have a go at moving the control over to a separate Position PanelBody. Here's how it's looking now:

2022-12-02 16 34 11

@paaljoachim
Copy link
Contributor

Thanks for working on this feature Andrew!

I am not updated on the discussion but my initial thought is that it would be nice to have this in a toggle.
Position
Description based on toggle selection.
Toggle: Static - Sticky

@jasmussen
Copy link
Contributor

Took this for a spin, it's not bad:

status

Of course if the split tabs experiment isn't enabled, the list can grow a bit long. Is it possible to show this position panel above the "advanced" panel?, i.e. at the end of the stack?

Screenshot 2022-12-02 at 09 22 49

@paaljoachim We did consider a toggle. There's a longer discussion in #46032. One of the hopes here is we can start with an interface that can grow into supporting "Fixed" also.

@jameskoster @mtias could this serve as a starting point, that grows in the future as the position panel potentially becomes a toolspanel, and fixed is added?

@andrewserong andrewserong force-pushed the try/position-support-decoupled-from-layout branch from 8b8cd9c to 338d16b Compare December 5, 2022 05:49
@andrewserong
Copy link
Contributor Author

Is it possible to show this position panel above the "advanced" panel?, i.e. at the end of the stack?

Good catch, and thanks for taking this for a spin!

I've pushed an update (338d16b) that explicitly places the Position panel directly before the Advanced panel in both contexts now 👍

Normal state (appears after Border and before Advanced) With the block inspector tabs experiment active (appears after Layout and before Advanced)
@jasmussen
Copy link
Contributor

Thanks for your patience with this one. Current status:

status

Some thoughts on launchability.

  • The prominence in being attached to just group blocks is pretty low. That makes it pretty safe
  • Sticky is easy, because it works well without any position values.
  • The dropdown can expand, and we have some initial ideas on how to accomplish positioning for "Fixed" in the future.

That makes this a pretty low-footprint feature addition, that could probably only be made simpler by moving it to the "Advanced" panel, postponing the conversation on a "Position" panel.

I think the question then boils down to: is it useful to start with just sticky, or do we need fixed from the get-go after all?

  • If we do need fixed, we need to think through more of the UI.
  • We likely need to create some codepens and explore how the various positional presets can work in a way that's useful.
  • It might even be useful to consider some pattern designs that incorporate fixed positioning, and see how these might work in a branch. https://cloudup.com/ccO8mtV4UVn is one collection of designs where some can probably leverage "fixed".

I personally think we can iterate (land things step by step) so long as we have some confidence in the end result. And so to answer the question: can we land "sticky" as the first step, it might be useful to ask some theme designers: how could you see yourself using it? Would it be useful in a pattern? CC: @WordPress/gutenberg-design @WordPress/theme-team

@annezazu annezazu mentioned this pull request Dec 5, 2022
57 tasks
@andrewserong
Copy link
Contributor Author

Thanks for the recap and thoughts about next steps @jasmussen!

Just a couple more things to add:

  • For fixed, I'll need to do a bit more digging to work out how it'll play with the other elements in the editor (e.g. the layout header of the editor UI), as there'll be some styling conflicts there that the position logic will need to account for.
  • When we set fixed, unlike sticky, the block will lose its width settings (e.g. the block doesn't default to full width). We don't yet have a container-level width control, so we probably need to figure out how adjusting width (or height) will work for fixed position blocks. Fortunately we have the min width support for Group blocks now, so height is probably okay, it's mostly width we'll need to figure out.
  • Whichever way we go, if we decide to begin with this PR and just sticky support to begin with, there are still some issues with the block selection toolbar to resolve, which I'm investigating separately over in Block Selection Toolbar: Support fixed blocks by flipping toolbar when block goes out of view #46085 and hope to get resolved soon 🤞
@andrewserong
Copy link
Contributor Author

I'm wrapping up for the year now. To keep this a working snapshot of the current progress toward a sticky position support, I've given this a rebase and rolled in one of the proposed fixes for the positioning of the block selection toolbar (#46565). While there's still things that need to be tweaked in this PR I'm sure, this should be an accurate representation now of where we're currently at.

Here is a quick demo of the current state, and how to set a Header to be sticky by wrapping it in a Group block that is set at the root of the site, and then switching it over to "sticky":

convert-header-to-sticky.mp4

In the above video:

  • The theme has a Header template part at the root of the site.
  • Select the Header template part, and wrap it in a Group block.
  • Deselect Inner blocks use content width to make the block full width.
  • With the root Group block selected, set the Position to Sticky.
  • It appears to work fairly well so far

Some of the limitations of the current approach:

  • Because sticky is set at the Group block level, this happens outside of the Header template part, so for a site with many different templates, each template would need to have this set, rather than setting it within the Header template part. A possible longer-term solution might be to allow block supports at the template part level, however since this hasn't been done up until now, it might be non-trivial to attempt, and earlier discussion flagged that as a good thing to explore in follow-ups rather than for us to try to do that just yet.
  • The output of the sticky position rules on the site front end factors in the logged in WP header, which works nicely at desktop viewport sizes. However, on mobile, it appears that WP header isn't sticky, so I'm not too sure what the ideal relationship between that header and a block that is set to the top position would be on mobile on a site frontend. This might need a little more digging.
  • While the block toolbar position is improved thanks to the changes pulled in from Block Selection Toolbar: Support fixed and sticky blocks by flipping when there is not enough space above the block #46565, it's still a little jittery, so will need some more digging, too, to come up with an ideal fix there.

I'll pick this up again when I'm back in the new year, but very happy if anyone wants to hack on this PR, branch from it, and/or help out with the related PR to look into block selection toolbar fixes (#46565). No worries if not, I'll happily resume from where I left off once I'm back.

Thanks again for all the feedback and collaboration on this one!

@jameskoster
Copy link
Contributor

Because sticky is set at the Group block level, this happens outside of the Header template part, so for a site with many different templates, each template would need to have this set, rather than setting it within the Header template part

Imo this is fine. It should always be the template that defines stickiness, not the part itself. Otherwise we'd need to design a UI to override the inherent sticky behavior per template, and that starts to get very complicated.

The flexibility can be useful too – on some templates you might want to include additional blocks in the sticky region (sale banner on a product category archive for example).

It's a shame that you have to wrap the template part in a Group as that isn't particularly discoverable, but we can probably solve that separately. It may only require something simple like a "Sticky Group" variation.

@jasmussen
Copy link
Contributor

It's a shame that you have to wrap the template part in a Group as that isn't particularly discoverable, but we can probably solve that separately. It may only require something simple like a "Sticky Group" variation.

Can't it be a group inside the template part?

@jameskoster
Copy link
Contributor

I don't think so, because position: sticky; is always relative to its container. Since the Template Part block outputs a container in the markup the Group wouldn't stick. Crude example:

sticky.mp4
@jasmussen
Copy link
Contributor

Oh, I forgot that. Does the template part always output a container? I may have mentally grouped it with RBs. If yes, then if need be we could bring sticky to the template part itself, if it turns out succesful.

@jameskoster
Copy link
Contributor

It gets tricky if we do that. We learned before that folks expect template part edits to be global, but block properties are local to the parent document. This is why we had to remove background color options on template parts back in the day, it just gets way too confusing when you mix global / local settings.

@jasmussen
Copy link
Contributor

Indeed. I don't think it's the end of the world to wrap the template part in a group.

@jameskoster
Copy link
Contributor

Agreed, especially if we decide that a "Sticky" Group variation makes sense.

@jasmussen
Copy link
Contributor

If we are to have a single interface for sticky and fixed, potentially absolute in the future, and possibly an interface that might even expand beyond just the group, wouldn't that make a "sticky group" variation redundant?

@jameskoster
Copy link
Contributor

I don't think so. I see the variation serving two purposes:

  1. In list view it's easier to identify a sticky region
  2. Adding a sticky region from the inserter is easier and the functionality more discoverable

That said, it doesn't deserve the same prominence as other variations like Row and Stack, especially as Rows and Stacks can be sticky too :) So perhaps it's less of a variation in the traditional sense, and more of a treatment conditionally applied to containers based on position.

Definitely not something to worry about here/now though :)

Copy link
Contributor

@tellthemachines tellthemachines left a comment

Choose a reason for hiding this comment

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

Thanks for the update! Re-testing confirms the Position panel no longer appears on classic themes, even if there's a positioned block in the content.

@andrewserong andrewserong merged commit 9764ee7 into trunk Jan 10, 2023
@andrewserong andrewserong deleted the try/position-support-decoupled-from-layout branch January 10, 2023 23:33
@github-actions github-actions bot added this to the Gutenberg 15.0 milestone Jan 10, 2023
@andrewserong
Copy link
Contributor Author

Thanks for all the reviews and collaboration on this one, everyone!

It positions (excuse the pun) us nicely for future enhancements down the road, and is a solid base from which we can learn more about general usage.

Agreed, I think we've honed in on a good initial set of features for now. I've opened up an issue in #47043 to list follow-up tasks, which should be a little easier to implement now that we've got the foundation in. Feel free to add / edit the list if anyone has other items to add!

@youknowriad
Copy link
Contributor

Hi folks, I missed the introduction of this block support but I have some high-level questions/thoughts about this.

At first, I'd agree that setting a layout and setting a position is two different things but there are strong relations between the two:

  • First thing I want to ask is why this is even an opt-in block support: I guess it's a safe start but setting position seems to be something that all blocks should have access to.
  • I've always considered the alignments we have now: left/right/wide/full as some properties of the "position" definition.
  • I think position depends on layout. In the sense that if the parent layout is "flex", it doesn't make sense to have "alignments" but does it make sense to have "sticky"?
  • Are we going to support "absolute" position at some point, in which case, the "position" object would have a different format (type, x, y).

Are these things you've discussed, what's the current approach and do we have a "plan" to go there?

@jameskoster
Copy link
Contributor

I guess it's a safe start but setting position seems to be something that all blocks should have access to.

I agree, but the 'safe start' element is why we restricted this to Groups for now. It also enables the creation of sticky headers which was one of the driving forces in adding this functionality.

Are we going to support "absolute" position at some point

I believe so, yes. There's lots of back-scroll on the design discussion here. We explored how the control can support other position values (absolute and fixed), then rowed back to the simplest execution for sticky as a starting point.

@andrewserong
Copy link
Contributor Author

Thanks for adding the thoughts and questions @youknowriad!

I agree, but the 'safe start' element is why we restricted this to Groups for now.

Yes, this gives us a much safer level of scope for testing and making further changes — once we've got a stabilised and fully fleshed out suite of features, we could look at switching over to more of an opt-out approach. For the moment, it's been very helpful being deliberate about the opt-in approach, especially with feedback on how sticky works where it's looking likely that we'll hide the sticky controls when the block is in a non-root position (more discussion here: #47230 (comment)).

I think position depends on layout. In the sense that if the parent layout is "flex", it doesn't make sense to have "alignments" but does it make sense to have "sticky"?

There's definitely a close relationship between layout and position, but after previous PRs that explored tying the implementation of position to layout, it became clear that it's helpful for there to be at least some separation between the two, which is how we settled on having it be its own support. It gives us more flexibility in being able to open up controls outside of layout (e.g. relative/absolute) in the future. However, it also doesn't box us into a corner in that we can always roll the controls into the Layout UI in the future if we need to.

But one of the other concerns is that Layout has already grown quite a lot in complexity, so to manage that, it's helpful to have a position support that uses a similar approach, but sits just off to the side.

Are we going to support "absolute" position at some point, in which case, the "position" object would have a different format (type, x, y).

Yes, we considered that and it informed the shape of the position object. Absolute would be represented in the same way as the current sticky position, using top, right, bottom and left properties to match the CSS. So the following shapes are tacitly supported by the current PR:

// sticky (implemented in this PR)
{
  "type": "sticky",
  "top": "0px"
}

// absolute (supported by the structure in this PR, not yet implemented)
{
  "type": "absolute",
  "top": "-15px",
  "left": "-15px"
}

So, we don't yet support relative/absolute output, etc, but the shape of the data will support it.

Are these things you've discussed, what's the current approach and do we have a "plan" to go there?

The plan for the moment is to refine the controls for sticky positioning, with the objective to land it as part of 6.2. The work is being tracked in a follow-up issue of tasks here: #47043

For future exploratory designs, there is discussion over in #46032, with some UI controls being explored further down, too.

In terms of next steps, I think once we're past the 6.2 feature freeze and have sticky positioning polished to the best place we can, it'd be good to start with a design-led approach to how the UI/UX should work for the other kinds of positioning, and then we could look at breaking down the tasks from there. In terms of the data model for attributes / structure of where the code lives, I think we landed on a pretty good approach in this PR that should set us up well for exploring those follow-ups.

@femkreations femkreations added the Needs User Documentation Needs new user documentation label Feb 1, 2023
pento pushed a commit to WordPress/wordpress-develop that referenced this pull request Feb 1, 2023
Adds support for the following CSS properties considered safe for inline CSS:
* `position`
* `top`
* `right`
* `bottom`
* `left`
* `z-index`

References:
* [WordPress/gutenberg#46142 Gutenberg PR 46142].

Follow-up to [54117].

Props andrewserong, mukesh27.
Fixes #57504.

git-svn-id: https://develop.svn.wordpress.org/trunk@55184 602fd350-edb4-49c9-b593-d223f7449a82
markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Feb 1, 2023
Adds support for the following CSS properties considered safe for inline CSS:
* `position`
* `top`
* `right`
* `bottom`
* `left`
* `z-index`

References:
* [WordPress/gutenberg#46142 Gutenberg PR 46142].

Follow-up to [54117].

Props andrewserong, mukesh27.
Fixes #57504.
Built from https://develop.svn.wordpress.org/trunk@55184


git-svn-id: http://core.svn.wordpress.org/trunk@54717 1a063a9b-81f0-0310-95a4-ce76da25c4cd
github-actions bot pushed a commit to platformsh/wordpress-performance that referenced this pull request Feb 1, 2023
Adds support for the following CSS properties considered safe for inline CSS:
* `position`
* `top`
* `right`
* `bottom`
* `left`
* `z-index`

References:
* [WordPress/gutenberg#46142 Gutenberg PR 46142].

Follow-up to [54117].

Props andrewserong, mukesh27.
Fixes #57504.
Built from https://develop.svn.wordpress.org/trunk@55184


git-svn-id: https://core.svn.wordpress.org/trunk@54717 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@bph bph added the Needs Dev Note Requires a developer note for a major WordPress release cycle label Feb 8, 2023
@bph bph mentioned this pull request Feb 8, 2023
47 tasks
@andrewserong
Copy link
Contributor Author

andrewserong commented Feb 14, 2023

Dev notes for 6.2

Note: if there's room, this dev note could potentially be combined with other design tools in a larger dev note. There is a bit of information to convey, though, so alternately it could be its own standalone note. Draft below:


Sticky position block support

WordPress 6.2 adds a new position block support feature, beginning with support for sticky positioning, with the Group block opted-in by default. For themes using the appearanceTools feature in theme.json, the Group block will now be able to be set to "sticky".

The sticky positioning feature follows the CSS behavior for position: sticky which sets an element to stick to its immediate parent (in this case, the block's immediate parent) when the user scrolls down the page. Because it can be a potentially confusing feature to work with, for WordPress 6.2, the positioning controls will only be displayed for Group blocks at the root of the document. In order to create a sticky header in a site template, people building themes or sites can wrap a Header template part in a Group block and set that Group block to "sticky".

This is just the beginning of the position block support feature, and there are ideas for future enhancements, including rolling out sticky to non-root blocks, and improving the UX surrounding building sticky site headers. There is an open issue in the Gutenberg repo to track progress beyond 6.2.

How to add sticky position support to a theme

There are two ways to add support for sticky position to a blocks theme. The simplest is to opt in to the appearanceTools setting, which automatically enables a number of design tools (read more in the developer handbook).

For themes that wish to have more granular control over which UI tools are enabled, the sticky position support can be opted into by setting settings.position.sticky to true in theme.json. For example:

{
	"settings": {
		"position": {
			"sticky": true

How does it work?

When a user sets a block to the sticky position via the drop-down list in the inspector controls, styling rules are output for position: sticky, a top position of 0px (with an offset to account for the logged in admin bar), and a hard-coded z-index value of 10 to ensure that the sticky block sits above other content, while still working correctly in the admin UI. There is not yet support for controlling custom z-index values.

To support the output of these position properties, the safe_style_css filter has been updated in core to support the position, top, right, bottom, left, and z-index properties.

The styling rules are output when the block is rendered, and a classname is-position-sticky is injected into the block markup. For themes wishing to add custom CSS that targets sticky positioned group blocks, this could be achieved by using a selector like .wp-block-group.is-position-sticky.

Why was support for non-root sticky blocks removed in Gutenberg?

While the feature was being developed in the Gutenberg plugin, sticky positioning was initially enabled in all hierarchies of blocks. However, in manual testing, feedback indicated that without additional UI or UX work, it could be confusing for users attempting to create sticky headers if they accidentally set a non-root block to sticky, or for example, a block within a header template part to sticky. The decision was to scale back the feature to just the root blocks for 6.2 to allow more time to explore a good solution for nested blocks. See the discussion in this Gutenberg issue for more context.

Why is positioning not available in global styles?

The position block support has been designed to be set within individual block attributes, as positioning is typically set for an individual block, rather than globally for a particular block type. Therefore, within theme.json the position setting can be used to opt in to using the position support, however a block's position styles cannot be set within global styles. It should instead be set at the individual Group block level, either within a site template, or a page or post.

Further reading


@bph for visibility, here's a draft dev note for the sticky position block support.

@bph bph added has dev note when dev note is done (for upcoming WordPress release) and removed Needs Dev Note Requires a developer note for a major WordPress release cycle labels Feb 28, 2023
@bph
Copy link
Contributor

bph commented Feb 28, 2023

Thank you so much @andrewserong I think this should be a stand-alone dev note, as it's a pretty neat feature. Would you have bandwidth to post it as a draft on the Make Blog to get it into the publishing queue for the field guide?

@andrewserong
Copy link
Contributor Author

Thanks @bph, a stand-alone dev note sounds good to me! Here's a draft on the Make blog for sticky position block support: https://make.wordpress.org/core/?p=103009&preview=1&_ppp=7494b4dec7

@bph
Copy link
Contributor

bph commented Mar 2, 2023

Thank you! @andrewserong

VenusPR added a commit to VenusPR/Wordpress_Richard that referenced this pull request Mar 9, 2023
Adds support for the following CSS properties considered safe for inline CSS:
* `position`
* `top`
* `right`
* `bottom`
* `left`
* `z-index`

References:
* [WordPress/gutenberg#46142 Gutenberg PR 46142].

Follow-up to [54117].

Props andrewserong, mukesh27.
Fixes #57504.
Built from https://develop.svn.wordpress.org/trunk@55184


git-svn-id: http://core.svn.wordpress.org/trunk@54717 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Layout Layout block support, its UI controls, and style output. has dev note when dev note is done (for upcoming WordPress release) Needs User Documentation Needs new user documentation [Type] Experimental Experimental feature or API.
10 participants