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;
}
}| Comment | File | Size | Author |
|---|---|---|---|
| #3 | quicktabs-quicktabsjs_tabKey_fix-3008441-3.patch | 1.01 KB | johnnydarkko |
| #2 | quicktabs-quicktabsjs_tabKey_fix-3008441-1.patch | 978 bytes | johnnydarkko |
Comments
Comment #2
johnnydarkko commentedCreated patch with the solution proposed above.
Comment #3
johnnydarkko commentedThe 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.
Comment #4
johnnydarkko commentedComment #6
shelane