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

Try a fixed toolbar in the navigation page #21340

Merged
merged 9 commits into from
Apr 16, 2020

Conversation

talldan
Copy link
Contributor

@talldan talldan commented Apr 2, 2020

Description

There are a couple of issues with the toolbar in the navigation page at the moment:

  • The tab order is incorrect, the toolbar can't be tabbed to from the block (this is a pretty easy fix, the slot that renders the toolbar needs to be moved to a more appropriate place).
  • The toolbar overlaps the top of the panel. While we can make space for it, it looks unusual having empty space when the toolbar hides when typing.

This PR tries using a fixed top toolbar to solve those issues. This toolbar might also become useful for other functionality (undo, redo) on this page in the future.

The negatives of this are that if someone is creating a long nav menu they might have to scroll up to access the toolbar. The empty menu also looks unusual when no block is selected.

How has this been tested?

  1. Open the nav menu page
  2. Try editing a nav block

Screenshots

Before

Screenshot 2020-04-02 at 10 47 11 am

Initially I tried adding some empty space for the toolbar, but it results in this empty space when typing

Screenshot 2020-04-02 at 10 47 47 am

This PR, using a fixed toolbar, it doesn't hide when typing (but is empty when no block is selected)

Screenshot 2020-04-02 at 10 38 58 am

Types of changes

New feature (non-breaking change which adds functionality)

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.

@talldan talldan added [Type] Enhancement A suggestion for improvement. Needs Design Feedback Needs general design feedback. [Block] Navigation Affects the Navigation Block labels Apr 2, 2020
@talldan talldan self-assigned this Apr 2, 2020
@github-actions
Copy link

github-actions bot commented Apr 2, 2020

Size Change: -49.1 kB (5%) ✅

Total Size: 840 kB

Filename Size Change
build/a11y/index.js 1.02 kB +1 B
build/annotations/index.js 3.62 kB +213 B (5%) 🔍
build/api-fetch/index.js 4.01 kB +213 B (5%) 🔍
build/autop/index.js 2.82 kB +239 B (8%) 🔍
build/block-directory/index.js 6.24 kB +207 B (3%)
build/block-editor/index.js 104 kB +2.23 kB (2%)
build/block-editor/style-rtl.css 10.2 kB -41 B (0%)
build/block-editor/style.css 10.2 kB -40 B (0%)
build/block-library/editor-rtl.css 7.11 kB -106 B (1%)
build/block-library/editor.css 7.11 kB -108 B (1%)
build/block-library/index.js 112 kB +1.53 kB (1%)
build/block-library/style-rtl.css 7.13 kB -404 B (5%)
build/block-library/style.css 7.14 kB -407 B (5%)
build/block-library/theme-rtl.css 683 B +14 B (2%)
build/block-library/theme.css 685 B +14 B (2%)
build/block-serialization-default-parser/index.js 1.88 kB +234 B (12%) ⚠️
build/blocks/index.js 57.7 kB +220 B (0%)
build/components/index.js 198 kB +2.8 kB (1%)
build/components/style-rtl.css 16.6 kB +60 B (0%)
build/components/style.css 16.6 kB +55 B (0%)
build/compose/index.js 6.66 kB +447 B (6%) 🔍
build/core-data/index.js 11.1 kB +396 B (3%)
build/data-controls/index.js 1.25 kB +208 B (16%) ⚠️
build/data/index.js 8.43 kB +192 B (2%)
build/date/index.js 5.47 kB +104 B (1%)
build/dom/index.js 3.1 kB +48 B (1%)
build/edit-navigation/index.js 3.53 kB +785 B (22%) 🚨
build/edit-navigation/style-rtl.css 431 B +152 B (35%) 🚨
build/edit-navigation/style.css 430 B +150 B (34%) 🚨
build/edit-post/index.js 27.8 kB -65.1 kB (234%) 🏆
build/edit-site/index.js 10.4 kB +327 B (3%)
build/edit-widgets/index.js 7.53 kB +351 B (4%)
build/edit-widgets/style-rtl.css 4.65 kB +908 B (19%) ⚠️
build/edit-widgets/style.css 4.64 kB +909 B (19%) ⚠️
build/editor/editor-styles-rtl.css 428 B +29 B (6%) 🔍
build/editor/editor-styles.css 431 B +31 B (7%) 🔍
build/editor/index.js 43.6 kB +837 B (1%)
build/element/index.js 4.65 kB +204 B (4%)
build/format-library/index.js 7.32 kB +366 B (5%) 🔍
build/hooks/index.js 2.13 kB +207 B (9%) 🔍
build/i18n/index.js 3.56 kB -6 B (0%)
build/is-shallow-equal/index.js 711 B +1 B
build/keyboard-shortcuts/index.js 2.51 kB +213 B (8%) 🔍
build/keycodes/index.js 1.91 kB +211 B (11%) ⚠️
build/list-reusable-blocks/index.js 3.12 kB +134 B (4%)
build/media-utils/index.js 5.28 kB +439 B (8%) 🔍
build/notices/index.js 1.79 kB +219 B (12%) ⚠️
build/nux/index.js 3.4 kB +392 B (11%) ⚠️
build/plugins/index.js 2.67 kB +138 B (5%) 🔍
build/primitives/index.js 1.49 kB -6 B (0%)
build/redux-routine/index.js 2.84 kB +3 B (0%)
build/rich-text/index.js 14.8 kB +318 B (2%)
build/server-side-render/index.js 2.67 kB +131 B (4%)
build/shortcode/index.js 1.7 kB +1 B
build/url/index.js 4.01 kB +1 B
build/viewport/index.js 1.84 kB +236 B (12%) ⚠️
build/wordcount/index.js 1.17 kB -1 B
ℹ️ View Unchanged
Filename Size Change
build/blob/index.js 620 B 0 B
build/block-directory/style-rtl.css 760 B 0 B
build/block-directory/style.css 760 B 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 569 B 0 B
build/edit-post/style-rtl.css 12.3 kB 0 B
build/edit-post/style.css 12.3 kB 0 B
build/edit-site/style-rtl.css 5.02 kB 0 B
build/edit-site/style.css 5.02 kB 0 B
build/editor/style-rtl.css 3.49 kB 0 B
build/editor/style.css 3.49 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/style-rtl.css 502 B 0 B
build/format-library/style.css 502 B 0 B
build/html-entities/index.js 622 B 0 B
build/list-reusable-blocks/style-rtl.css 226 B 0 B
build/list-reusable-blocks/style.css 226 B 0 B
build/nux/style-rtl.css 616 B 0 B
build/nux/style.css 613 B 0 B
build/priority-queue/index.js 789 B 0 B
build/token-list/index.js 1.28 kB 0 B
build/warning/index.js 1.14 kB 0 B

