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

Sticky Position: Add a "Make sticky" action to the Template Part block #49085

Merged
merged 3 commits into from
Mar 16, 2023

Conversation

andrewserong
Copy link
Contributor

@andrewserong andrewserong commented Mar 15, 2023

What?

Part of #47043

Add a "Make sticky" action to template part blocks, that wraps a Template Part block in a Group block with sticky position settings set. This action is visible in the block settings menu, either in the editor canvas, or in the list view. It is only visible if the Template Part block is at the root level of the document.

This explores an idea from this comment: #47133 (comment)

Why?

To make it easier for a user to set a Template Part block to be sticky — rather than having to know to create a Group block and wrap the Template Part block with it, hopefully this action should be a little easier.

How?

Use a similar approach to the Grouping buttons/actions:

  • Add a menu item that transforms the Template Part block to Group (wrapping it in a Group block).
  • Inject block attributes that correspond to the full width default layout + sticky position and top 0px to stick the block to the top of the viewport when scrolled past the edge of the screen.

Testing Instructions

  1. Test with TT3 theme, which has appearanceTools set to true.
  2. In the site editor, within your Header template part, set a Group block to have a background color, so that it'll be visible when scrolled.
  3. Within the List View, select the Header template part at the root of the document.
  4. In the ellipsis menu, select "Make sticky"
  5. The template part block should now be wrapped in a sticky group block. If you scroll the page, the block should stick to the top of the screen. Note that TT3 includes some site-wide top padding — if you see some space above the Header, update your global styles to set the top padding to 0.
  6. Repeat with the Block Toolbar menu instead of the list view when setting to sticky.
  7. Revert the changes, and update your theme's theme.json file to set settings.appearanceTools to false and reload the site editor. When the Header template part block is at the root of the document, you should not have a "Make sticky" option available in the settings menus.

Screenshots or screencast

The flow for wrapping in a sticky group — note that the Ungroup menu item is a simple way to revert if folks need it:

Make-sticky-button.mp4
List View menu Toolbar menu
image image

@andrewserong andrewserong added the [Block] Template Part Affects the Template Parts Block label Mar 15, 2023
@andrewserong andrewserong self-assigned this Mar 15, 2023
@github-actions
Copy link

github-actions bot commented Mar 15, 2023

Size Change: +342 B (0%)

Total Size: 1.34 MB

Filename Size Change
build/block-editor/index.min.js 197 kB +33 B (0%)
build/blocks/index.min.js 51 kB +18 B (0%)
build/edit-site/index.min.js 65.3 kB +291 B (0%)
ℹ️ 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 483 B
build/block-directory/index.min.js 7.2 kB
build/block-directory/style-rtl.css 1.04 kB
build/block-directory/style.css 1.04 kB
build/block-editor/content-rtl.css 4.11 kB
build/block-editor/content.css 4.1 kB
build/block-editor/default-editor-styles-rtl.css 403 B
build/block-editor/default-editor-styles.css 403 B
build/block-editor/style-rtl.css 14.4 kB
build/block-editor/style.css 14.4 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 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 91 B
build/block-library/blocks/avatar/style.css 91 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 587 B
build/block-library/blocks/button/editor.css 587 B
build/block-library/blocks/button/style-rtl.css 628 B
build/block-library/blocks/button/style.css 627 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.6 kB
build/block-library/blocks/cover/style.css 1.59 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 265 B
build/block-library/blocks/file/style.css 265 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 830 B
build/block-library/blocks/image/editor.css 829 B
build/block-library/blocks/image/style-rtl.css 652 B
build/block-library/blocks/image/style.css 652 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 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 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 401 B
build/block-library/blocks/page-list/editor.css 401 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 71 B
build/block-library/blocks/post-excerpt/editor.css 71 B
build/block-library/blocks/post-excerpt/style-rtl.css 134 B
build/block-library/blocks/post-excerpt/style.css 134 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 322 B
build/block-library/blocks/post-featured-image/style.css 322 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 463 B
build/block-library/blocks/query/editor.css 463 B
build/block-library/blocks/quote/style-rtl.css 222 B
build/block-library/blocks/quote/style.css 222 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 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 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 489 B
build/block-library/blocks/site-logo/editor.css 489 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 433 B
build/block-library/blocks/table/editor.css 433 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 552 B
build/block-library/blocks/video/editor.css 555 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 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 11.6 kB
build/block-library/editor.css 11.6 kB
build/block-library/elements-rtl.css 54 B
build/block-library/elements.css 54 B
build/block-library/index.min.js 201 kB
build/block-library/reset-rtl.css 478 B
build/block-library/reset.css 478 B
build/block-library/style-rtl.css 12.7 kB
build/block-library/style.css 12.7 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/components/index.min.js 208 kB
build/components/style-rtl.css 11.7 kB
build/components/style.css 11.7 kB
build/compose/index.min.js 12.4 kB
build/core-data/index.min.js 16.3 kB
build/customize-widgets/index.min.js 12.2 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/data/index.min.js 8.58 kB
build/date/index.min.js 40.4 kB
build/deprecated/index.min.js 518 B
build/dom-ready/index.min.js 336 B
build/dom/index.min.js 4.72 kB
build/edit-post/classic-rtl.css 571 B
build/edit-post/classic.css 571 B
build/edit-post/index.min.js 34.8 kB
build/edit-post/style-rtl.css 7.55 kB
build/edit-post/style.css 7.54 kB
build/edit-site/style-rtl.css 10.2 kB
build/edit-site/style.css 10.2 kB
build/edit-widgets/index.min.js 17.3 kB
build/edit-widgets/style-rtl.css 4.56 kB
build/edit-widgets/style.css 4.56 kB
build/editor/index.min.js 45.8 kB
build/editor/style-rtl.css 3.54 kB
build/editor/style.css 3.53 kB
build/element/index.min.js 4.95 kB
build/escape-html/index.min.js 548 B
build/format-library/index.min.js 7.26 kB
build/format-library/style-rtl.css 557 B
build/format-library/style.css 556 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.94 kB
build/list-reusable-blocks/index.min.js 2.14 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.99 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.52 kB
build/private-apis/index.min.js 937 B
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 265 B
build/reusable-blocks/style.css 265 B
build/rich-text/index.min.js 11 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.74 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/widgets/index.min.js 7.3 kB
build/widgets/style-rtl.css 1.18 kB
build/widgets/style.css 1.18 kB
build/wordcount/index.min.js 1.06 kB

compressed-size-action

@github-actions
Copy link

github-actions bot commented Mar 15, 2023

Flaky tests detected in 9d9a849.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4422991678
📝 Reported issues:

