Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove sticky-menu class preventing full admin page scroll #11308

Merged
merged 3 commits into from
Nov 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion packages/edit-post/src/components/fullscreen-mode/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,25 @@
import { Component } from '@wordpress/element';
import { withSelect } from '@wordpress/data';

class FullscreenMode extends Component {
export class FullscreenMode extends Component {
componentDidMount() {
this.isSticky = false;
this.sync();

// `is-fullscreen-mode` is set in PHP as a body class by Gutenberg, and this causes
// `sticky-menu` to be applied by WordPress and prevents the admin menu being scrolled
// even if `is-fullscreen-mode` is then removed. Let's remove `sticky-menu` here as
// a consequence of the FullscreenMode setup
if ( document.body.classList.contains( 'sticky-menu' ) ) {
this.isSticky = true;
document.body.classList.remove( 'sticky-menu' );
}
}

componentWillUnmount() {
if ( this.isSticky ) {
document.body.classList.add( 'sticky-menu' );
}
}

componentDidUpdate( prevProps ) {
Expand Down
40 changes: 40 additions & 0 deletions packages/edit-post/src/components/fullscreen-mode/test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* External dependencies
*/
import { shallow } from 'enzyme';

/**
* Internal dependencies.
*/
import { FullscreenMode } from '..';

describe( 'FullscreenMode', () => {
it( 'fullscreen mode to be added to document body when active', () => {
shallow( <FullscreenMode isActive={ true } /> );

expect( document.body.classList.contains( 'is-fullscreen-mode' ) ).toBe( true );
} );

it( 'fullscreen mode not to be added to document body when active', () => {
shallow( <FullscreenMode isActive={ false } /> );

expect( document.body.classList.contains( 'is-fullscreen-mode' ) ).toBe( false );
} );

it( 'sticky-menu to be removed from the body class if present', () => {
document.body.classList.add( 'sticky-menu' );

shallow( <FullscreenMode isActive={ false } /> );

expect( document.body.classList.contains( 'sticky-menu' ) ).toBe( false );
} );

it( 'sticky-menu to be restored when component unmounted and originally present', () => {
document.body.classList.add( 'sticky-menu' );

const mode = shallow( <FullscreenMode isActive={ false } /> );
mode.unmount();

expect( document.body.classList.contains( 'sticky-menu' ) ).toBe( true );
} );
} );