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

Use blockLabel for BlockTitle component #23847

Merged
merged 6 commits into from
Aug 13, 2020

Conversation

noahtallen
Copy link
Member

Description

Changes the BlockTitle component to use the block label instead of just the title. (Note that the label will fall back to the title if no label is set.)

Fixes #23463

How has this been tested?

Locally, in edit-site. You can verify the change by looking for a computed label in the block breadcrumb.

Screenshots

Screen Shot 2020-07-09 at 1 14 37 PM

Types of changes

Enhancement

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@github-actions
Copy link

github-actions bot commented Jul 9, 2020

Size Change: +77 B (0%)

Total Size: 1.16 MB

Filename Size Change
build/block-editor/index.js 125 kB +77 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.67 kB 0 B
build/api-fetch/index.js 3.44 kB 0 B
build/autop/index.js 2.82 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/index.js 7.96 kB 0 B
build/block-directory/style-rtl.css 953 B 0 B
build/block-directory/style.css 952 B 0 B
build/block-editor/style-rtl.css 10.6 kB 0 B
build/block-editor/style.css 10.6 kB 0 B
build/block-library/editor-rtl.css 8.36 kB 0 B
build/block-library/editor.css 8.36 kB 0 B
build/block-library/index.js 132 kB 0 B
build/block-library/style-rtl.css 7.49 kB 0 B
build/block-library/style.css 7.49 kB 0 B
build/block-library/theme-rtl.css 729 B 0 B
build/block-library/theme.css 730 B 0 B
build/block-serialization-default-parser/index.js 1.88 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/blocks/index.js 48.4 kB 0 B
build/components/index.js 200 kB 0 B
build/components/style-rtl.css 15.7 kB 0 B
build/components/style.css 15.7 kB 0 B
build/compose/index.js 9.68 kB 0 B
build/core-data/index.js 11.8 kB 0 B
build/data-controls/index.js 1.29 kB 0 B
build/data/index.js 8.56 kB 0 B
build/date/index.js 5.38 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 3.23 kB 0 B
build/edit-navigation/index.js 10.9 kB 0 B
build/edit-navigation/style-rtl.css 1.08 kB 0 B
build/edit-navigation/style.css 1.08 kB 0 B
build/edit-post/index.js 304 kB 0 B
build/edit-post/style-rtl.css 5.63 kB 0 B
build/edit-post/style.css 5.63 kB 0 B
build/edit-site/index.js 17 kB 0 B
build/edit-site/style-rtl.css 3.06 kB 0 B
build/edit-site/style.css 3.06 kB 0 B
build/edit-widgets/index.js 11.7 kB 0 B
build/edit-widgets/style-rtl.css 2.45 kB 0 B
build/edit-widgets/style.css 2.45 kB 0 B
build/editor/editor-styles-rtl.css 537 B 0 B
build/editor/editor-styles.css 539 B 0 B
build/editor/index.js 45.3 kB 0 B
build/editor/style-rtl.css 3.8 kB 0 B
build/editor/style.css 3.79 kB 0 B
build/element/index.js 4.65 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/index.js 7.71 kB 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/hooks/index.js 2.13 kB 0 B
build/html-entities/index.js 621 B 0 B
build/i18n/index.js 3.56 kB 0 B
build/is-shallow-equal/index.js 711 B 0 B
build/keyboard-shortcuts/index.js 2.52 kB 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/index.js 3.12 kB 0 B
build/list-reusable-blocks/style-rtl.css 476 B 0 B
build/list-reusable-blocks/style.css 476 B 0 B
build/media-utils/index.js 5.33 kB 0 B
build/notices/index.js 1.79 kB 0 B
build/nux/index.js 3.4 kB 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/plugins/index.js 2.56 kB 0 B
build/primitives/index.js 1.41 kB 0 B
build/priority-queue/index.js 789 B 0 B
build/redux-routine/index.js 2.85 kB 0 B
build/rich-text/index.js 13.9 kB 0 B
build/server-side-render/index.js 2.71 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.27 kB 0 B
build/url/index.js 4.06 kB 0 B
build/viewport/index.js 1.85 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.17 kB 0 B

