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

List View: Use heading content for button label text if available #41855

Merged
merged 14 commits into from Jul 11, 2022

Conversation

andrewserong
Copy link
Contributor

@andrewserong andrewserong commented Jun 22, 2022

What?

Explore conditionally using the Heading block's content as the block button label in the List View, falling back to the block's title if no content is available.

Why?

As discussed in #33583, this could help improve navigating around the List View, and make it feel a little more like working with a document outline.

How?

  • Update the BlockTitle component and useBlockDisplayTitle hook to support passing in a context string that will then be passed along to getBlockLabel.
  • In the Heading block, check for a list-view context string and then conditionally return the block's content as the label.
  • In the List View, pass in list-view as the context to BlockTitle for the block button.

Testing Instructions

  1. Insert a heading block into a post/page
  2. When the heading is empty it should say "Heading" in the list view
  3. When the heading has any content in it, it should use that (truncated) in the list view
  4. In the contextual menu for selecting a block within the editor canvas, it should still say "Remove Heading" and not use the block's content as a label
  5. Other blocks should display in the list view as before

Screenshots or screencast

In the below screengrab, the empty Heading block defaults to using the block name as the label. As the content is updated, the label updates to use the block's content.

2022-06-23 12 17 31

Before After
image image

@andrewserong andrewserong added [Type] Enhancement A suggestion for improvement. [Feature] List View Menu item in the top toolbar to select blocks from a list of links. labels Jun 22, 2022
@andrewserong andrewserong self-assigned this Jun 22, 2022
@github-actions
Copy link

github-actions bot commented Jun 22, 2022

Size Change: +266 B (0%)

Total Size: 1.25 MB

