Skip to content

Commit 295bf67

Browse files
fenstratmarkhalliwell
fenstrat
authored andcommitted
Issue #2985470 by fenstrat: Fragment links to children elements in closed vertical tabs don't work
1 parent 97e3d9f commit 295bf67

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

js/misc/vertical-tabs.js

+22
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@
66
(function ($, window, Drupal, drupalSettings) {
77
"use strict";
88

9+
/**
10+
* Show the parent vertical tab pane of a targeted page fragment.
11+
*
12+
* In order to make sure a targeted element inside a vertical tab pane is
13+
* visible on a hash change or fragment link click, show all parent panes.
14+
*
15+
* @param {jQuery.Event} e
16+
* The event triggered.
17+
* @param {jQuery} $target
18+
* The targeted node as a jQuery object.
19+
*/
20+
var handleFragmentLinkClickOrHashChange = function handleFragmentLinkClickOrHashChange(e, $target) {
21+
$target.parents('.vertical-tabs-pane').each(function (index, pane) {
22+
$(pane).data('verticalTab').focus();
23+
});
24+
};
25+
926
/**
1027
* This script transforms a set of details into a stack of vertical
1128
* tabs. Another tab pane can be selected by clicking on the respective
@@ -26,6 +43,11 @@
2643
return;
2744
}
2845

46+
/**
47+
* Binds a listener to handle fragment link clicks and URL hash changes.
48+
*/
49+
$('body').once('vertical-tabs-fragments').on('formFragmentLinkClickOrHashChange.verticalTabs', handleFragmentLinkClickOrHashChange);
50+
2951
$(context).find('[data-vertical-tabs-panes]').once('vertical-tabs').each(function () {
3052
var $this = $(this).addClass('tab-content vertical-tabs-panes');
3153

0 commit comments

Comments
 (0)