Skip to content

Commit f233fe1

Browse files
committed
fix(pat autotoc): Fix fieldset ID and refactor TOC navigation.
1 parent d99627e commit f233fe1

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/pat/autotoc/autotoc.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,22 @@ export default Base.extend({
4747
var activeId = null;
4848

4949
$(self.options.levels, self.$el).each(function (i) {
50-
const section = this.closest(self.options.section);
5150
const $level = $(this);
52-
let id = $level.prop("id") ? $level.prop("id") : $(section).prop("id");
51+
const $section = $level.closest(self.options.section);
52+
let id = $section.prop("id") || $level.prop("id");
5353

54-
if (!id || $("#" + id).length > 0) {
54+
if (!asTabs || !id || $(`#${id}`).length > 1) {
5555
id = self.options.IDPrefix + self.name + "-" + i;
5656
}
57+
58+
const tabId = `${id}-tab`;
59+
60+
if (!asTabs) {
61+
$level.attr("id", id).attr("aria-labelledby", tabId);
62+
} else {
63+
$section.attr("id", id).attr("aria-labelledby", tabId);
64+
}
65+
5766
if (window.location.hash === "#" + id) {
5867
activeId = id;
5968
}
@@ -114,23 +123,15 @@ export default Base.extend({
114123
$level.data("autotoc-trigger-id", id);
115124

116125
self.tabs.push({
117-
section: section,
126+
section: $section[0],
118127
id: id,
119128
nav: $nav[0],
120129
});
121130
});
122131

123-
if (activeId) {
124-
$("a#" + activeId).trigger("click", {
125-
doScroll: true,
126-
skipHash: true,
127-
});
128-
} else {
129-
self.$toc.find("a").first().trigger("click", {
130-
doScroll: false,
131-
skipHash: true,
132-
});
133-
}
132+
const activeTabButton = activeId ? self.$toc.find("a#" + activeId)[0] : self.$toc.find("a").first()[0];
133+
const tab = Tab.getOrCreateInstance(activeTabButton);
134+
tab.show();
134135

135136
// After DOM tree is built, initialize eventual validation
136137
this.initialize_validation(self.$el);

0 commit comments

Comments
 (0)