@@ -78,16 +78,21 @@ export default Base.extend({
7878 var activeId = null ;
7979
8080 $ ( self . options . levels , self . $el ) . each ( function ( i ) {
81- const section = this . closest ( self . options . section ) ;
8281 const $level = $ ( this ) ;
83- let id = $level . prop ( "id" ) ? $level . prop ( "id" ) : $ ( section ) . prop ( "id" ) ;
82+ const $section = $level . closest ( self . options . section ) ;
83+ let id = $section . prop ( "id" ) || $level . prop ( "id" ) ;
8484
85- if ( ! id || $ ( "#" + id ) . length > 0 ) {
85+ if ( ! asTabs || ! id || $ ( `# ${ id } ` ) . length > 1 ) {
8686 id = self . options . IDPrefix + self . name + "-" + i ;
8787 }
8888
8989 const tabId = `${ id } -tab` ;
90- $ ( section ) . attr ( "id" , id ) . attr ( "aria-labelledby" , tabId ) ;
90+
91+ if ( ! asTabs ) {
92+ $level . attr ( "id" , id ) . attr ( "aria-labelledby" , tabId ) ;
93+ } else {
94+ $section . attr ( "id" , id ) . attr ( "aria-labelledby" , tabId ) ;
95+ }
9196
9297 if ( window . location . hash === "#" + id ) {
9398 activeId = tabId ;
@@ -156,25 +161,15 @@ export default Base.extend({
156161 $level . data ( "autotoc-trigger-id" , id ) ;
157162
158163 self . tabs . push ( {
159- section : section ,
164+ section : $ section[ 0 ] ,
160165 id : id ,
161166 nav : $nav [ 0 ] ,
162167 } ) ;
163168 } ) ;
164169
165- if ( activeId ) {
166- const activeTabButton = self . $toc . find ( "a#" + activeId ) [ 0 ] ;
167- if ( activeTabButton ) {
168- const tab = Tab . getOrCreateInstance ( activeTabButton ) ;
169- tab . show ( ) ;
170- }
171- } else {
172- const firstTabButton = self . $toc . find ( "a" ) . first ( ) [ 0 ] ;
173- if ( firstTabButton ) {
174- const tab = Tab . getOrCreateInstance ( firstTabButton ) ;
175- tab . show ( ) ;
176- }
177- }
170+ const activeTabButton = activeId ? self . $toc . find ( "a#" + activeId ) [ 0 ] : self . $toc . find ( "a" ) . first ( ) [ 0 ] ;
171+ const tab = Tab . getOrCreateInstance ( activeTabButton ) ;
172+ tab . show ( ) ;
178173
179174 // After DOM tree is built, initialize eventual validation
180175 this . initialize_validation ( ) ;
0 commit comments