Table of contents Collapse/Expand not working

Bug: T327064
Change-Id: Ica3b43d51169d33b01d7203c3672c301e775ec04
(cherry picked from commit 96ff431213)
This commit is contained in:
Moh'd Khier Abualruz 2023-01-16 18:06:30 +01:00 committed by Jdrewniak
parent 45ce966148
commit 0f7baf9e86

View file

@ -79,6 +79,7 @@ module.exports = function tableOfContents( props ) {
let SECTION_CLASS = 'sidebar-toc-list-item';
let ACTIVE_SECTION_CLASS = 'sidebar-toc-list-item-active';
let EXPANDED_SECTION_CLASS = 'sidebar-toc-list-item-expanded';
let SIDEBAR_EXPANDED_SECTION_CLASS = 'sidebar-toc-list-item-expanded';
let TOP_SECTION_CLASS = 'sidebar-toc-level-1';
let ACTIVE_TOP_SECTION_CLASS = 'sidebar-toc-level-1-active';
let LINK_CLASS = 'sidebar-toc-link';
@ -239,6 +240,7 @@ module.exports = function tableOfContents( props ) {
if ( topSection && toggle && expandedSections.indexOf( topSection ) < 0 ) {
toggle.setAttribute( 'aria-expanded', 'true' );
topSection.classList.add( EXPANDED_SECTION_CLASS );
topSection.classList.add( SIDEBAR_EXPANDED_SECTION_CLASS );
expandedSections.push( topSection );
}
}
@ -292,6 +294,7 @@ module.exports = function tableOfContents( props ) {
if ( isSelected && toggle && toggle.length > 0 ) {
toggle[ 0 ].setAttribute( 'aria-expanded', 'false' );
section.classList.remove( EXPANDED_SECTION_CLASS );
section.classList.remove( SIDEBAR_EXPANDED_SECTION_CLASS );
return false;
}
return true;
@ -319,7 +322,7 @@ module.exports = function tableOfContents( props ) {
function initializeExpandedStatus() {
const parentSections = props.container.querySelectorAll( `.${TOP_SECTION_CLASS}` );
parentSections.forEach( ( section ) => {
const expanded = section.classList.contains( EXPANDED_SECTION_CLASS );
const expanded = section.classList.contains( EXPANDED_SECTION_CLASS ) || section.classList.contains( SIDEBAR_EXPANDED_SECTION_CLASS );
const toggle = section.querySelector( `.${TOGGLE_CLASS}` );
if ( toggle ) {
toggle.setAttribute( 'aria-expanded', expanded.toString() );
@ -378,6 +381,7 @@ module.exports = function tableOfContents( props ) {
SECTION_CLASS = 'vector-toc-list-item';
ACTIVE_SECTION_CLASS = 'vector-toc-list-item-active';
EXPANDED_SECTION_CLASS = 'vector-toc-list-item-expanded';
SIDEBAR_EXPANDED_SECTION_CLASS = 'sidebar-toc-list-item-expanded';
TOP_SECTION_CLASS = 'vector-toc-level-1';
ACTIVE_TOP_SECTION_CLASS = 'vector-toc-level-1-active';
LINK_CLASS = 'vector-toc-link';