@andrewserong andrewserong changed the title Sticky Position: Try adding a make sticky action to the Template Part block Sticky Position: Add a "Make sticky" action to the Template Part block Mar 15, 2023
@andrewserong andrewserong added [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi [Type] Enhancement A suggestion for improvement. labels Mar 15, 2023
@andrewserong andrewserong marked this pull request as ready for review March 15, 2023 05:24
@jameskoster
Copy link
Contributor

Thanks for the PR, exciting!

It seems to work well, but I miss some kind of visual feedback/confirmation. This is where I think the Sticky Group variation we've discussed before would be really handy. Even if the Group name just became 'Sticky Group', 'Group (sticky)', or similar, that would help. Maybe it doesn't need to be a variation?

@jameskoster jameskoster requested a review from a team March 15, 2023 10:05
@jasmussen
Copy link
Contributor

Yep indeed — should we have a sticky icon next to the title, when stickied?

@paaljoachim
Copy link
Contributor

paaljoachim commented Mar 15, 2023

Very cool!

From what I noticed in the above video.
Can one only add a sticky template part by right clicking it in List view or are there other easier to see methods?

Copy link
Contributor

@apeatling apeatling left a comment

Choose a reason for hiding this comment

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

This feels natural to me, and worked exactly as described. Nice work!

I would echo @jameskoster's comments above, it could use some sort of indication that it worked otherwise you don't know until you try and scroll. I agree changing the name/label of the template part group block in the list view and on the canvas would be sufficiently indicative. 👍

@andrewserong
Copy link
Contributor Author

Thanks for the feedback, folks! Totally agree that it'd be good to make it clearer that the wrapping Group block is sticky. I've had a go at this over in #49122 — it'll likely need some design feedback to figure out the right presentation for it. I thought creating more granular PRs could be helpful, so that we can iterate on each of the proposed changes in isolation 🙂

Maybe it doesn't need to be a variation?

At this stage, I don't think we need to create a separate variation for the Group block — I think we can get a long way via labelling based on position values, and it will also help ensure that the position support is decoupled from the Group block, which should help for if/when we want to add position support to other blocks in the future.

Can one only add a sticky template part by right clicking it in List view or are there other easier to see methods?

It's also available in the settings menu from the block toolbar within the editor canvas, so the user doesn't need to have the list view open to find this action. It'd also be possible to add an action to the right-hand sidebar, but for now, I think the two sets of block settings menus might be a good fit — it ensures that the action is available, while not making it too prominent. But, happy for feedback on that idea of course!

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.

Code looks good and it's working very well! This is so much easier than hunting around in the sidebar for the relevant control, I almost wish all root blocks could have it (though of course it wouldn't make sense to wrap any block that's not a template part in a Group)

Agree with handling the list view label separately, and

help ensure that the position support is decoupled from the Group block, which should help for if/when we want to add position support to other blocks in the future

can't wait for sticky Headings and Tables of Contents 😼

if (
! isGroupable ||
! canRemove ||
! groupingBlockName ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Til about the concept of a "grouping block"! Does this mean blocks could be grouped with a different container than a Group block?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Theoretically yes, but in practice the groupingBlockName is set up as the Group block when the core blocks are registered here. My understanding is that it's good when dealing with grouping (verb) behaviour to use this abstraction so that (in theory) custom editors that don't use core blocks can still work properly. In practice, I'm not sure how frequently that use case is realised, but for this PR, I thought I'd try to be consistent with the existing grouping logic!

@andrewserong
Copy link
Contributor Author

Yay, thanks for the review @tellthemachines! I'll hold off on merging to wait for designers to let us know if they'd prefer we have the sticky labelling in list view present before landing this one. Good to know this is in decent shape for when we're happy with the labelling situation 😀

@jameskoster
Copy link
Contributor

Since #49122 is already on the way I don't think this PR needs to be blocked.

@andrewserong
Copy link
Contributor Author

Thanks for confirming @jameskoster! With the approving review, I'll merge this in now. Happy to do any follow up if anyone runs into any issues.

@andrewserong andrewserong merged commit cae48d7 into trunk Mar 16, 2023
@andrewserong andrewserong deleted the try/make-sticky-menu-option branch March 16, 2023 23:02
@github-actions github-actions bot added this to the Gutenberg 15.5 milestone Mar 16, 2023
@jasmussen
Copy link
Contributor

Thanks for all the work here. Coming back to this one, in my haste I think I missed the nuance where this wraps the template part in a group. Apologies, this is on me.

But essentially I'm not sure it's the best experience after all, it isn't obvious how to undo this action. But perhaps more importantly, I always saw the sticky property as something we eventually expand to more blocks than the group. In fact the main reason we started with limiting sticky to only the group (correct me if I'm misremembering) wasn't because that was going to remain that way forever, but to limit the surface for a somewhat advanced feature we weren't sure of. I always expected that as we found out how the feature got used, that it would expand to other blocks, like template parts, and simply be available there. In the case of sticky, it seems to have already proven itself hugely valuable with themes, so it seems like instead of adding this group wrapping functionality, we might just add it to the template part itself?

No real harm done here if we need to revisit: there really is no danger in having a group block wrap your template part. But I think it might still be worth it to revisit this flow. What do you think?

@jameskoster
Copy link
Contributor

Applying position directly to the template part always results in a question of whether that property is synced or not. Seeing as every other property is synced, you would likely expect position to be synced as well. But that doesn't feel clear cut to me. You might want the header to be sticky in some templates, but not in others.

If we did want to allow this to by synced globally, then we'd need to come up with a way to override it locally.

I've always come to the conclusion that ultimately it's the responsibility of the parent document to position its constituent blocks. And that we can/should do a better job of communicating the sticky regions in the UI (#49122).

@jasmussen
Copy link
Contributor

I like 49122, especially if we go an icon-route.

Synced globally or locally is a valid conversation to have, one that I do recall coming up for TPs before. But is that solved well with the grouping container? You could put a group inside the template part, make that sticky, if you wanted it synced. I know, there's a bit of a devils advocate tinge to that statement, I don't mean to dismiss your feedback. The thing is, if we do mean to eventually roll out sticky positioning to virtually all blocks, it feels weird that there's a dedicated "make a group and apply sticky" feature just for the template part.

@jameskoster
Copy link
Contributor

I do agree in general, but without a clearer solution for the global / local issue it seems necessary to me.

What we need is a way to override template part / reusable block properties in a local context. Similar to how you can apply overrides to component instances in Figma. Then you could say the Header is sticky by default, but in this one template I am going to override that and make it fixed, or static, or whatever.

I guess this has some overlap with Styles, where you might want to style elements such as links in the Paragraph block at a global level, but override those styles in certain contexts. cc @SaxonF.

You could put a group inside the template part, make that sticky

You can try, but it probably wouldn't work as expected due to the sticky behaviour being local to the direct ancestor.

@jasmussen
Copy link
Contributor

I wouldn't oppose a more global solution. But as far as local, I don't think we should go with this "add a group and set it to sticky" in the mean time. It seems a bit random and temporary, and it makes the menu all the longer and even inconsistent. Again, sorry I didn't catch this sooner.

@jameskoster
Copy link
Contributor

The only short term alternative I can think of would be to add the Position panel to the Template Part block:

Screenshot 2023-03-17 at 13 23 04

But we'd need to decide if it's applied locally or globally, and communicate that to the user.

For some added context we used to have an option to change the background color here, and folks got confused when they added a background color and found that it wasn't applied globally. For that reason I'd lean towards making it a global change. But the trade-off there is that you wouldn't be able to make a template part sticky in some templates and not in others.

Did you have any other ideas? 🤔

@jasmussen
Copy link
Contributor

That was my suggestion. This would be applied locally, right? That way, nothing to communicate since it would always be local here, just like anything that's in the Advanced section. And you'd be able to mix and match.

@andrewserong
Copy link
Contributor Author

andrewserong commented Mar 19, 2023

Thanks for the feedback here folks, just to make sure we're on the same page, would you like me to revert this change? If you'll indulge me, I'd like to advocate for keeping this change, but happy to disagree and commit if you confirm you'd like it removed for now 🙂

Here's some more context on how we arrived at the current state in this PR, and some responses to the discussion so far:

  • Currently the only way a user can make a template part sticky is by wrapping in a Group block — this is not obvious to a user, so it would be good to provide an action that makes it easier for the user to achieve. (A user can't place a sticky group within a template part, because sticky applies to the area of the immediate ancestor)
  • The problem this feature resolves only exists with Template Part blocks because of the discussion surrounding local vs global styling. Any other block we opt in to sticky position will not need these actions (e.g. headings).
  • We already have a couple of other grouping-related actions in the block settings menu for template parts (e.g. Detach blocks from template part), so I thought having an action here would be consistent with those other kinds of grouping actions.
  • The additional menu item will only appear on Template Part blocks, so in terms of cluttering up the settings menu, it only applies to this one block, in case that makes it less of an issue.
  • Adding sticky position support to the template part block was previously explored in this PR: Try adding sticky position support to the template part block #47133 — it wound up not being viable because of the confusion it causes if folks adjust position at the local level for a template part, but it is not applied across templates.
  • Earlier issue where local vs global template part styles was discussed, with the decision to remove styling from the template part block: Style changes made to template parts are only applied to one page #30732

Unfortunately figuring out how to apply styles across all instances of a template part block will be non-trivial. In #47133 where we explored adding the Position panel to the template part block locally, the block attributes are stored in the markup of the parent template and not within the template part itself. We currently don't have a concept of block attributes being stored at the root level of the template part itself, and we would need to figure out where in the database those block attributes would be stored — so I believe figuring out root template part styles that are applied globally will wind up becoming a bit on an API problem. I'm keen to avoid that complexity for now while we come up with pragmatic UI improvements that can ease the UX problems with interacting with the position support.

In the longer-term, I think exploring the globally styled template part block idea is worth pursuing, but since it'll involve API changes, and working out where the block attributes will be serialized, it sounds like an area for more design exploration and technical research rather than something we can immediately jump in and try implementing.

To try to phrase this differently:

If we accept that in the short-term (and say, potentially for the next major WP release) we will not have the ability to set sticky on the template part block itself, and have it apply to all instances of that template part, what things can we do in the UI to make it easier for folks to create sticky headers?

Again, thanks for all the feedback! Happy to put up a revert PR if that's preferred, and have another go at improving the UX here in subsequent PRs 🙂

@SaxonF
Copy link
Contributor

SaxonF commented Mar 20, 2023

The only short term alternative I can think of would be to add the Position panel to the Template Part block:

but it's the responsibility of the document to position its blocks.

I agree with @jameskoster suggestion here, but sticky position should only apply locally.

We should think about the future of patterns where a pattern could be synced across your site, possibly replacing template parts and re-usable blocks. In that future, you should be able to apply/override certain local attributes of patterns. For example, setting the width or changing the colour set of a local instance of a pattern. You shouldn't have to wrap a pattern/template part in a group for every local change.

To change something globally , regardless of what it is, I think we need to start establishing a common pattern so people feel confident in the context they are editing in. For example, a dedicated "edit" button that enters focus mode or changes toolbar title (my page -> my header)

@jameskoster
Copy link
Contributor

jameskoster commented Mar 20, 2023

For example, a dedicated "edit" button that enters focus mode or changes toolbar title (my page -> my header)

I agree. #43608 is relevant to that discussion.

@richtabor
Copy link
Member

If we accept that in the short-term (and say, potentially for the next major WP release) we will not have the ability to set sticky on the template part block itself, and have it apply to all instances of that template part, what things can we do in the UI to make it easier for folks to create sticky headers?

I don't think we should keep this in.

Wrapping the template part in a group for you, and applying position to that group, are the right steps to do this currently, but it's not the right experience we should be optimizing for. I think it'll confuse folks, more than help.

It makes it seem like you can apply the position to the template part, but you really can't. Also, the template part will then be nested, which can further confuse folks — as you loose context of where that template part is now.

This would also introduce inconsistencies on how sticky is applied, when opened up to other blocks perhaps. We don't have design tooling in the block toolbar more menu elsewhere—and I don't think we should perhaps. Those menus are more managerial (copy/duplicate/delete/lock).

@andrewserong
Copy link
Contributor Author

Thanks for all the discussion, feedback and clarity here! I've opened a revert PR over in #49219

Happy to have another go at improving the UX here once we've got a better sense of the next steps we'd like to take.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Template Part Affects the Template Parts Block [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi Needs User Documentation Needs new user documentation [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants