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

Fullscreen Mode: Change the "Back" button to toggle the sidebar #21121

Merged
merged 24 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3428949
A quick and dirty try at making the wp-admin sidebar accessible while…
shaunandrews Mar 24, 2020
fa9c5ce
Back to the dark background by default, and accounting for the `folde…
shaunandrews Mar 24, 2020
ccfdb6e
Making the WP logo just a little smaller.
shaunandrews Mar 26, 2020
3b04e76
Improve interaction handling for Navigation menu logo
Apr 1, 2020
06925b2
Adjust click outside to close logic
Apr 1, 2020
76824a9
A quick and dirty try at making the wp-admin sidebar accessible while…
shaunandrews Mar 24, 2020
e435096
Fix SVG color and pointer events
Apr 1, 2020
d0cb8f3
Rename fullscreen-mode-close to admin-menu-toggle
Apr 1, 2020
3b2e3a3
Fix classNames and imports for renamed admin-menu-toggle
Apr 1, 2020
13b2cb6
Focus Admin Menu on TAB press when open
Apr 1, 2020
4f85339
Make sure the top toolbar moves when the menu is opened.
shaunandrews Apr 2, 2020
28efc8e
Adjusting focus state to use new line-width, making the button a litt…
shaunandrews Apr 2, 2020
746f9e6
Improve admin menu keyboard navigation in open/close states
Apr 3, 2020
87ff44b
Updating classNames after a rebase.
shaunandrews Apr 7, 2020
f134242
Moving to toggle button from edit-post into the interface package so …
shaunandrews Apr 9, 2020
3946045
Oops, forgot to remove this.
shaunandrews Apr 10, 2020
baab65c
Updating classnames.
shaunandrews Apr 10, 2020
96e2d94
Replacing the FullscreenModeClose component with the new AdminMenuTog…
shaunandrews Apr 10, 2020
e1ff1cd
Removing the .js selector.
shaunandrews Apr 10, 2020
70d046d
Moving the display logic out of the component and into the places whe…
shaunandrews Apr 14, 2020
e5ce2f6
Update package-lock and e2e test
Apr 14, 2020
edb8102
Refactor event bindings in relation to state within admin-menu-toggle
Apr 15, 2020
84a3da5
Refactoring the transition to avoid a display bug in Safari.
shaunandrews Apr 21, 2020
d55ad2c
Update package-lock.json
Apr 22, 2020
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
7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,5 @@ describe( 'Fullscreen Mode', () => {
} );

expect( isFullscreenEnabled ).toBe( true );

const fullscreenCloseButton = await page.$(
'.edit-post-fullscreen-mode-close'
);

expect( fullscreenCloseButton ).not.toBeNull();
} );
} );

This file was deleted.

This file was deleted.

9 changes: 6 additions & 3 deletions packages/edit-post/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import { Button } from '@wordpress/components';
import { PostPreviewButton, PostSavedState } from '@wordpress/editor';
import { useSelect, useDispatch } from '@wordpress/data';
import { cog } from '@wordpress/icons';
import { PinnedItems } from '@wordpress/interface';
import { PinnedItems, AdminMenuToggle } from '@wordpress/interface';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's not a component, but the is an existing thing that collapses the admin menu. I'm not sure what it's called, but it's at the bottom of the menu. I think using the name AdminMenuToggle could be a bit confusing since one already exists. I'm not sure why the existing one isn't used for this fullscreen thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I think of the #collapse-button option that exists at the bottom of the menu as a different feature; The collapse button changes the width of the admin sidebar, not the visibility.

This new AdminMenuToggle component toggles the visibility.

The two features can work together; You can collapse the admin sidebar and toggle its visibility.


/**
* Internal dependencies
*/
import FullscreenModeClose from './fullscreen-mode-close';
import HeaderToolbar from './header-toolbar';
import MoreMenu from './more-menu';
import PostPublishButtonOrToggle from './post-publish-button-or-toggle';
Expand All @@ -25,6 +24,7 @@ function Header( { onToggleInserter, isInserterOpen } ) {
isPublishSidebarOpened,
isSaving,
getBlockSelectionStart,
isFullscreenActive,
} = useSelect(
( select ) => ( {
shortcut: select(
Expand All @@ -40,6 +40,9 @@ function Header( { onToggleInserter, isInserterOpen } ) {
isSaving: select( 'core/edit-post' ).isSavingMetaBoxes(),
getBlockSelectionStart: select( 'core/block-editor' )
.getBlockSelectionStart,
isFullscreenActive: select( 'core/edit-post' ).isFeatureActive(
'fullscreenMode'
),
} ),
[]
);
Expand All @@ -58,7 +61,7 @@ function Header( { onToggleInserter, isInserterOpen } ) {

return (
<div className="edit-post-header">
<FullscreenModeClose />
{ isFullscreenActive && <AdminMenuToggle /> }
<div className="edit-post-header__toolbar">
<HeaderToolbar
onToggleInserter={ onToggleInserter }
Expand Down
1 change: 0 additions & 1 deletion packages/edit-post/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ $footer-height: $button-size-small;
@import "../../interface/src/style.scss";

@import "./components/header/style.scss";
@import "./components/header/fullscreen-mode-close/style.scss";
@import "./components/header/header-toolbar/style.scss";
@import "./components/header/more-menu/style.scss";
@import "./components/keyboard-shortcut-help-modal/style.scss";
Expand Down

This file was deleted.

This file was deleted.

16 changes: 13 additions & 3 deletions packages/edit-site/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import {
ToolSelector,
Inserter,
} from '@wordpress/block-editor';
import { PinnedItems } from '@wordpress/interface';
import { useSelect } from '@wordpress/data';
import { PinnedItems, AdminMenuToggle } from '@wordpress/interface';

/**
* Internal dependencies
*/
import { useEditorContext } from '../editor';
import FullscreenModeClose from './fullscreen-mode-close';
import MoreMenu from './more-menu';
import TemplateSwitcher from '../template-switcher';
import SaveButton from '../save-button';
Expand Down Expand Up @@ -49,9 +49,19 @@ export default function Header() {
} ) ),
[]
);

const { isFullscreenActive } = useSelect(
( select ) => ( {
isFullscreenActive: select( 'core/edit-site' ).isFeatureActive(
'fullscreenMode'
),
} ),
[]
);

return (
<div className="edit-site-header">
<FullscreenModeClose />
{ isFullscreenActive && <AdminMenuToggle /> }
<div className="edit-site-header__toolbar">
<Inserter
position="bottom right"
Expand Down
1 change: 0 additions & 1 deletion packages/edit-site/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

@import "./components/block-editor/style.scss";
@import "./components/header/style.scss";
@import "./components/header/fullscreen-mode-close/style.scss";
@import "./components/header/more-menu/style.scss";
@import "./components/notices/style.scss";
@import "./components/sidebar/style.scss";
Expand Down
1 change: 1 addition & 0 deletions packages/interface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@wordpress/element": "file:../element",
"@wordpress/i18n": "file:../i18n",
"@wordpress/icons": "file:../icons",
"@wordpress/keycodes": "file:../keycodes",
"@wordpress/plugins": "file:../plugins",
"classnames": "^2.2.5",
"lodash": "^4.17.15"
Expand Down
105 changes: 105 additions & 0 deletions packages/interface/src/components/admin-menu-toggle/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
* WordPress dependencies
*/
import { Button } from '@wordpress/components';
import { useRef, useEffect, useState } from '@wordpress/element';
import { ESCAPE, TAB } from '@wordpress/keycodes';
import { __ } from '@wordpress/i18n';
import { wordpress } from '@wordpress/icons';

function AdminMenuToggle() {
const buttonRef = useRef();
const toggleMenu = useToggle( { ref: buttonRef } );

return (
<Button
className="interface-admin-menu-toggle"
icon={ wordpress }
iconSize={ 36 }
onClick={ toggleMenu }
label={ __( 'Show sidebar menu' ) }
ref={ buttonRef }
/>
);
}

function useToggle( { ref } ) {
const [ isActive, setIsActive ] = useState( false );
const buttonNode = ref?.current;

const adminMenuNode = document.querySelector( '#adminmenumain' );

const toggleClassName = 'is-showing-admin-menu';

const toggleAdminMenu = () => setIsActive( ! isActive );
const closeAdminMenu = () => setIsActive( false );

const focusFirstAdminMenuItem = () => {
if ( ! buttonNode ) return;

const isButtonFocused = buttonNode.matches( ':focus' );
const item = adminMenuNode.querySelector( '#adminmenu > li > a' );

if ( isButtonFocused && item ) {
item.focus();
}
};

// Renders the open/closed UI for the admin menu
useEffect( () => {
if ( isActive ) {
document.body.classList.add( toggleClassName );
} else {
document.body.classList.remove( toggleClassName );
}
}, [ isActive ] );

// Handles closing the admin menu when clicking outside
useEffect( () => {
const handleOnClickOutside = ( event ) => {
if ( ! isActive ) return;

const { target } = event;

const didClickOutside =
! adminMenuNode.contains( target ) && target !== buttonNode;

if ( didClickOutside ) {
closeAdminMenu();
}
};

document.body.addEventListener( 'click', handleOnClickOutside );

return () => {
document.body.removeEventListener( 'click', handleOnClickOutside );
};
}, [ isActive, buttonNode ] );

// Handles admin menu keyboard interactions
useEffect( () => {
const handleOnKeyDown = ( event ) => {
if ( ! isActive ) return;

const { keyCode } = event;

if ( keyCode === ESCAPE ) {
closeAdminMenu();
}

if ( keyCode === TAB ) {
focusFirstAdminMenuItem();
}
};

document.body.addEventListener( 'keydown', handleOnKeyDown );

return () => {
document.body.removeEventListener( 'keydown', handleOnKeyDown );
};
}, [ isActive ] );

return toggleAdminMenu;
}

export default AdminMenuToggle;
Loading