compressed-size-action

Copy link
Contributor

@draganescu draganescu left a comment

Choose a reason for hiding this comment

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

I tested this and managed to crash it. See below:

menu-editor-crash

It seems when switching menus the toolbar does not adjust to the new selected menu.

@talldan
Copy link
Contributor Author

talldan commented Apr 3, 2020

What's happening with the issue @draganescu spotted is that when the menu is changed, the blocks are replaced using the RESET_BLOCKS action, but block selection is still kept in the store.

I tried a fix to the block editor store in #21371, but I don't think it's going to be straightforward, so I've pushed an intermediate fix in one of the last commits that calls clearBlockSelection whenever the menu is changed.

We might actually want to select the root navigation block when the menu is changed rather than clearing selection.

@talldan talldan force-pushed the try/navigation-page-fixed-toolbar branch from 2701495 to 4aa01fb Compare April 3, 2020 05:47
@mtias
Copy link
Member

mtias commented Apr 3, 2020

This makes sense to me.

}
>
<PanelBody title={ __( 'Navigation menu' ) }>
<NavigableToolbar
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be fine to just render the toolbar slot in a fixed position?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using the BlockToolbar component mirrors the way the fixed toolbar is implemented in the post editor. My thoughts were that this is preferable as the movers are implemented differently in BlockToolbar component—they're inline buttons. Whereas with the Slot, the movers reveal and have a drag handle, which doesn't seem like the right behaviour for an inline toolbar.

@tellthemachines
Copy link
Contributor

Was testing this and ran into an issue where pressing Esc to go into Navigation mode causes Uncaught TypeError: Cannot read property 'parentNode' of null at refresh (index.js:334) to appear again and again in the console (it keeps repeating until I return to edit mode)

Seems to point to (this line)[https://github.com/WordPress/gutenberg/blob/e8f4f37d5c4e45ce545ddf55e387100ae996a15e/packages/components/src/popover/index.js#L330-L331]

@talldan talldan force-pushed the try/navigation-page-fixed-toolbar branch from 5e2ef89 to ee226a0 Compare April 6, 2020 04:09
@talldan
Copy link
Contributor Author

talldan commented Apr 6, 2020

@tellthemachines Thanks for spotting that. I fixed it in the last commit. Navigation mode depends on <Popover.Slot name="block-toolbar" /> for rendering the block breadcrumb button in navigation mode, which I'd inadvertently removed. It's probably not ideal that this button renders over the top of the toolbar 🤔

Screenshot 2020-04-06 at 12 11 44 pm

@tellthemachines
Copy link
Contributor

It's probably not ideal that this button renders over the top of the toolbar 🤔

Can we hide the toolbar when in Navigation mode? It probably shouldn't be shown unless in Edit mode and a block is selected.

@talldan
Copy link
Contributor Author

talldan commented Apr 7, 2020

Can we hide the toolbar when in Navigation mode? It probably shouldn't be shown unless in Edit mode and a block is selected.

Yep, that might be a good option. Will work on that 👍

@talldan talldan force-pushed the try/navigation-page-fixed-toolbar branch from b28628e to d8be3a9 Compare April 8, 2020 09:25
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.

I can still cause the page to crash in a similar way to what @draganescu found: after making changes to a menu item and clicking "Save navigation", the "More options" button remains visible in the toolbar:

Screen Shot 2020-04-09 at 1 45 38 pm

<Panel>
<PanelBody
title={ __( 'Navigation structure' ) }
initialOpen={ isLargeViewport }
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure what's wrong, but this is no longer applying? The panel is always closed, whatever the screen size.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, yeah, unusual. Not sure why this happens.

I moved the useViewportMatch call back to its original location in a796f3c and it works again now.

@karmatosed karmatosed removed their request for review April 9, 2020 19:51
Copy link
Member

@karmatosed karmatosed left a comment

Choose a reason for hiding this comment

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

From a design perspective, I think this works. There are a few issues I found in testing but isolating for the feedback to be about toolbar, this passes design review.

@karmatosed karmatosed removed the Needs Design Feedback Needs general design feedback. label Apr 9, 2020
@talldan
Copy link
Contributor Author

talldan commented Apr 15, 2020

I can still cause the page to crash in a similar way to what @draganescu found: after making changes to a menu item and clicking "Save navigation", the "More options" button remains visible in the toolbar:

@tellthemachines thanks for spotting that! It's the same issue as before, RESET_BLOCKS is being called when saving, and it causes every block to get a new client id. Unfortunately, the block selection state retains the previous client id, so the toolbar still tries to show the more menu for a block that now no longer exists.

There seem to be a few issues that I encountered to document 😵:

aff58f7 and a56ef6e solve the problem for temporarily.

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.

All working fine now!

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.

5 participants