Filename Size Change
build/block-editor/index.min.js 152 kB +98 B (0%)
build/block-editor/style-rtl.css 14.6 kB +69 B (0%)
build/block-editor/style.css 14.6 kB +72 B (0%)
build/block-library/index.min.js 183 kB +27 B (0%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 982 B
build/annotations/index.min.js 2.76 kB
build/api-fetch/index.min.js 2.26 kB
build/autop/index.min.js 2.14 kB
build/blob/index.min.js 475 B
build/block-directory/index.min.js 6.58 kB
build/block-directory/style-rtl.css 990 B
build/block-directory/style.css 991 B
build/block-editor/default-editor-styles-rtl.css 378 B
build/block-editor/default-editor-styles.css 378 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 65 B
build/block-library/blocks/archives/style.css 65 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 103 B
build/block-library/blocks/audio/style.css 103 B
build/block-library/blocks/audio/theme-rtl.css 110 B
build/block-library/blocks/audio/theme.css 110 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 59 B
build/block-library/blocks/avatar/style.css 59 B
build/block-library/blocks/block/editor-rtl.css 161 B
build/block-library/blocks/block/editor.css 161 B
build/block-library/blocks/button/editor-rtl.css 441 B
build/block-library/blocks/button/editor.css 441 B
build/block-library/blocks/button/style-rtl.css 543 B
build/block-library/blocks/button/style.css 543 B
build/block-library/blocks/buttons/editor-rtl.css 292 B
build/block-library/blocks/buttons/editor.css 292 B
build/block-library/blocks/buttons/style-rtl.css 275 B
build/block-library/blocks/buttons/style.css 275 B
build/block-library/blocks/calendar/style-rtl.css 207 B
build/block-library/blocks/calendar/style.css 207 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 79 B
build/block-library/blocks/categories/style.css 79 B
build/block-library/blocks/code/style-rtl.css 103 B
build/block-library/blocks/code/style.css 103 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 187 B
build/block-library/blocks/comment-template/style.css 185 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 95 B
build/block-library/blocks/comments/editor.css 95 B
build/block-library/blocks/cover/editor-rtl.css 615 B
build/block-library/blocks/cover/editor.css 616 B
build/block-library/blocks/cover/style-rtl.css 1.55 kB
build/block-library/blocks/cover/style.css 1.55 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 110 B
build/block-library/blocks/embed/theme.css 110 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 346 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 948 B
build/block-library/blocks/gallery/editor.css 950 B
build/block-library/blocks/gallery/style-rtl.css 1.5 kB
build/block-library/blocks/gallery/style.css 1.49 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 333 B
build/block-library/blocks/group/editor.css 333 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 327 B
build/block-library/blocks/html/editor.css 329 B
build/block-library/blocks/image/editor-rtl.css 738 B
build/block-library/blocks/image/editor.css 737 B
build/block-library/blocks/image/style-rtl.css 524 B
build/block-library/blocks/image/style.css 530 B
build/block-library/blocks/image/theme-rtl.css 110 B
build/block-library/blocks/image/theme.css 110 B
build/block-library/blocks/latest-comments/style-rtl.css 284 B
build/block-library/blocks/latest-comments/style.css 284 B
build/block-library/blocks/latest-posts/editor-rtl.css 199 B
build/block-library/blocks/latest-posts/editor.css 198 B
build/block-library/blocks/latest-posts/style-rtl.css 463 B
build/block-library/blocks/latest-posts/style.css 462 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 493 B
build/block-library/blocks/media-text/style.css 490 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 705 B
build/block-library/blocks/navigation-link/editor.css 703 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 296 B
build/block-library/blocks/navigation-submenu/editor.css 295 B
build/block-library/blocks/navigation-submenu/view.min.js 423 B
build/block-library/blocks/navigation/editor-rtl.css 2.03 kB
build/block-library/blocks/navigation/editor.css 2.04 kB
build/block-library/blocks/navigation/style-rtl.css 1.96 kB
build/block-library/blocks/navigation/style.css 1.95 kB
build/block-library/blocks/navigation/view-modal.min.js 2.78 kB
build/block-library/blocks/navigation/view.min.js 443 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 363 B
build/block-library/blocks/page-list/editor.css 363 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 157 B
build/block-library/blocks/paragraph/editor.css 157 B
build/block-library/blocks/paragraph/style-rtl.css 260 B
build/block-library/blocks/paragraph/style.css 260 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 495 B
build/block-library/blocks/post-comments-form/style.css 495 B
build/block-library/blocks/post-comments/editor-rtl.css 77 B
build/block-library/blocks/post-comments/editor.css 77 B
build/block-library/blocks/post-comments/style-rtl.css 632 B
build/block-library/blocks/post-comments/style.css 630 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 605 B
build/block-library/blocks/post-featured-image/editor.css 605 B
build/block-library/blocks/post-featured-image/style-rtl.css 153 B
build/block-library/blocks/post-featured-image/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 73 B
build/block-library/blocks/post-terms/style.css 73 B
build/block-library/blocks/post-title/style-rtl.css 80 B
build/block-library/blocks/post-title/style.css 80 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 198 B
build/block-library/blocks/pullquote/editor.css 198 B
build/block-library/blocks/pullquote/style-rtl.css 370 B
build/block-library/blocks/pullquote/style.css 370 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 234 B
build/block-library/blocks/query-pagination/style.css 231 B
build/block-library/blocks/query/editor-rtl.css 365 B
build/block-library/blocks/query/editor.css 364 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 385 B
build/block-library/blocks/search/style.css 386 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 233 B
build/block-library/blocks/separator/style.css 233 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 464 B
build/block-library/blocks/shortcode/editor.css 464 B
build/block-library/blocks/site-logo/editor-rtl.css 708 B
build/block-library/blocks/site-logo/editor.css 708 B
build/block-library/blocks/site-logo/style-rtl.css 192 B
build/block-library/blocks/site-logo/style.css 192 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 84 B
build/block-library/blocks/site-title/editor.css 84 B
build/block-library/blocks/social-link/editor-rtl.css 177 B
build/block-library/blocks/social-link/editor.css 177 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.37 kB
build/block-library/blocks/social-links/style.css 1.36 kB
build/block-library/blocks/spacer/editor-rtl.css 322 B
build/block-library/blocks/spacer/editor.css 322 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 494 B
build/block-library/blocks/table/editor.css 494 B
build/block-library/blocks/table/style-rtl.css 611 B
build/block-library/blocks/table/style.css 609 B
build/block-library/blocks/table/theme-rtl.css 175 B
build/block-library/blocks/table/theme.css 175 B
build/block-library/blocks/tag-cloud/style-rtl.css 226 B
build/block-library/blocks/tag-cloud/style.css 227 B
build/block-library/blocks/template-part/editor-rtl.css 149 B
build/block-library/blocks/template-part/editor.css 149 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 87 B
build/block-library/blocks/verse/style.css 87 B
build/block-library/blocks/video/editor-rtl.css 561 B
build/block-library/blocks/video/editor.css 563 B
build/block-library/blocks/video/style-rtl.css 159 B
build/block-library/blocks/video/style.css 159 B
build/block-library/blocks/video/theme-rtl.css 110 B
build/block-library/blocks/video/theme.css 110 B
build/block-library/common-rtl.css 987 B
build/block-library/common.css 984 B
build/block-library/editor-rtl.css 10.2 kB
build/block-library/editor.css 10.2 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 11.5 kB
build/block-library/style.css 11.5 kB
build/block-library/theme-rtl.css 695 B
build/block-library/theme.css 700 B
build/block-serialization-default-parser/index.min.js 1.11 kB
build/block-serialization-spec-parser/index.min.js 2.83 kB
build/blocks/index.min.js 47 kB
build/components/index.min.js 230 kB
build/components/style-rtl.css 14 kB
build/components/style.css 14 kB
build/compose/index.min.js 11.7 kB
build/core-data/index.min.js 14.7 kB
build/customize-widgets/index.min.js 11.2 kB
build/customize-widgets/style-rtl.css 1.4 kB
build/customize-widgets/style.css 1.4 kB
build/data-controls/index.min.js 653 B
build/data/index.min.js 7.95 kB
build/date/index.min.js 32 kB
build/deprecated/index.min.js 507 B
build/dom-ready/index.min.js 324 B
build/dom/index.min.js 4.66 kB
build/edit-navigation/index.min.js 16 kB
build/edit-navigation/style-rtl.css 4.02 kB
build/edit-navigation/style.css 4.03 kB
build/edit-post/classic-rtl.css 546 B
build/edit-post/classic.css 547 B
build/edit-post/index.min.js 30.4 kB
build/edit-post/style-rtl.css 6.97 kB
build/edit-post/style.css 6.97 kB
build/edit-site/index.min.js 52.1 kB
build/edit-site/style-rtl.css 8.23 kB
build/edit-site/style.css 8.21 kB
build/edit-widgets/index.min.js 16.5 kB
build/edit-widgets/style-rtl.css 4.35 kB
build/edit-widgets/style.css 4.35 kB
build/editor/index.min.js 39.4 kB
build/editor/style-rtl.css 3.65 kB
build/editor/style.css 3.65 kB
build/element/index.min.js 4.27 kB
build/escape-html/index.min.js 537 B
build/format-library/index.min.js 6.75 kB
build/format-library/style-rtl.css 571 B
build/format-library/style.css 571 B
build/hooks/index.min.js 1.64 kB
build/html-entities/index.min.js 448 B
build/i18n/index.min.js 3.77 kB
build/is-shallow-equal/index.min.js 527 B
build/keyboard-shortcuts/index.min.js 1.78 kB
build/keycodes/index.min.js 1.38 kB
build/list-reusable-blocks/index.min.js 1.74 kB
build/list-reusable-blocks/style-rtl.css 835 B
build/list-reusable-blocks/style.css 835 B
build/media-utils/index.min.js 2.93 kB
build/notices/index.min.js 953 B
build/nux/index.min.js 2.05 kB
build/nux/style-rtl.css 732 B
build/nux/style.css 728 B
build/plugins/index.min.js 1.94 kB
build/preferences-persistence/index.min.js 2.22 kB
build/preferences/index.min.js 1.3 kB
build/primitives/index.min.js 933 B
build/priority-queue/index.min.js 612 B
build/react-i18n/index.min.js 696 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.69 kB
build/reusable-blocks/index.min.js 2.22 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/rich-text/index.min.js 11.1 kB
build/server-side-render/index.min.js 1.61 kB
build/shortcode/index.min.js 1.53 kB
build/token-list/index.min.js 644 B
build/url/index.min.js 3.61 kB
build/vendors/react-dom.min.js 38.5 kB
build/vendors/react.min.js 4.34 kB
build/viewport/index.min.js 1.08 kB
build/warning/index.min.js 268 B
build/widgets/index.min.js 7.19 kB
build/widgets/style-rtl.css 1.16 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.06 kB

compressed-size-action

@talldan
Copy link
Contributor

talldan commented Jun 22, 2022

There's an existing system for doing this that should make the PR a bit smaller.

You can see how the navigation link block achieves it here - https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/navigation-link/index.js#L25.

@mtias
Copy link
Member

mtias commented Jun 22, 2022

@talldan that reminds me, we should probably unexperimentalize that API :)

