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

Navigation: Allow a label to used for placeholder text #35094

Closed
wants to merge 3 commits into from

Conversation

gwwar
Copy link
Contributor

@gwwar gwwar commented Sep 23, 2021

Changes here allow us to use a label as placeholder text instead of "Select Page". This makes creating navigation patterns more visually interesting and lets users more quickly pick out useful patterns. See related #35063

CleanShot.2021-09-23.at.09.22.39.mp4

Testing Instructions

  • Create a new post or page
  • In the code editor add the following:
<!-- wp:navigation -->
<!-- wp:navigation-link {"label":"About","type":"page","kind":"post-type","isTopLevelLink":true} /-->
<!-- /wp:navigation -->
  • Switch back to the Visual Editor
  • Verify that newly added links still have the correct placeholder text like "Select page"
  • Navigate to the Navigation Editor
  • Add a Page Link
  • Unlink
  • Verify that all attributes have been removed (the same behavior as trunk).

@gwwar gwwar added [Type] Enhancement A suggestion for improvement. [Block] Navigation Affects the Navigation Block labels Sep 23, 2021
@gwwar gwwar self-assigned this Sep 23, 2021
@github-actions
Copy link

github-actions bot commented Sep 23, 2021

Size Change: +181 B (0%)

Total Size: 1.07 MB

