Disable table of contents toggle on VE activation

While the table of contents is not updated by VisualEditor
we should hide it.

Bug: T307900
Change-Id: I246fbe0069329ef78735147b8d3f280433155158
This commit is contained in:
Jon Robson 2022-06-10 14:20:07 -07:00
parent 93e8cfcd90
commit 5fdd66fa3b
2 changed files with 16 additions and 0 deletions

View file

@ -323,6 +323,14 @@ module.exports = function tableOfContents( props ) {
// Bind event listeners.
bindClickListener();
// Hide TOC button on VE activation
mw.hook( 've.activationStart' ).add( () => {
const tocButton = document.getElementById( 'vector-toc-collapsed-button' );
if ( tocButton ) {
tocButton.style.display = 'none';
}
} );
}
initialize();

View file

@ -95,6 +95,13 @@ describe( 'Table of contents', () => {
beforeEach( () => {
// @ts-ignore
global.window.matchMedia = jest.fn( () => ( {} ) );
// @ts-ignore
global.mw = {
hook: jest.fn( () => ( {
add: () => {}
} ) )
};
} );
describe( 'renders', () => {
@ -190,6 +197,7 @@ describe( 'Table of contents', () => {
const toggleButton = /** @type {HTMLElement} */ ( barSection.querySelector( `.${toc.TOGGLE_CLASS}` ) );
expect( toggleButton.getAttribute( 'aria-expanded' ) ).toEqual( 'true' );
expect( mw.hook ).toBeCalledWith( 've.activationStart' );
} );
test( 'when expanding sections', () => {