compressed-size-action

@epiqueras
Copy link
Contributor

The block title is used in a lot of places. Have you checked that it makes sense to swap in the label everywhere?

cc @youknowriad

@noahtallen
Copy link
Member Author

noahtallen commented Jul 10, 2020

Searching through the repo, I see the component is used in fewer places than I expected:

  • TableOfContentsItem in document-outline. This is fine because template part doesn't show up in the outline, but it would be good to show "header" there:

Screen Shot 2020-07-09 at 6 23 24 PM

  • BlockSelectionButton in block-list. This is used for selection mode and it looks good there:

Screen Shot 2020-07-09 at 6 24 31 PM

  • BlockBreadcrumb for the breadcrumb. This is the goal of the PR, and it also works well:

Screen Shot 2020-07-09 at 1 14 37 PM

The only concern I'd have is if other blocks would not want their display name/label used in these UI. But I'm not sure what the point of the label is if it wouldn't be used in these cases 🤔

@epiqueras
Copy link
Contributor

Thanks for this. I think the change makes sense.

Let's see what Riad thinks.

@mtias
Copy link
Member

mtias commented Jul 10, 2020

I think this could be a bit challenging applied widely. For example, it affects the navigation menu in ways that may not be desirable:

image

image

While the sidebar inspector remains as:

image

@Copons
Copy link
Contributor

Copons commented Jul 13, 2020

I think this could be a bit challenging applied widely. For example, it affects the navigation menu in ways that may not be desirable:

Document > Group > Header > Navigation > Some Draft With a Long Long Title > Ocean

I agree that the breadcrumb there would become unusable.

Back when the block label was introduced, there was a discussion about optionally displaying the block name as well, which was shelved for overcomplicating things.
Maybe this is a good use case for that? 🤔

@noahtallen
Copy link
Member Author

If that's the case, I'm not sure what the best solution is here. 🤔 Thinking through some options & ideas:

Don't we want to use the nav link's label in the breadcrumb for the same reason we want the template part's label there?

In prod it looks like this:
> Document > Group > Header > Navigation > Link > Link

With plain label it looks like this:
> Document > Group > Header > Navigation > Some Draft With a Long Long Title > Ocean

What if we updated the label to be like this
> Document > Group > Header > Navigation > Link (Some Draft With a Long Long Title) > Link (Ocean)

or
> Document > Group > Header > Navigation > Link - Some Draft With a Long Long Title > Link - Ocean

If we don't do that, it sounds like the label is not a good fit for the breadcrumb, in which case we either have to invent a new API (which doesn't seem like a good idea to me). Or add more settings to the label API in order to use it in some places for some blocks, but not for others

While the sidebar inspector remains as:

We could also change the sidebar inspector to use the block label. I'm not sure we want to do that 🤔

But at the same time, I don't search "ocean" or "header" in the block inserter, I search "link" and "template part" (so the proper block title is still needed in some cases)

cc @talldan if you have ideas :)

@epiqueras
Copy link
Contributor

Link (Some Draft With a Lo...) with truncation seems like a good choice.

@noahtallen
Copy link
Member Author

A related question is do we want that to be the raw label in general, or do we want to make the BlockTitle component use ${ blockTitle } (${ truncate( blockLabel ) })

@epiqueras
Copy link
Contributor

The latter for flexibility I think.

@noahtallen
Copy link
Member Author

Screen Shot 2020-07-13 at 3 27 20 PM

@epiqueras
Copy link
Contributor

@jasmussen @MichaelArestad @shaunandrews

@epiqueras
Copy link
Contributor

@pablohoneyhoney

@epiqueras epiqueras added the Needs Design Feedback Needs general design feedback. label Jul 13, 2020
@paaljoachim
Copy link
Contributor

Reading through this PR I think it is a very good idea using labels in the bottom breadcrumbs area. Long labels could be truncated, as we do not need to know all the text contained in the label.
@mapk - Mark what do you think of this PR?

@talldan
Copy link
Contributor

talldan commented Jul 14, 2020

Link (Some Draft With a Lo...) with truncation seems like a good choice.