@andrewserong
Copy link
Contributor Author

Thanks @talldan, using that function's a great idea! I've updated this PR — I went a little further and added a context param to the BlockTitle and useBlockDisplayTitle so that we can conditionally use the block content only in the list view. Let me know if you don't think this is the right way to handle it, but I thought that could be a neat way to ensure that the block name is still used in other places (such as the Remove button in the block settings dropdown in the editor canvas).

@andrewserong andrewserong marked this pull request as ready for review June 23, 2022 02:36
@andrewserong andrewserong changed the title [WIP] List View: Use heading content for button label text if available List View: Use heading content for button label text if available Jun 23, 2022
@andrewserong andrewserong added the [Block] Heading Affects the Headings Block label Jun 23, 2022
@talldan
Copy link
Contributor

talldan commented Jun 23, 2022

I went a little further and added a context param to the BlockTitle and useBlockDisplayTitle so that we can conditionally use the block content only in the list view.

I wonder if that'll be needed. I think the only other place it'll display is the breadcrumb at the bottom of the screen. I think other blocks that use __experimentalLabel show their label in the breadcrumb.

It might be good to get input from a designer about this part.

@andrewserong
Copy link
Contributor Author

andrewserong commented Jun 23, 2022

I wonder if that'll be needed

Good question, it appears to be used for both the breadcrumb at the bottom of the screen and the Remove button in the dropdown (the settings dropdown uses useBlockDisplayTitle here). With some longer titles it felt a bit odd to me using the content as the label, whereas in the List view it feels a bit clearer to me since it has the Heading icon. Here's how it looks if we don't have the check for list-view context:

image

I'll add a "Needs Design feedback" label.

TL;DR for designers: should we use Heading content as the label just in the list view, or is it also okay in the breadcrumb at the bottom of the screen, and in the remove button in the settings menu? (I'm happy to implement it either way 🙂)

@andrewserong andrewserong added the Needs Design Feedback Needs general design feedback. label Jun 23, 2022
@talldan
Copy link
Contributor

talldan commented Jun 23, 2022

Good question, it appears to be used for both the breadcrumb at the bottom of the screen and the Remove button in the dropdown (the settings dropdown uses useBlockDisplayTitle here).

Hmm, yeah, it doesn't look great in the remove button. There may need to be some more nuance in how this is shown. I think the distinction is in whether the title shows content (like it will for Heading and does for Navigation Link), or whether it represents the semantic name of a block (like it does for variations and the names of template parts / reusable blocks).

@andrewserong
Copy link
Contributor Author

I think the distinction is in whether the title shows content

Ah, so we could potentially use a context value of content instead of list-view?

@talldan
Copy link
Contributor

talldan commented Jun 23, 2022

I think the problem with really specific terms like 'list-view' is that this could grow into a really big list of contexts as different types of UI are introduced, or ideas around this are iterated on.

All in all, I'm not sure this context system is the right solution in the first place. Maybe it should be something like this pseudocode:

getLabels( blockType, attributes ) {
    return {
        // used where there's a short amount of space for the block (e.g. remove block button)
        title: `${ blockType.title } (${ attributes.level })`,
        // used where there's more space (list view, breadcrumbs)
        label: attributes.content,
        // used for aria labels
        accessibility: `${ attributes.level } - ${ attributes.content }`,
    };
}

These outstanding issues are one of the reasons why it hasn't been stabilised yet

@andrewserong
Copy link
Contributor Author

andrewserong commented Jun 23, 2022

These outstanding issues are one of the reasons why it hasn't been stabilised yet

Ah, gotcha. And then it's also potentially tricky if we want different behaviour for different blocks (like in the screenshot of how the Paragraph block might work: #41855 (comment)), which appears to be a strength of the existing API 🤔. If we wind up wanting to proceed with the label in the list view being different from the remove button or breadcrumbs, but it's too fiddly to land on a change to that API, I can always roll this PR back to the initial commit.

Alternately, if it's acceptable that the Remove button also uses the content, then there's a clearer path to a smaller changeset for this PR (just change the __experimentalLabel for the heading block for all visual contexts, and don't mess with the BlockTitle component 🙂).

Thanks again for thinking through the implications, and I'm happy to keep hacking away tomorrow!

@mtias
Copy link
Member

mtias commented Jun 23, 2022

My inclination would be to use only on list-view. Not quite sure about breadcrumbs, but I lean towards no.

@andrewserong
Copy link
Contributor Author

Thanks for the feedback! I ran out of time to progress this one today, but I'll revisit next week. I suspect we'll need a little more logic to make sure that long titles truncate comfortably for headings with a custom anchor id in the button label, too, so as a first step, it might be worth us keeping the logic encapsulated to the List View button component for now (with a hard-coded list of blocks we're dealing with similar to my first commit), also so that we can side-step the discussion about the shape of the label API.

That said, do let me know if anyone feels strongly about how it should be implemented, though, and I'll incorporate the feedback when I revisit this next week. Thanks, all! 🙇

@andrewserong
Copy link
Contributor Author

andrewserong commented Jun 28, 2022

I've updated this PR to revert back to the approach of using some hard-coded logic in the block-select-button component, so that we can side-step the problem of the label API for the moment.

I took a look at how to get the truncation to play nicely with the id attribute, and it looks like if we add an HStack wrapper over the title and anchor tag, we can get the truncation to factor in the existence of that pill. As an example, here's a screenshot of the current state of the PR:

image

In the above screenshot, from the highlighted Heading:

  • A long heading that gets truncated to still allow room for the HTML anchor.
  • A long heading that gets truncated.
  • A long heading that gets truncated and is locked (shows how it sits with a lock icon)
  • A reusable block that gets truncated (no change here, just demonstrating)

In each of the above examples, space is effectively "reserved" for the lock icon via the max width settings. If the lock is removed on that particular heading, then the whole List View returns to the default width of 350px.

To achieve the above, I've added a max-width of 225px to the wrapper containing the title + anchor id, which appears to be the maximum width before the long titles start to extend over the minimum width of the List View container (350px) — there might be a better width to go with (either a little less or a little more), but at least in my testing today, it seemed to be a kind of sweet spot between too narrow, or letting long headings stretch out the list view to be a bit too wide. Very happy for feedback or ideas on an ideal max width.

The PR probably still needs a little bit of tidying, but happy to try implementing any other ideas. I think the additional HStack with the max-width should help us with the Paragraph block follow-up, too, where we'll try out having grey truncated content text next to the block title (as in this screenshot: #41855 (comment)).

(Note: I think the current change possibly breaks the e2e tests, so I'll look at fixing that up, too)

@talldan
Copy link
Contributor

talldan commented Jun 28, 2022

I've updated this PR to revert back to the approach of using some hard-coded logic in the block-select-button component, so that we can side-step the problem of the label API for the moment.

Sorry to potentially make you u-turn again, but I do think it'd be better to use the existing label API. The context === 'list-view' approach you outlined is a reasonable trade-off right now if there are no other quick wins. At least this means that all the blocks that have a label are implemented similarly, and there's then a basis from which to improve the whole API.

I don't think defining the block names implicitly in list view is the way to go - it wouldn't be something that could easily develop as an API because it limits the feature to core blocks.

@andrewserong
Copy link
Contributor Author

Sorry to potentially make you u-turn again, but I do think it'd be better to use the existing label API. The context === 'list-view' approach you outlined is a reasonable trade-off right now if there are no other quick wins.

Not a bother at all @talldan, it's easy to revert! I'll rework this PR to go with the list-view context approach later on today, and it was still useful figuring out the max-width stuff yesterday, so no wasted effort 🙂

@andrewserong
Copy link
Contributor Author

Just a note for myself, I think the e2e tests are failing because of the additional div so the title span isn't a direct child of the a tag in the list view. I'll probably need to update the logic in: https://github.com/WordPress/gutenberg/blob/trunk/packages/e2e-test-utils/src/get-list-view-blocks.js#L7, and maybe try to make it a little more flexible. I'll look at that tomorrow.

@talldan
Copy link
Contributor

talldan commented Jul 8, 2022

From testing just now - anchor text truncates a little early and doesn't show many characters:

Before:
Screen Shot 2022-07-08 at 2 57 02 pm

After:
Screen Shot 2022-07-08 at 2 57 21 pm

It feels like it should take up any available space. It's probably really tricky to account for all the different situations.

@andrewserong
Copy link
Contributor Author

andrewserong commented Jul 8, 2022

It feels like it should take up any available space. It's probably really tricky to account for all the different situations.

It sure is! There's kind of a delicate balancing act between which things should fill up which available space and when 😆
I can have another go at tweaking that one on Monday (it might be that anchor should be in the same wrapper as title, but not the same wrapper as lock 🤔). Thanks for testing!

Copy link
Contributor

@talldan talldan left a comment

Choose a reason for hiding this comment

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

Works really well! Thanks for sticking with this.

I left an earlier comment about the anchor. If it's an easy fix to improve that before merging, it'd be great. I think it should be possible through some flexboxery.

If it's complicated it might be worth leaving it to a separate PR.

Copy link
Contributor

@jameskoster jameskoster left a comment

Choose a reason for hiding this comment

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

Agreed on the anchor fix, otherwise this seems to be working well! Nice job :)

@andrewserong andrewserong force-pushed the try/use-heading-content-as-label-in-list-view branch from eeb6705 to 26d7799 Compare July 11, 2022 01:29
@andrewserong
Copy link
Contributor Author

andrewserong commented Jul 11, 2022

Thanks for the reviews, folks! It turned out not to be too hard to fix up the anchor, too — I wound up using flex: 1 on the title wrapper so that it isn't quite as greedy at using up the available space, and then used a min() function on the max-width of the anchor so that it never uses up more than 40% of the available space (so that it isn't too greedy with taking up space in narrow titles 😄)

Seems to be working nicely now, so I'll merge this in once tests pass:

Happy to continue tweaking in follow-ups, of course — I'll have a go at the Paragraph block next. Thanks again! 🙇

@andrewserong andrewserong merged commit 9764831 into trunk Jul 11, 2022
@andrewserong andrewserong deleted the try/use-heading-content-as-label-in-list-view branch July 11, 2022 02:09
@github-actions github-actions bot added this to the Gutenberg 13.7 milestone Jul 11, 2022
@mtias
Copy link
Member

mtias commented Jul 11, 2022

We could consider not rendering the anchor label on headings when they match the same name. I also think it might be useful to add a "Copy anchor" to the ellipsis menu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Heading Affects the Headings Block [Feature] List View Menu item in the top toolbar to select blocks from a list of links. Needs Design Feedback Needs general design feedback. 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.

None yet

7 participants