Problem/Motivation

If you customize the toolbar (for a particular site or a distribution), and the first toolbar item is not a tab, then toolbar.js will always mark the first toolbar item as being active.

hook_toolbar() (see core/modules/toolbar/toolbar.api.php) speaks of toolbar items. But then core/modules/toolbar/templates/toolbar.html.twig marks every toolbar item as a tab:

    {% for key, tab in tabs %}
      {% set tray = trays[key] %}
      <div{{ tab.attributes.addClass('toolbar-tab') }}>

This is wrong.

Worse, core/modules/toolbar/js/toolbar.js then does this:

        // If the toolbar's orientation is horizontal and no active tab is
        // defined then show the tray of the first toolbar tab by default (but
        // not the first 'Home' toolbar tab).
        if (Drupal.toolbar.models.toolbarModel.get('orientation') === 'horizontal' && Drupal.toolbar.models.toolbarModel.get('activeTab') === null) {
          Drupal.toolbar.models.toolbarModel.set({
            activeTab: $('.toolbar-bar .toolbar-tab:not(.home-toolbar-tab) a').get(0)
          });
        }

This means that by default, if there is no active tab, it will automatically set the first toolbar item as active. Even if it's just a link, and not actually a tab.

This means that if the first toolbar item is a link, it is automatically marked as active, and will continue to be so until the first "actual" tab (with a tray, e.g. the "user" tab+tray) is clicked. But until you do, that means the first toolbar item (a link) will remain active, even while you click other toolbar items that are links, to navigate around. This is super confusing behavior.

Proposed resolution

  1. Better distinguish between "tab" items and "link" items.
  2. Stop assuming the default toolbar in the codebase.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#43 interdiff_39_43.txt861 bytesRishabh Vishwakarma
#43 2885755-43.patch3.99 KBRishabh Vishwakarma
#39 2885755-39.patch4.54 KBGauravvvv
#38 2885755-nr-bot.txt144 bytesneeds-review-queue-bot
#36 2885755-36.patch5.42 KBsmustgrave
#36 interdiff-34-36.txt612 bytessmustgrave
#34 interdiff_32-34.txt704 bytesAkashKumar07
#34 2885755-34.patch5.42 KBAkashKumar07
#32 2885755-32.patch5.4 KBkarishmaamin
#21 interdiff-2885755-18-21.txt916 bytesGrandmaGlassesRopeMan
#21 2885755-21.patch5.44 KBGrandmaGlassesRopeMan
#18 interdiff-2885755-14-18.txt2.63 KBGrandmaGlassesRopeMan
#18 2885755-18.patch5.44 KBGrandmaGlassesRopeMan
#15 2885755-14.patch6 KBdawehner
#15 2885755-14-test.patch3.58 KBdawehner
#13 interdiff-2885755-10-13.txt2.38 KBGrandmaGlassesRopeMan
#13 2885755-13.patch2.42 KBGrandmaGlassesRopeMan
#10 2885755-10.patch1.59 KBGrandmaGlassesRopeMan
#6 2885755-2-8.3.x.patch989 bytesWim Leers
#2 2885755-2.patch1.72 KBWim Leers
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Wim Leers created an issue. See original summary.

Wim Leers’s picture

Status: Active » Needs review
FileSize
1.72 KB
GrandmaGlassesRopeMan’s picture

Issue tags: +JavaScript
droplet’s picture

hook_toolbar() (see core/modules/toolbar/toolbar.api.php) speaks of toolbar items. But then core/modules/toolbar/templates/toolbar.html.twig marks every toolbar item as a tab:

Hmm.. can be improved but not a problem for most CSS guy I think. `.toolbar-tab` is a helper class for tab-like style. And for the customized site, changing the Twig markup to remove `.toolbar-tab` for LINK also makes sense. (Toolbar default to support Tab-like style only)

The patch removed the default active Tab. I'm not so sure it's a Bug or Task. (Or incomplete patch?) I don't like its default to active also but I thought the UX guy has diff thoughts...

** Note: I can see the buggy on default active tab to `$('.toolbar-bar .toolbar-tab:not(.home-toolbar-tab) a').get(0)` on frontend is a problem. But @wim's IS mixed few requests as I seen.

Status: Needs review » Needs work

The last submitted patch, 2: 2885755-2.patch, failed testing. View results

Wim Leers’s picture

yogeshmpawar’s picture

Status: Needs work » Needs review

Triggering Bots.

Status: Needs review » Needs work

The last submitted patch, 6: 2885755-2-8.3.x.patch, failed testing. View results

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

GrandmaGlassesRopeMan’s picture

- 8.5.x reroll

GrandmaGlassesRopeMan’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 10: 2885755-10.patch, failed testing. View results

GrandmaGlassesRopeMan’s picture

Status: Needs work » Needs review
FileSize
2.42 KB
2.38 KB

- Find the first item and make sure it has a tray to be opened, data-toolbar-tray.

Wim Leers’s picture

  1. +++ b/core/modules/toolbar/js/toolbar.es6.js
    @@ -136,6 +136,19 @@
    +        if (Drupal.toolbar.models.toolbarModel.get('orientation') === 'horizontal' && Drupal.toolbar.models.toolbarModel.get('activeTab') === null) {
    

    We shouldn't special case .home-toolbar-tab. It should definitely be possible to not special case it, because that one doesn't even have a tray.

  2. +++ b/core/modules/toolbar/js/toolbar.es6.js
    @@ -136,6 +136,19 @@
    +          if (typeof attr !== typeof undefined && attr !== false) {
    

    This looks very weird and brittle, but I'm guessing it's necessary?

  3. +++ b/core/modules/toolbar/js/toolbar.js
    @@ -93,6 +94,16 @@
    +          if ((typeof attr === 'undefined' ? 'undefined' : _typeof(attr)) !== (typeof undefined === 'undefined' ? 'undefined' : _typeof(undefined)) && attr !== false) {
    

    I think this might be the scariest line of code I've seen in years… 😱 Yes, it's in compiled code. But still.

dawehner’s picture

+++ b/core/modules/toolbar/js/toolbar.es6.js
@@ -136,6 +136,19 @@
+          if (typeof attr !== typeof undefined && attr !== false) {

I was wondering: is this the only/best way to check for typeof. According to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operat... the only value which returns undefined for typeof is undefed, so why can't you use attr === undefined

On top of this question, here is also a test.

The last submitted patch, 15: 2885755-14-test.patch, failed testing. View results

Wim Leers’s picture

On top of this question, here is also a test.

👏

+++ b/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php
@@ -30,6 +30,11 @@ public function testToolbarToggling() {
+    // Ensure that the administration is active by default.

übernit: s/administration/administration toolbar tab/

GrandmaGlassesRopeMan’s picture

- The .attr() method returns a cross browser undefined for attributes that have not been set. jQuery Docs. No more scary symbol typeof helper.
- Fix übernit.

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

👍

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Needs work

Improvement looks good, thanks! Only two small things I found:

  1. +++ b/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php
    @@ -48,4 +54,25 @@ public function testToolbarToggling() {
    +   * Tests a toolbar with the first item being only an item.
    

    Can we somehow make this more clear? An item being an item, is well, what an item is.

  2. +++ b/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php
    @@ -48,4 +54,25 @@ public function testToolbarToggling() {
    +    // Ensure that there is not active tab by default.
    

    not => no

GrandmaGlassesRopeMan’s picture

Status: Needs work » Needs review
FileSize
5.44 KB
916 bytes

- #20.1 - I think this is more clear now?
- #20.2 - 👍🏿

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: -JavaScript +JavaScript, +Bug Smash Initiative, +Needs reroll
karishmaamin’s picture

Status: Needs work » Needs review
FileSize
5.4 KB

Re-rolled patch againt 9.5.x. Please review

smustgrave’s picture

Status: Needs review » Needs work

Looks like an issue with the patch

AkashKumar07’s picture

Status: Needs work » Needs review
FileSize
5.42 KB
704 bytes

Fixing the reported prettier/prettier issue.

smustgrave’s picture

Status: Needs review » Needs work

Looks like the patch is still having issues.

You can run core/scripts/dev/commit-code-check.sh to check the code before making the patch.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
FileSize
144 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Gauravvvv’s picture

Status: Needs work » Needs review
FileSize
4.54 KB

Re-rolled patch for 10.1.x, Please review

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

This was already rtbc in #19 and the 2 things that were requested by @Gábor Hojtsy have been fixed. Looks good to me.

luenemann’s picture

Component: tour.module » toolbar.module

I guess it's not about tour.module.

longwave’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php
@@ -50,6 +55,7 @@ public function testToolbarToggling() {
+    $this->createScreenshot('/tmp/foo.png');

Stray debug code in the test.

Rishabh Vishwakarma’s picture

Status: Needs work » Needs review
FileSize
3.99 KB
861 bytes

Removed the extra code as suggested in #42

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 43: 2885755-43.patch, failed testing. View results

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.