Filename Size Change
build/block-library/index.min.js 148 kB +157 B (0%)
build/edit-navigation/index.min.js 15.4 kB +24 B (0%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 931 B
build/admin-manifest/index.min.js 1.09 kB
build/annotations/index.min.js 2.7 kB
build/api-fetch/index.min.js 2.21 kB
build/autop/index.min.js 2.08 kB
build/blob/index.min.js 459 B
build/block-directory/index.min.js 6.2 kB
build/block-directory/style-rtl.css 1.01 kB
build/block-directory/style.css 1.01 kB
build/block-editor/default-editor-styles-rtl.css 378 B
build/block-editor/default-editor-styles.css 378 B
build/block-editor/index.min.js 134 kB
build/block-editor/style-rtl.css 13.9 kB
build/block-editor/style.css 13.9 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 65 B
build/block-library/blocks/archives/style.css 65 B
build/block-library/blocks/audio/editor-rtl.css 58 B
build/block-library/blocks/audio/editor.css 58 B
build/block-library/blocks/audio/style-rtl.css 111 B
build/block-library/blocks/audio/style.css 111 B
build/block-library/blocks/audio/theme-rtl.css 125 B
build/block-library/blocks/audio/theme.css 125 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 474 B
build/block-library/blocks/button/editor.css 474 B
build/block-library/blocks/button/style-rtl.css 600 B
build/block-library/blocks/button/style.css 600 B
build/block-library/blocks/buttons/editor-rtl.css 315 B
build/block-library/blocks/buttons/editor.css 315 B
build/block-library/blocks/buttons/style-rtl.css 370 B
build/block-library/blocks/buttons/style.css 370 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 90 B
build/block-library/blocks/code/style.css 90 B
build/block-library/blocks/code/theme-rtl.css 131 B
build/block-library/blocks/code/theme.css 131 B
build/block-library/blocks/columns/editor-rtl.css 206 B
build/block-library/blocks/columns/editor.css 205 B
build/block-library/blocks/columns/style-rtl.css 497 B
build/block-library/blocks/columns/style.css 496 B
build/block-library/blocks/cover/editor-rtl.css 477 B
build/block-library/blocks/cover/editor.css 480 B
build/block-library/blocks/cover/style-rtl.css 1.17 kB
build/block-library/blocks/cover/style.css 1.17 kB
build/block-library/blocks/embed/editor-rtl.css 488 B
build/block-library/blocks/embed/editor.css 488 B
build/block-library/blocks/embed/style-rtl.css 417 B
build/block-library/blocks/embed/style.css 417 B
build/block-library/blocks/embed/theme-rtl.css 124 B
build/block-library/blocks/embed/theme.css 124 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 255 B
build/block-library/blocks/file/style.css 255 B
build/block-library/blocks/file/view.min.js 322 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 977 B
build/block-library/blocks/gallery/editor.css 982 B
build/block-library/blocks/gallery/style-rtl.css 1.6 kB
build/block-library/blocks/gallery/style.css 1.59 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 159 B
build/block-library/blocks/group/editor.css 159 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 114 B
build/block-library/blocks/heading/style.css 114 B
build/block-library/blocks/home-link/style-rtl.css 247 B
build/block-library/blocks/home-link/style.css 247 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 731 B
build/block-library/blocks/image/editor.css 730 B
build/block-library/blocks/image/style-rtl.css 502 B
build/block-library/blocks/image/style.css 505 B
build/block-library/blocks/image/theme-rtl.css 124 B
build/block-library/blocks/image/theme.css 124 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 137 B
build/block-library/blocks/latest-posts/editor.css 137 B
build/block-library/blocks/latest-posts/style-rtl.css 528 B
build/block-library/blocks/latest-posts/style.css 527 B
build/block-library/blocks/list/style-rtl.css 94 B
build/block-library/blocks/list/style.css 94 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 568 B
build/block-library/blocks/navigation-link/editor.css 570 B
build/block-library/blocks/navigation-link/style-rtl.css 94 B
build/block-library/blocks/navigation-link/style.css 94 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 300 B
build/block-library/blocks/navigation-submenu/editor.css 299 B
build/block-library/blocks/navigation-submenu/style-rtl.css 195 B
build/block-library/blocks/navigation-submenu/style.css 195 B
build/block-library/blocks/navigation-submenu/view.min.js 343 B
build/block-library/blocks/navigation/editor-rtl.css 1.72 kB
build/block-library/blocks/navigation/editor.css 1.72 kB
build/block-library/blocks/navigation/style-rtl.css 1.62 kB
build/block-library/blocks/navigation/style.css 1.61 kB
build/block-library/blocks/navigation/view.min.js 2.74 kB
build/block-library/blocks/nextpage/editor-rtl.css 395 B
build/block-library/blocks/nextpage/editor.css 395 B
build/block-library/blocks/page-list/editor-rtl.css 377 B
build/block-library/blocks/page-list/editor.css 377 B
build/block-library/blocks/page-list/style-rtl.css 198 B
build/block-library/blocks/page-list/style.css 198 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 273 B
build/block-library/blocks/paragraph/style.css 273 B
build/block-library/blocks/post-author/editor-rtl.css 210 B
build/block-library/blocks/post-author/editor.css 210 B
build/block-library/blocks/post-author/style-rtl.css 182 B
build/block-library/blocks/post-author/style.css 181 B
build/block-library/blocks/post-comments-form/style-rtl.css 140 B
build/block-library/blocks/post-comments-form/style.css 140 B
build/block-library/blocks/post-comments/style-rtl.css 360 B
build/block-library/blocks/post-comments/style.css 359 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 396 B
build/block-library/blocks/post-featured-image/editor.css 397 B
build/block-library/blocks/post-featured-image/style-rtl.css 156 B
build/block-library/blocks/post-featured-image/style.css 156 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 391 B
build/block-library/blocks/post-template/style.css 392 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 60 B
build/block-library/blocks/post-title/style.css 60 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 378 B
build/block-library/blocks/pullquote/style.css 378 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 262 B
build/block-library/blocks/query-pagination/editor.css 255 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-title/editor-rtl.css 85 B
build/block-library/blocks/query-title/editor.css 85 B
build/block-library/blocks/query/editor-rtl.css 131 B
build/block-library/blocks/query/editor.css 132 B
build/block-library/blocks/quote/style-rtl.css 187 B
build/block-library/blocks/quote/style.css 187 B
build/block-library/blocks/quote/theme-rtl.css 220 B
build/block-library/blocks/quote/theme.css 222 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 374 B
build/block-library/blocks/search/style.css 375 B
build/block-library/blocks/search/theme-rtl.css 64 B
build/block-library/blocks/search/theme.css 64 B
build/block-library/blocks/separator/editor-rtl.css 99 B
build/block-library/blocks/separator/editor.css 99 B
build/block-library/blocks/separator/style-rtl.css 250 B
build/block-library/blocks/separator/style.css 250 B
build/block-library/blocks/separator/theme-rtl.css 172 B
build/block-library/blocks/separator/theme.css 172 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 769 B
build/block-library/blocks/site-logo/editor.css 769 B
build/block-library/blocks/site-logo/style-rtl.css 165 B
build/block-library/blocks/site-logo/style.css 165 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 165 B
build/block-library/blocks/social-link/editor.css 165 B
build/block-library/blocks/social-links/editor-rtl.css 812 B
build/block-library/blocks/social-links/editor.css 811 B
build/block-library/blocks/social-links/style-rtl.css 1.3 kB
build/block-library/blocks/social-links/style.css 1.3 kB
build/block-library/blocks/spacer/editor-rtl.css 307 B
build/block-library/blocks/spacer/editor.css 307 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 471 B
build/block-library/blocks/table/editor.css 472 B
build/block-library/blocks/table/style-rtl.css 481 B
build/block-library/blocks/table/style.css 481 B
build/block-library/blocks/table/theme-rtl.css 188 B
build/block-library/blocks/table/theme.css 188 B
build/block-library/blocks/tag-cloud/style-rtl.css 146 B
build/block-library/blocks/tag-cloud/style.css 146 B
build/block-library/blocks/template-part/editor-rtl.css 636 B
build/block-library/blocks/template-part/editor.css 635 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/term-description/editor-rtl.css 90 B
build/block-library/blocks/term-description/editor.css 90 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 571 B
build/block-library/blocks/video/editor.css 572 B
build/block-library/blocks/video/style-rtl.css 173 B
build/block-library/blocks/video/style.css 173 B
build/block-library/blocks/video/theme-rtl.css 124 B
build/block-library/blocks/video/theme.css 124 B
build/block-library/common-rtl.css 853 B
build/block-library/common.css 849 B
build/block-library/editor-rtl.css 9.8 kB
build/block-library/editor.css 9.79 kB
build/block-library/reset-rtl.css 474 B
build/block-library/reset.css 474 B
build/block-library/style-rtl.css 10.4 kB
build/block-library/style.css 10.4 kB
build/block-library/theme-rtl.css 665 B
build/block-library/theme.css 669 B
build/block-serialization-default-parser/index.min.js 1.09 kB
build/block-serialization-spec-parser/index.min.js 2.79 kB
build/blocks/index.min.js 45.7 kB
build/components/index.min.js 217 kB
build/components/style-rtl.css 15.2 kB
build/components/style.css 15.2 kB
build/compose/index.min.js 10.4 kB
build/core-data/index.min.js 12.4 kB
build/customize-widgets/index.min.js 11.2 kB
build/customize-widgets/style-rtl.css 1.5 kB
build/customize-widgets/style.css 1.49 kB
build/data-controls/index.min.js 614 B
build/data/index.min.js 7.1 kB
build/date/index.min.js 31.5 kB
build/deprecated/index.min.js 428 B
build/dom-ready/index.min.js 304 B
build/dom/index.min.js 4.46 kB
build/edit-navigation/style-rtl.css 3.74 kB
build/edit-navigation/style.css 3.74 kB
build/edit-post/classic-rtl.css 492 B
build/edit-post/classic.css 494 B
build/edit-post/index.min.js 29.3 kB
build/edit-post/style-rtl.css 7.2 kB
build/edit-post/style.css 7.19 kB
build/edit-site/index.min.js 29.6 kB
build/edit-site/style-rtl.css 5.5 kB
build/edit-site/style.css 5.5 kB
build/edit-widgets/index.min.js 15.7 kB
build/edit-widgets/style-rtl.css 4.1 kB
build/edit-widgets/style.css 4.1 kB
build/editor/index.min.js 37.5 kB
build/editor/style-rtl.css 3.76 kB
build/editor/style.css 3.75 kB
build/element/index.min.js 3.17 kB
build/escape-html/index.min.js 517 B
build/format-library/index.min.js 5.93 kB
build/format-library/style-rtl.css 571 B
build/format-library/style.css 571 B
build/hooks/index.min.js 1.55 kB
build/html-entities/index.min.js 424 B
build/i18n/index.min.js 3.6 kB
build/is-shallow-equal/index.min.js 501 B
build/keyboard-shortcuts/index.min.js 1.72 kB
build/keycodes/index.min.js 1.3 kB
build/list-reusable-blocks/index.min.js 1.85 kB
build/list-reusable-blocks/style-rtl.css 838 B
build/list-reusable-blocks/style.css 838 B
build/media-utils/index.min.js 2.92 kB
build/notices/index.min.js 845 B
build/nux/index.min.js 2.03 kB
build/nux/style-rtl.css 747 B
build/nux/style.css 743 B
build/plugins/index.min.js 1.83 kB
build/primitives/index.min.js 921 B
build/priority-queue/index.min.js 582 B
build/react-i18n/index.min.js 671 B
build/redux-routine/index.min.js 2.63 kB
build/reusable-blocks/index.min.js 2.19 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/rich-text/index.min.js 10.6 kB
build/server-side-render/index.min.js 1.52 kB
build/shortcode/index.min.js 1.48 kB
build/token-list/index.min.js 562 B
build/url/index.min.js 1.74 kB
build/viewport/index.min.js 1.02 kB
build/warning/index.min.js 248 B
build/widgets/index.min.js 7.11 kB
build/widgets/style-rtl.css 1.16 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.04 kB

compressed-size-action

@jasmussen
Copy link
Contributor

Nice one, this works as intended:
Screenshot 2021-09-24 at 09 23 55

One question though, can we enable theme authors to create these patterns in the UI? There's already an "unlink" feature, which perhaps we could tweak so that the label remains? Right now unlinking removes both label and link:

nav

In making unlink just remove the link, arguably it'd be consistent with unlinking text:
unlink

@gwwar
Copy link
Contributor Author

gwwar commented Sep 27, 2021

I've updated the unlink function to only remove id/url in 61519ec

When we publish, should a link with a label but no url be visible in the published view?

CleanShot.2021-09-27.at.09.33.35.mp4

@gwwar gwwar requested a review from getdave September 27, 2021 16:37
@jasmussen
Copy link
Contributor

When we publish, should a link with a label but no url be visible in the published view?

Great question. On the one hand my initial instinct was "no".

On the other hand, the hope is that the wavy underline/linting indicator of a dead link can scale to blocks like Buttons, where right now you can publish a button that links no-where.

I would also like to pair the underline (separate effort) with a pre-publish panel that says "these blocks have dead links", making the wavy underline an extra affordance and not the sole indicator. In that light, maybe it's okay to publish? Not a strong opinion either way, and probably best to choose what feels right and go from there.

@gwwar
Copy link
Contributor Author

gwwar commented Sep 27, 2021

@jasmussen If we follow up with a pre-publish check I think it's less of an issue to have this display with the URL empty. That's what current behavior does, but it's harder to get into this state since folks end up needing to edit the markup manually.

@getdave
Copy link
Contributor

getdave commented Sep 28, 2021

@gwwar I wonder if this could be used in conjunction with #33849 so that if the user just enters the text it will use that as the label placeholder. Once they enter a URL then it updates fully.

@gwwar
Copy link
Contributor Author

gwwar commented Sep 28, 2021

@getdave feel free to apply this changeset to the branch 👍 I was hoping that we could maybe land this piece first though to help enable pattern work.

@getdave
Copy link
Contributor

getdave commented Sep 28, 2021

Oh yes don't hold anything up. I just saw the potential synergy in the future 😄

@gwwar
Copy link
Contributor Author

gwwar commented Sep 29, 2021

@jasmussen @getdave I think this piece is relatively safe to land by itself. Do y'all agree or is there any other behavior we should update in this PR?

Copy link
Contributor

@jasmussen jasmussen left a comment

Choose a reason for hiding this comment

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

Absolutely worth trying. Thank you!

@gwwar
Copy link
Contributor Author

gwwar commented Sep 30, 2021

Looks like we need some input for what should happen in the Navigation Editor if we unlink a subset of properties for a navigation link. In this branch it looks like we point the url at the menu item in that case.

CleanShot.2021-09-30.at.12.01.03.mp4

Note that serializing link placeholders in trunk has inconsistent behavior depending on the variation: #35271

cc @getdave @tellthemachines @talldan any thoughts on ideal behavior for the Navigation Editor?

@getdave
Copy link
Contributor

getdave commented Oct 1, 2021

cc @getdave @tellthemachines @talldan any thoughts on ideal behaviour for the Navigation Editor?

The Nav Editor should serialize the url to match whatever the URL is that was selected, not some generated slug of the Menu post type. I guess there is a bug... 🤔

It looks like it's not possible to Unlink the nav item. If I unlink an item and the reload the Nav editor the unlinked item is restored as though no action occurred.

Screen.Capture.on.2021-10-01.at.12-02-06.mov

Let's look at the block that we're persisting:

{
    "clientId": "ea02ad66-b946-4c5f-8761-2aa7f7cd541c",
    "name": "core/navigation-link",
    "isValid": true,
    "attributes": {
        "label": "",
        "type": "",
        "id": "",
        "opensInNewTab": false,
        "url": "",
        "kind": "",
        "__internalRecordId": 807,
        "isTopLevelLink": true
    },
    "innerBlocks": []
}

and here is the block that comes back from the call to

const updatedBlocks = await dispatch(
batchSaveMenuItems( post.blocks[ 0 ], menuId )
);

{
    "clientId": "ea02ad66-b946-4c5f-8761-2aa7f7cd541c",
    "name": "core/navigation-link",
    "isValid": true,
    "attributes": {
        "label": "my new draft page",
        "type": "page",
        "kind": "post-type",
        "url": "http://localhost:8888/my-new-draft-page/",
        "id": 770,
        "__internalRecordId": 807
    },
    "innerBlocks": []
}

It looks like perhaps the API ignores the "empty" block and just sends back the original so we can never remove the link.

@spacedmonkey Would you have any insight into this? Is the REST API rejecting menu items which don't have any attributes as invalid?

@spacedmonkey
Copy link
Member

@getdave @gwwar Without looking at it deeply, I would guess it is these lines that might be the issue

// Check if menu item is type custom, then title and url are required.
if ( 'custom' === $prepared_nav_item['menu-item-type'] ) {
if ( '' === $prepared_nav_item['menu-item-title'] ) {
return new WP_Error( 'rest_title_required', __( 'Title required if menu item of type custom.', 'gutenberg' ), array( 'status' => 400 ) );
}
if ( empty( $prepared_nav_item['menu-item-url'] ) ) {
return new WP_Error( 'rest_url_required', __( 'URL required if menu item of type custom.', 'gutenberg' ), array( 'status' => 400 ) );
}
}

Have you looked in the REST API response? If there a error returned?

It is worth noting, that menu items without a title should be removed, like the current menu editor.

Screen.Recording.2021-09-11.at.13.39.48.mov

@gwwar
Copy link
Contributor Author

gwwar commented Oct 5, 2021

@getdave @spacedmonkey @jasmussen let's explore the Navigation Editor placeholder behavior in a separate PR to address #35271

My current thoughts are that we ideally:

  1. Prioritize retraining backwards compatibility for menu items
  2. Provided that we can retain backwards compatibility, the most user friendly behavior I can think of adopting would be keeping the placeholders in the Navigation Editor view, but not render them on the published page.

Unless I'm misunderstanding the Navigation Editor project, there's hopefully some wiggle room to adopt new behaviors if it enhances the experience, instead of doing a straightforward functionality port.

I can keep this PR on hold until we resolve #35271.

@gwwar
Copy link
Contributor Author

gwwar commented Oct 11, 2021

🤔 to unblock this PR I can try to modify unlink behavior depending via a block parameter.

Edit: Reading through #30007 it doesn't feel right to serialize an extra block attribute (via block context) to modify behavior that will only be seen in the edit view. Making each editor pass through an unlink function isn't ideal, either since it's easy to forget passing through the needed setting for a new editor, and the functions themselves will likely drift.

@gwwar
Copy link
Contributor Author

gwwar commented Oct 11, 2021

@gwwar gwwar force-pushed the try/navigation-label-placeholder branch from 61519ec to 871418d Compare October 11, 2021 17:51
@gwwar
Copy link
Contributor Author

gwwar commented Oct 11, 2021

Okay I think I have this unblocked. In 871418d I disable this new behavior for the navigation editor.

cc @getdave @jasmussen much appreciated if folks could take this for another spin

@jasmussen
Copy link
Contributor

Here's a GIF showing the building of a nice header pattern, leveraging the "unlink" and "keep label" features in this branch:

nice

I think this is potent. I'd love for it to land. I'd defer to Dave on whether it needs an opt-out at all, but if that's what it takes to land this, it seems good to me since there's a clear comment in context, and the amount of code is manageable!

Nice work as always.

Copy link
Contributor

@getdave getdave left a comment

Choose a reason for hiding this comment

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

Sorry for the late response. GH comments becoming overwhelming.

I tested the editor and it is correctly disabled.

Screen.Capture.on.2021-10-13.at.14-37-01.mp4

But I have questions about if this is the best way to proceed given the potential upcoming advances to the paradigm around how the Nav block and inner blocks interact.

Specifically I'm concerned about us starting to disable functionality in the editor via props on inner nav blocks.

Why?

As you may have seen the Nav block is possibly moving towards an architecture where the presentation is governed by the wrapping core/navigation block whilst the inner blocks represent the structure of the nav data. Think about the Nav block as being akin to a Template Part and how this facilitates reusable navigation data with different presentations.

The vision is that the Nav Editor becomes another instance of an Isolated Template Part editor, concerned only with editing the inner blocks. In this scenario there would be no wrapping core/navigation block used in the Nav Editor.

One of the benefits of this is that we'd be able to stop having to worry about features added to the Nav block leaking into the Editor and causing regressions. The inner blocks are "raw" so we shouldn't need to disable anything on them.

Therefore (and circling back to my concerns) it we start controlling the inner blocks via props then we're going to be back in the same situation of having to "undo" things on the inner blocks.

Is there a way this feature could be added via the core/navigation block itself - perhaps via some context mechanism. Ideally if the configuring attribute isn't provided to the parent Nav block then the feature shouldn't manifest on the inner block.

I'd like to get a 2nd opinion from @talldan on this one as may disagree.

Edit: forgot to say I ❤️ the feature. Thank you for working on it. It will work very nicely with #33849.

@gwwar
Copy link
Contributor Author

gwwar commented Oct 13, 2021

Is there a way this feature could be added via the core/navigation block itself - perhaps via some context mechanism. Ideally if the configuring attribute isn't provided to the parent Nav block then the feature shouldn't manifest on the inner block.

@getdave Thanks for taking another look! I did consider using block context, but this currently only works for block attributes. In this particular case, it didn't feel like the correct fit to serialize a new attribute on the navigation and navigation link, since this is modifying editor behavior only (and its primary use case is for dropping in easier to use patterns).

Existing links without the attribute also won't behave as we expect for unsetting a link.

Overall, if we're a bit wary about diverging behavior, another option would be fixing behavior in #35271 first. (Though it does sound like there are serialization issues to work through).

@jasmussen
Copy link
Contributor

For a little bit of context, the TwentyTwentyTwo theme will come with some nice bundled header patterns, including a fresh version of this one. That particular pattern is highly opinionated, and is designed around having precisely 4 menu items, no more, no less. And the pattern is that much more effective when the labels are pre-suggested, knowing a user can always rename them after wiring them up.

In that vein, I would really love for a version of this PR to be able to land for 5.9, so such patterns are possible. Given that horizon, is it better to disable it from the nav editor as is done now, or to fix it separately in the nav editor? What's the most feasible?

@gwwar
Copy link
Contributor Author

gwwar commented Oct 14, 2021

I would really love for a version of this PR to be able to land for 5.9, so such patterns are possible. Given that horizon, is it better to disable it from the nav editor as is done now, or to fix it separately in the nav editor? What's the most feasible?

Since there already needs to be a cleanup of the remove-edit-unsupported-features filter, adding one more prop doesn't seem too problematic for me, especially since folks are thinking through this problem. I am happy to defer to folks who have been working more closely on the navigation editor screens. Maybe cc @tellthemachines @talldan @draganescu

For context changes here add the ability to used named placeholders which is very helpful in creating interesting patterns, eg "Home, About, Contact" vs "add link, add link, add link". I'm proposing a fork in behavior here since the Editor Navigation screen doesn't use patterns yet and there are some unsolved inconsistencies with how placeholders are serialized in #35271

@talldan
Copy link
Contributor

talldan commented Oct 15, 2021

The context I'm missing is why the behavior of 'Unlink' is being changed within the Navigation Block. Is it because that's the only way a pattern builder can build patterns? If so, I don't think that's right, the navigation block should be focusing on the primary use case for the majority of users, not pattern builders.

If it's being changed because everyone agrees that the right experience for all users would be for 'Unlink' to leave a label untouched, then it seems like a good change. But I think this is still debatable. For the link variations that are connected to a resource like a page, it might be quite frustrating for the label to remain present after 'Unlink', particularly if that label still matches the page title.

Then there's the case of the Navigation Editor, which I don't think should miss out on the best user experience because of past rules. Most of the features disabled in the navigation editor are like that because a theme can't possibly support those features. But this seems like a case that the navigation editor could support.

So to summarise, my opinion is that we need to understand how it should work for the majority of users, then implement that everywhere if we can.

@jasmussen
Copy link
Contributor

To an extent, the navigation block is currently the odd one out. In the cases of every other link, unlinking the item just unlinks it, and does not clear any labels set:

unlink text

unlink buttons

In light of that, it feels odd that the navigation block does it:

navigation

The fact that it enables building patterns is a side-effect of adding consistency there.

We have spent some time making it easy to build navigation people for most people, lately with the plus instantly inserting a page link, and the URL picker immediately opening to wire up a destination. Creating a menu is currently fairly seamless and smooth.

One of the benefits of the navigation block is that it lets you customize it after the fact: change labels if you like, for example prefixing "New:" to an item that's been updated, or to offer general customizability. You can even edit the URL after the fact, should you want to append a query string or fix a typo, or just point it somewhere else entirely. In light of this, the URL dialog is agnostic to the content, and it could be argued that it should work the same everywhere.

@talldan
Copy link
Contributor

talldan commented Oct 15, 2021

To an extent, the navigation block is currently the odd one out. In the cases of every other link, unlinking the item just unlinks it, and does not clear any labels set

There's quite a strong difference in that those interfaces invite the user to type the label or paragraph text first and then add the link. In that way, linking and unlinking has symmetry.

That's not true in the Navigation Link block, the act of linking also creates the label in the majority of cases.

@jasmussen
Copy link
Contributor

jasmussen commented Oct 15, 2021

That [the symmetry of linking and unlinking] remains the case, though? This interface is only ever accessible after you've created the link in the first place, at which point you can change both the label and the link to break any symmetry, it feels like the unlink button is just an extension of that. Unlinking feels different to me than removing and reinserting a link block.

@talldan
Copy link
Contributor

talldan commented Oct 15, 2021

It is quite a minor thing, so I don't really feel that strongly about it. It just seems like a really unusual flow that the way to add an unlinked item is:

  1. Add a link (which prefills the label)
  2. Unlink the link
  3. Modify the label that I didn't want in the first place.

What use case is this fulfilling for the majority of users?

Maybe this will get better with #30170, but I am genuinely confused.

@jasmussen
Copy link
Contributor

Being such an important part of a website, there's a great deal of value in being able to provide rich patterns as shortcuts to accomplishing good designs. In concert with other features built for this purpose, being able to create an opinionated 4-item pattern like this one can help enable or inspire rich designs.

Screenshot 2021-10-15 at 09 58 19

Patterns, as noted, is a side effect. Being able to unlink an item on its own can be as important as being able to edit a link. Since you can already change labels and URLs after the fact, also keeping the behavior of the unlink button consistent serves to reinforce confidence in the UI.

Flipping the question on its head: what use case is fulfilled by keeping the behavior of the unlink button unique to the menu item?

@talldan
Copy link
Contributor

talldan commented Oct 15, 2021

I think the main part I'm concerned about is that 'Unlink' potentially now introduces a system that can be abused by users to add semantically incorrect tags to their websites (anchors without hrefs being used as plain text), something that was previously quite strongly discouraged in the block by the use of the Add link button.

A couple of thoughts:

  • Is this definitely needed? Patterns can use valid links, but they might be a document anchor link (#).
  • What are the alternatives? How about a placeholder prop, or an isPlaceholder state for the block? The placeholder could be something that is only shown when the block is unselected and is unset when the user adds their own link.

@talldan
Copy link
Contributor

talldan commented Oct 15, 2021

Being able to unlink an item on its own can be as important as being able to edit a link.

Why? The block itself is called 'link', it seems unusual to consider it valid in an unlinked state.

For the issue you linked to, the reporter had a very clear use case, they wanted to create a submenu where the top-level item isn't a link. This has since been solved by the submenu block, which keeps the semantics of the link block in-tact.

@jasmussen
Copy link
Contributor

Thanks for talking through this with me. As outlined, I believe there's value to be found, but given the concerns voiced, perhaps we should pause this one after all. Of note, the following is possible as a pattern today:

Screenshot 2021-10-14 at 13 43 20

Given that fact gets us 90% there, it could be a good baseline to start from and get some feedback on patterns as they are being created and used. We can then revisit in the future if we find a need to take it further.

@mtias
Copy link
Member

mtias commented Oct 15, 2021

Chiming in a bit late, but I don't think we should ever allow a state like this:

image

Where it's not clear at all if things are in "placeholder" state or there is actual content set. If I have pages that coincide with those names, I might mistake the above as being set already while that's not true. Placeholder states that need the user to interact should be obvious and uncomplicated.

@jasmussen
Copy link
Contributor

Understood, I might have stared at this for too long. Thanks all, for chiming in and for exploring this one, I'll go ahead and close the adjacent issues.

@mtias
Copy link
Member

mtias commented Oct 15, 2021

I think our current solution is not quite right, so we'll need to continue to stare at it but at larger intervals :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Navigation Affects the Navigation Block [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants