Identified Problem

In quicktabs.js, the constructor for the individual tab (Drupal.quicktabs.tab) is determining the tabKey value unreliably. Currently, there is a for loop that just sets the loop index as the value for the tabKey parameter.

Why this matters/What breaks?

When preventing empty quicktab content from being rendered (https://www.drupal.org/project/quicktabs/issues/2909326), the tab links to a corresponding tab content which is selected by using an ID which is determined by the tab's nth-element position. If there are tabs that are empty, the nth position is no longer a reliable index.

Proposed Solution

The tabKey should be set to an index that maps the quicktab to its corresponding content directly. There is an $index value that Quicktabs is already using as a tab index so we can add a data attribute to the quicktab link in QuickTabs.php: 'data-quicktabs-tab-index' => $index,

And instead of

  for (var i = 0; i < drupalSettings.quicktabs[qtKey].tabs.length; i++) {
    if (i == this.tabIndex) {
      this.tabObj = drupalSettings.quicktabs[qtKey].tabs[i];
      this.tabKey = i;
    }
  }

Set the tabKey as the quicktabs tab index value that we set in QuickTabs.php:

  for (var i = 0; i < drupalSettings.quicktabs[qtKey].tabs.length; i++) {
    if (i == this.tabIndex) {
      this.tabObj = drupalSettings.quicktabs[qtKey].tabs[i];
      this.tabKey = el.dataset.quicktabsTabIndex;
    }
  }

Comments

johnnydarkko created an issue. See original summary.

johnnydarkko’s picture

Status: Active » Needs review
StatusFileSize
new978 bytes

Created patch with the solution proposed above.

johnnydarkko’s picture

Status: Needs review » Needs work
StatusFileSize
new1.01 KB

The quicktabs tab index doesn't apply to views quicktabs. Created a patch that addresses the issue of quicktabs when the tab index doesn't exist.

johnnydarkko’s picture

Status: Needs work » Needs review

  • shelane committed 7f6bd12 on 8.x-3.x authored by johnnydarkko
    Issue #3008441 by johnnydarkko: quicktabs.js isn't reliably determining...
shelane’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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