@@ -405,30 +405,48 @@ function setAlgolia(latestVersion) {
405405 } ) ;
406406}
407407$ ( document ) . ready ( function ( ) {
408+ // Initialize tabs: create nav items from tab panes
408409 $ ( ".tab-content" )
409410 . find ( ".tab-pane" )
410411 . each ( function ( idx , item ) {
411412 const navTabs = $ ( this ) . closest ( ".tabs" ) . find ( ".nav-tabs" ) ;
412413 const title = $ ( this ) . attr ( "title" ) ;
413- navTabs . append ( `<li><a href="#">${ title } </a></li>` ) ;
414+ navTabs . append ( `<li><a href="#" role="button" tabindex="0" >${ title } </a></li>` ) ;
414415 } ) ;
415416
417+ // Set first tab as active in each tab group
416418 $ ( ".tabs ul.nav-tabs" ) . each ( function ( ) {
417419 $ ( this ) . find ( "li:first" ) . addClass ( "active" ) ;
418420 } ) ;
419421
422+ // Set first pane as active in each tab group
420423 $ ( ".tabs .tab-content" ) . each ( function ( ) {
421424 $ ( this ) . find ( "div:first" ) . addClass ( "active" ) ;
422425 } ) ;
423426
424- $ ( ".nav-tabs a" ) . click ( function ( e ) {
427+ // Use event delegation for tab switching (works even if tabs are added dynamically)
428+ $ ( document ) . on ( "click" , ".nav-tabs a" , function ( e ) {
425429 e . preventDefault ( ) ;
426- const tab = $ ( this ) . parent ( ) ;
430+ e . stopPropagation ( ) ;
431+ const tab = $ ( this ) . parent ( "li" ) ;
427432 const tabIndex = tab . index ( ) ;
428433 const tabPanel = $ ( this ) . closest ( ".tabs" ) ;
429434 const tabPane = tabPanel . find ( ".tab-pane" ) . eq ( tabIndex ) ;
430- tabPanel . find ( ".active" ) . removeClass ( "active" ) ;
435+
436+ // Remove active class from all tabs and panes in this group
437+ tabPanel . find ( ".nav-tabs li" ) . removeClass ( "active" ) ;
438+ tabPanel . find ( ".tab-pane" ) . removeClass ( "active" ) ;
439+
440+ // Add active class to clicked tab and corresponding pane
431441 tab . addClass ( "active" ) ;
432442 tabPane . addClass ( "active" ) ;
433443 } ) ;
444+
445+ // Also support keyboard navigation (Enter/Space)
446+ $ ( document ) . on ( "keydown" , ".nav-tabs a" , function ( e ) {
447+ if ( e . key === "Enter" || e . key === " " ) {
448+ e . preventDefault ( ) ;
449+ $ ( this ) . click ( ) ;
450+ }
451+ } ) ;
434452} ) ;
0 commit comments