Problem/Motivation

As part of #3343940: Field UI 2023 User Research, we discovered that users have challenges orienting themselves in the Drupal Admin UI. One of the many causes to this is that Drupal doesn't indicate active menu trail in the Toolbar when user navigates to pages that are deeper in the administrative UI. While this information is available through the breadcrumbs, to make users more confident about their orientation, it is important to communicate the current location using multiple mechanisms as described by this Nielsen Norman article about navigation.

Proposed resolution

Indicate active menu trail even for pages that are not included in Toolbar to help users orient in which section of the site they are currently on.

Remaining tasks

User interface changes


Top level: /admin/structure

HEAD:

MR:


Sub level: /admin/structure/types


HEAD:

MR:


Sub sub level: /admin/structure/types/manage/article/fields

HEAD:

MR:

API changes

Data model changes

Release notes snippet

Issue fork drupal-3371005

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

lauriii created an issue. See original summary.

shailja179’s picture

Status: Active » Needs work
shailja179’s picture

This feature is not working in other Drupal versions as well. For this we will have to enable the child links in toolbar as well.

lauriii’s picture

Thanks @shailja179! That is indeed the current behavior. 😊 This issue is to address that bug. Hopefully we can find a way to indicate the active menu trail even when the child links are not in Toolbar.

tim.plunkett’s picture

Title: Toolbar doesn't indicate active menu trail for pages not included Toolbar » Toolbar doesn't indicate active menu trail for pages not included in Toolbar
omkar.podey’s picture

Assigned: Unassigned » omkar.podey

omkar.podey’s picture

Issue tags: +Needs tests

The toolbar seems to be working as expected (The active trail is maintained through the menu even if we traverse deeper into feild settings) in vertical orientation but not in the horizontal one, they basically have different UI's so I don't think the same behaviour should be expected anyways.

omkar.podey’s picture

ToolbarTest.php is just copied over and i used it to debug initially, might delete it completely or convert into an actual test.

omkar.podey’s picture

Assigned: omkar.podey » Unassigned
Status: Needs work » Needs review
omkar.podey’s picture

Assigned: Unassigned » omkar.podey
Status: Needs review » Needs work
omkar.podey’s picture

Still need to create an issue for broken breadcrumb under the Appearance tab.

omkar.podey’s picture

Assigned: omkar.podey » Unassigned
Status: Needs work » Needs review
shiv_sharma’s picture

Status: Needs review » Needs work

@omkar.podey PR does have 4 unresolved threads please resolve them,

omkar.podey’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

I'm unable to log in into gitlab as of now (just keeps redirecting me to the home page, when clicking signIn), hence the unresolved threads, but i have addressed all of it.

tim.plunkett’s picture

Issue tags: +Admin UX
omkar.podey’s picture

Assigned: Unassigned » omkar.podey
Status: Needs review » Needs work
omkar.podey’s picture

I mostly caused this behaviour so closed #3376457: Change in orientation doesn't load collapsible icons until page refresh. and start fixing it here.

omkar.podey’s picture

Assigned: omkar.podey » Unassigned
Status: Needs work » Needs review
lauriii’s picture

Status: Needs review » Needs work

I'm not sure if I'm doing something wrong, but I tried to take the MR locally and it isn't changing the behavior at all. Wondering if some of the changes broke this for Drupal instances that are not running in a subdirectory?

omkar.podey’s picture

That's weird, I am not running drupal in a subdirectory it does seem to be working for me and other machines. Maybe just needs a drush cr.

omkar.podey’s picture

Status: Needs work » Needs review
tim.plunkett’s picture

Note that in addition to clearing Drupal caches I also ran sessionStorage.clear();localStorage.clear(); in the browser console while testing this just to be sure. Works for me. Pushed a small clean-up

Rajeshreeputra made their first commit to this issue’s fork.

rajeshreeputra’s picture

StatusFileSize
new198.58 KB
new438.04 KB

Rebased and to apply patch locally.
Tested the same, I can see the current active menu trail. Nice work here. 🙂

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

Test failure seems legit to issue.

lauriii’s picture

It looks like #20 is because I'm using Umami which is a multilingual site that uses a path prefix for detecting languages.

omkar.podey’s picture

Assigned: Unassigned » omkar.podey
omkar.podey’s picture

Assigned: omkar.podey » Unassigned
Status: Needs work » Needs review
hooroomoo’s picture

Status: Needs review » Needs work
StatusFileSize
new39.93 KB
new51.57 KB

The bold and underline indicating the active tab is hard to see in my opinion. I think this could benefit from changing the background color to highlight it as well.

Current MR:

Suggestion of highlighted tab (#f5f5f5 is used in the screenshot for the active tab):

omkar.podey’s picture

Assigned: Unassigned » omkar.podey
omkar.podey’s picture

Assigned: omkar.podey » Unassigned
Status: Needs work » Needs review
omkar.podey’s picture

i did try to change the highlight colour on the css file but it seemed to show no effect on my local, is there something that i'm missing?

hooroomoo’s picture

#33 It looks like if on Claro, then claro/css/state/toolbar.menu.pcss.css is used so the bg color needed to be added there

omkar.podey’s picture

Assigned: Unassigned » omkar.podey
Status: Needs review » Needs work
omkar.podey’s picture

Assigned: omkar.podey » Unassigned
Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Applied the MR on an Umami install
Went to /en/admin/structure/types/manage/article/fields
But "Content types" doesn't appear to be highlighted.

There a step I'm missing?

omkar.podey’s picture

Maybe try

  1. clearing caches first
  2. restarting local server
hooroomoo’s picture

Status: Needs work » Needs review

#37 should work now

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Retested MR 4366 and on admin/structure/types/manage/article/fields I see that the "Content types" link is highlighted as expected

Woo!

hooroomoo’s picture

StatusFileSize
new10.91 KB

Uploading static patch for 11.x. Please ignore this and continue further work on MR.

lauriii’s picture

Status: Reviewed & tested by the community » Needs work

Posted review on the MR

omkar.podey’s picture

Assigned: Unassigned » omkar.podey

.

omkar.podey’s picture

The problem right now is a line in core/modules/toolbar/tests/src/Nightwatch/Tests/toolbarApiTest.js night watch js test Drupal.toolbar.models.toolbarModel.set('orientation', 'vertical'); should have triggered

 Drupal.toolbar.models.toolbarModel.on(
          'change:activeTab change:orientation change:isOriented change:isTrayToggleVisible chan

in core/modules/toolbar/js/toolbar.js and which should have the toolbar in vertical state but it doesn't.

omkar.podey’s picture

Assigned: omkar.podey » Unassigned
Status: Needs work » Needs review
omkar.podey’s picture

Assigned: Unassigned » omkar.podey
lauriii’s picture

Confirmed with @ckrina that the background change this issue is introducing is acceptable.

utkarsh_33’s picture

Status: Needs review » Needs work

Left a comment suggesting a small change so marking it back to needs work.

lauriii’s picture

Status: Needs work » Needs review

Thanks for the review @Utkarsh_33! Addressed feedback 😊

omkar.podey’s picture

Issue summary: View changes
StatusFileSize
new112.17 KB

While reviewing I found a bug when the toolbar is expanded down Configuration-->Development the horizontal orientation button disappears and can't be scrolled down to but this can be a separate issue.

omkar.podey’s picture

I think we should also test Horizontal->Vertical and vice-versa that tests, the state is maintained properly after orientation change. Expanded the test coverage to cover this in the previous commit.

omkar.podey’s picture

Just a bit concerned about render() as we are always calling both this.renderVertical(); this.renderHorizontal(); but it does seem to work fine and the code is much simpler this way.

omkar.podey’s picture

Assigned: omkar.podey » Unassigned
wim leers’s picture

Status: Needs review » Needs work
Issue tags: +Needs screenshots, +JavaScript
  1. Can we get before vs after screenshots? 🙏 For the horizontal orientation as well as the vertical orientation. And in vertical orientation also for a top-level vs sub-level vs sub-sub-level item.
  2. +++ b/core/modules/toolbar/js/toolbar.menu.js
    @@ -14,6 +14,34 @@
    +          const dataDrupalPath = `${basePath}${path}`.startsWith('/')
    

    This logic exists in two places — let's extract it into a helper function? 🙏

  3. +++ b/core/modules/toolbar/js/toolbar.menu.js
    @@ -23,7 +51,7 @@
    -     * @param {jQuery} $item
    +     * @param {*|jQuery} $item
    

    Why this change? (Not yet explained on issue or MR AFAICT.)

  4. +++ b/core/modules/toolbar/js/toolbar.menu.js
    @@ -161,16 +190,37 @@
    +            const dataDrupalPath = `${basePath}${path}`.startsWith('/')
    +              ? `${basePath}${path}`.substring(1)
    +              : `${basePath}${path}`;
    

    AFAICT the startsWith will always be true due to presence of the base path.

    Shouldn't this be

    path.startsWith('/')
    

    instead? 🤔

  5. +++ b/core/modules/toolbar/js/views/MenuVisualView.js
    @@ -13,8 +13,20 @@
    +      /**
    +       * Renders the horizontal toolbar with the right focus.
    +       */
    +      renderHorizontal() {
    +        if ('drupalToolbarMenu' in $.fn) {
    +          this.$el.children('.toolbar-menu').drupalToolbarMenuHorizontal();
    +        }
           },
    

    🤔 The comment mentions "focus", but I don't see anything focus-related here?

  6. +++ b/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarActiveTrailTest.php
    @@ -0,0 +1,76 @@
    +   * Tests that the active trail is maintained even when traversed deeper.
    

    👏

  7. +++ b/core/modules/toolbar/toolbar.module
    @@ -350,6 +350,14 @@ function toolbar_preprocess_html(&$variables) {
    +  foreach ($links as $link) {
    +    $paths[] = $link->getUrl()->getInternalPath();
    +  }
    +  $variables['#attached']['drupalSettings']['breadcrumb_paths'] = $paths;
    

    🤔 It's possible to add external links anywhere in a menu.

    How will this behave in that case?

    Let's add explicit test coverage. Chances are a number of sites are using that, and we want to ensure there are no JS errors in that case!

    Breadcrumbs can only ever refer to local/internal links! 👍

omkar.podey’s picture

Assigned: Unassigned » omkar.podey
Issue tags: -JavaScript +JavaScript
omkar.podey’s picture

RE Comment#54 / 4

I think we are majorly concerned with the basePath rather than path which comes from a list of internal paths which is always relative I think but the basePath is always absolute I guess so maybe we don't need the condition at all ?.

RE Comment#54 / 3 and RE Comment#54 / 5

It's no more the case, based on a previous commit.

hooroomoo’s picture

hooroomoo’s picture

Issue summary: View changes
Issue tags: -Needs screenshots

Added screenshots to IS of before and after changes with both vertical and horizontal orientations for top level (/structure), sub level (/structure/types) , and sub sub level (/admin/structure/types/manage/article/fields)

hooroomoo’s picture

Status: Needs work » Reviewed & tested by the community

I believe all the remaining feedback has been addressed or no longer applies. Tested and code looks good to me.

lauriii credited catch.

lauriii’s picture

Status: Reviewed & tested by the community » Needs work

Posted feedback regarding caching + how we could handle custom breadcrumb builders more gracefully. Crediting @catch for discussing this in Slack.

omkar.podey’s picture

Assigned: omkar.podey » Unassigned
Status: Needs work » Needs review
hooroomoo’s picture

Status: Needs review » Needs work
StatusFileSize
new99.94 KB
new176.53 KB
new103.17 KB

It looks like there was a regression somewhere because I am not getting the active tab anymore when I manually tested. I think the tests also need to be updated since it didn't catch the regression (left a comment).

Horizontal admin/structure/types on initial load not showing active tab

Vertical admin/structure/types/manage/article/fields not showing active tab

Horizontal admin/structure/types/manage/article/fields not showing active tab

tim.plunkett’s picture

Issue tags: +Needs tests

According to manually testing with git bisect, https://git.drupalcode.org/project/drupal/-/merge_requests/4366/diffs?co... is the offending commit.

Reverting that fixes things, but I'm not sure why @omkar.podey added that.

And as @hooroomoo points out, we're definitely missing test coverage

omkar.podey’s picture

Status: Needs work » Needs review
hooroomoo’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

Feedback has been addressed. Removing needs test tag. Looks good to me.

lauriii’s picture

Status: Reviewed & tested by the community » Needs review

One more thread in the MR because we can probably get rid of the breadcrumb dependency with the latest solution 👍

hooroomoo’s picture

Status: Needs review » Reviewed & tested by the community

Feedback has been addressed

  • lauriii committed 3165269b on 11.x
    Issue #3371005 by omkar.podey, lauriii, hooroomoo, tim.plunkett,...

lauriii’s picture

Status: Reviewed & tested by the community » Fixed

Committed 3165269 and pushed to 11.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.