@noahtallen This suggestion from @epiqueras makes sense, but good to get more designer eyes on this.

As part of that we should make sure that screenreaders don't end up with a label that only has partial words from the text truncation (like the one quoted above).

Let's make sure a round of accessibility testing happens on the changes.

@mapk
Copy link
Contributor

mapk commented Jul 14, 2020

I thought at one point we were possibly getting rid of the breadcrumbs? Maybe that's not the case anymore.

Of the options listed here, I do prefer the parenthesis. It provides much more clarity beyond the typical block type AND the parenthesis provide a better visual indication of a label than the - dash. I also support the truncation of the text in the parenthesis too. 👍

Another possible route is using colons.

Document > Group > Header > Navigation > Link: Some Draft Wi... > Link: Ocean

@noahtallen
Copy link
Member Author

we were possibly getting rid of the breadcrumbs

At least, in FSE, it is currently one of the few indicators of what you're editing. That's a broader problem, but it is useful in that context right now

I also support the truncation of the text in the parenthesis too.

I'm happy to use any separator we want to go with. How many characters would we like to truncate to?

@noahtallen
Copy link
Member Author

cc @shaunandrews @MichaelArestad I'd like to move forward with this issue, but I think I'm still confused which direction to go.

It sounds like we could use the current approach of the PR, which definitely solves the original "problem". Or we could go with the "tooltip" method. I think I prefer the current approach, but it really comes down to:

Is a user going to expect to see "header" or "template part"?

In my mind, many end-users might expect "header", but maybe theme devs would expect "template part".

@paaljoachim
Copy link
Contributor

Could we have a "template part: header"?

@noahtallen
Copy link
Member Author

yeah, that should be working in the current code on this branch: #23847 (comment)

@paaljoachim
Copy link
Contributor

A tooltip is harder to discover. As it requires the user to hover the object that shows the tooltip.
It is better to show the example "template Part: Header" without having to hover. As I believe using the current approach.
It is helpful to have the bottom breadcrumbs show an instant view of the hierarchy as is seen without any user interaction.

@MichaelArestad
Copy link
Contributor

It is better to show the example "template Part: Header" without having to hover. As I believe using the current approach.

@paaljoachim I'm not sure I agree with that. It's not clear to me that the added label is useful enough to be always visible in the breadcrumbs. My concern lies with clarity. Breadcrumbs are useful for getting an understanding of the current hierarchy and an okay way to navigate to a parent. Does adding that label add clarity? If the issue is around concern of which template part the user is modifying, that's being explored here. So far the proposals are more visible than any change we make to the breadcrumb bar.

Is a user going to expect to see "header" or "template part"?

@noahtallen I don't think either are going to spend much time looking at the breadcrumb bar. I lean toward consistency when looking at problems like this. I would go with the block title to be consistent with the rest of the items in the breadcrumbs. I like the idea of exposing the name or other added identifying information in a tooltip. Yes, it's not always visible, but, in most cases, I don't think it needs to be.

This is not something that has a clear answer to me. Due to the location and visibility of the breadcrumbs bar, we can try either way. If you want to try using the block names there, I think we can probably try that for a bit in master to see how it feels.

@noahtallen
Copy link
Member Author

[template part visibility is] being explored here.

I think the template part visibility issues is compounded by lots of smaller issues. Improving that means improving lots of small things which might include the breadcrumb :)

My concern lies with clarity. Breadcrumbs are useful for getting an understanding of the current hierarchy and an okay way to navigate to a parent. Does adding that label add clarity?

I think that the label does add clarity if the user is using the breadcrumb. "Template Part" is not a concept that many end-users will understand or know about without doing some research or learning. I think anything we can do to help guide that sort of user to understand the concept of template part better would be very nice.

I definitely understand your argument about consistency, and I think that's really important. In my opinion, we could use the label in more places as well to improve consistency (rather than just the title). I think there are likely many dynamic blocks which could benefit from better labels in more places (like the nav items, and probably lots of the other FSE blocks dealing with dynamic values)

If you want to try using the block names there, I think we can probably try that for a bit in master to see how it feels.

I like this idea myself. The code changes here are minimal, so we can easily iterate as needed!

@noahtallen noahtallen force-pushed the try/use-block-label-for-breadcrumb branch from 25878f6 to 1146683 Compare August 12, 2020 22:18
@noahtallen
Copy link
Member Author

Here is a gif of the current UI (don't mind the gibberish titles =))

2020-08-12 15 25 53

@jeyip
Copy link
Contributor

jeyip commented Aug 12, 2020

I might have missed an update in one of the threads, but to clarify, are we supporting special characters? The discussion here seems to imply that they were previously working. I am, however, having trouble rendering them locally. kanji 僕は猫です, ! " # $ % & ' ( ) * + , - . / and other symbols weren't showing up in the block label output.

block label

Everything else works as described in Firefox, Chrome, Edge, Safari, and IE11. 🚀

+1 from me when we resolve our discussion about special characters 🙂

@paaljoachim
Copy link
Contributor

paaljoachim commented Aug 13, 2020

I really like seeing the selected block/object name listed in the breadcrumbs. As it really gives a nice quick overview. I can just quickly glance at the breadcrumbs and right away see where I am in the hierarchy and what is selected.

@Copons
Copy link
Contributor

Copons commented Aug 13, 2020

I might have missed an update in one of the threads, but to clarify, are we supporting special characters? The discussion here seems to imply that they were previously working. I am, however, having trouble rendering them locally. kanji 僕は猫です, ! " # $ % & ' ( ) * + , - . / and other symbols weren't showing up in the block label output.

@jeyip Ah, sorry about that, I was only testing the Lodash truncate function (used in the PR) to see how it performed with various type of characters.
I haven't tried actually using special characters as block labels.
It's weird that nothing shows up though... 🤔

@noahtallen
Copy link
Member Author

I am, however, having trouble rendering them locally.

I didn't really think about it, but ideally they would work. Unless special characters are unsupported by the template part slug/name field in the database. This is probably an issue lower in the stack.... maybe something in the labels?

I'll look into it though!

@noahtallen noahtallen force-pushed the try/use-block-label-for-breadcrumb branch from d7cfc71 to 60cd2e5 Compare August 13, 2020 20:47
@noahtallen
Copy link
Member Author

Screen Shot 2020-08-13 at 1 52 56 PM

The reason that emojis are excluded is because we use cleanForSlug before setting the slug.

Converts Latin-1 Supplement and Latin Extended-A letters to basic Latin
letters. Removes combining diacritical marks. Converts whitespace, periods,
and forward slashes to hyphens. Removes any remaining non-word characters
except hyphens. Converts remaining string to lowercase. It does not account
for octets, HTML entities, or other encoded characters.

@noahtallen
Copy link
Member Author

noahtallen commented Aug 13, 2020

I think it basically needs to be sanitized into something which works as a post slug. (i.e. it's not really a display name.)

@noahtallen
Copy link
Member Author

noahtallen commented Aug 13, 2020

That said, I think we can actually start using the title as the label now. previously we were using the slug, but the title would be able to include those characters, I think.

The title also won't work because it gets cleaned in a similar way. I think we can stick with the current behavior now as it is expected and doesn't change anything.

That said, there has been some discussion about introducing proper "labels" for template parts. (#21161 (review))

@noahtallen
Copy link
Member Author

I'll move forward with merging this. I am happy to address any further feedback in follow-ups!

@noahtallen noahtallen merged commit b44996c into master Aug 13, 2020
@noahtallen noahtallen deleted the try/use-block-label-for-breadcrumb branch August 13, 2020 21:19
@github-actions github-actions bot added this to the Gutenberg 8.8 milestone Aug 13, 2020
@MichaelArestad
Copy link
Contributor

Nice work @noahtallen

@noahtallen
Copy link
Member Author

I should clarify this:

The title also won't work because it gets cleaned in a similar way

This actually isn't true, my test code was just incorrect. But there are still other issues with using the post title as the label that would make it fit for a follow-up PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Design Feedback Needs general design feedback. [Package] Block editor /packages/block-editor [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Breadcrumb doesn't show the display name of blocks like "Template Part"