-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Make SiteHub available in mobile viewports #63060
Changes from all commits
27304cc
a0b5c93
03f524b
983d89f
db284b1
4401f60
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,13 +153,13 @@ export default function Layout( { route } ) { | |
} } | ||
className="edit-site-layout__sidebar" | ||
> | ||
<SiteHub | ||
ref={ toggleRef } | ||
isTransparent={ | ||
isResizableFrameOversized | ||
} | ||
/> | ||
<SidebarContent routeKey={ routeKey }> | ||
<SiteHub | ||
ref={ toggleRef } | ||
isTransparent={ | ||
isResizableFrameOversized | ||
} | ||
/> | ||
{ areas.sidebar } | ||
</SidebarContent> | ||
<SaveHub /> | ||
|
@@ -174,6 +174,16 @@ export default function Layout( { route } ) { | |
|
||
{ isMobileViewport && areas.mobile && ( | ||
<div className="edit-site-layout__mobile"> | ||
{ canvasMode !== 'edit' && ( | ||
<SidebarContent routeKey={ routeKey }> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jsnajdr if you have any thoughts here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
2024-07-04.12.04.19.mp4Edit: After re-checking out this branch I can't reproduce the above 🤔 |
||
<SiteHub | ||
ref={ toggleRef } | ||
isTransparent={ | ||
isResizableFrameOversized | ||
} | ||
/> | ||
</SidebarContent> | ||
) } | ||
{ areas.mobile } | ||
</div> | ||
) } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,24 +8,35 @@ import clsx from 'clsx'; | |
*/ | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { Button, __experimentalHStack as HStack } from '@wordpress/components'; | ||
import { useViewportMatch } from '@wordpress/compose'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
import { decodeEntities } from '@wordpress/html-entities'; | ||
import { memo, forwardRef } from '@wordpress/element'; | ||
import { memo, forwardRef, useContext } from '@wordpress/element'; | ||
import { search } from '@wordpress/icons'; | ||
import { store as commandsStore } from '@wordpress/commands'; | ||
import { displayShortcut } from '@wordpress/keycodes'; | ||
import { filterURLForDisplay } from '@wordpress/url'; | ||
import { privateApis as routerPrivateApis } from '@wordpress/router'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as editSiteStore } from '../../store'; | ||
import SiteIcon from '../site-icon'; | ||
import { unlock } from '../../lock-unlock'; | ||
const { useHistory } = unlock( routerPrivateApis ); | ||
import { SidebarNavigationContext } from '../sidebar'; | ||
|
||
const SiteHub = memo( | ||
forwardRef( ( { isTransparent }, ref ) => { | ||
const isMobileViewport = useViewportMatch( 'medium', '<' ); | ||
const history = useHistory(); | ||
const { navigate } = useContext( SidebarNavigationContext ); | ||
const isRoot = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a better way to detect we are in the root? This relies on the The sidebar uses a explicit |
||
history.location.pathname === '/wp-admin/site-editor.php' && | ||
history.location.search === ''; | ||
|
||
const { dashboardLink, homeUrl, siteTitle } = useSelect( ( select ) => { | ||
const { getSettings } = unlock( select( editSiteStore ) ); | ||
|
||
|
@@ -57,18 +68,37 @@ const SiteHub = memo( | |
} | ||
) } | ||
> | ||
<Button | ||
ref={ ref } | ||
href={ dashboardLink } | ||
label={ __( 'Go to the Dashboard' ) } | ||
className="edit-site-layout__view-mode-toggle" | ||
style={ { | ||
transform: 'scale(0.5)', | ||
borderRadius: 4, | ||
} } | ||
> | ||
<SiteIcon className="edit-site-layout__view-mode-toggle-icon" /> | ||
</Button> | ||
{ ( isRoot || ! isMobileViewport ) && ( | ||
<Button | ||
ref={ ref } | ||
href={ dashboardLink } | ||
label={ __( 'Go to the Dashboard' ) } | ||
className="edit-site-layout__view-mode-toggle" | ||
style={ { | ||
transform: 'scale(0.5)', | ||
borderRadius: 4, | ||
} } | ||
> | ||
<SiteIcon className="edit-site-layout__view-mode-toggle-icon" /> | ||
</Button> | ||
) } | ||
{ isMobileViewport && ( | ||
<Button | ||
ref={ ref } | ||
label={ __( 'Go to Site Editor' ) } | ||
className="edit-site-layout__view-mode-toggle" | ||
style={ { | ||
transform: 'scale(0.5)', | ||
borderRadius: 4, | ||
} } | ||
onClick={ () => { | ||
history.push( {} ); | ||
navigate( 'back' ); | ||
} } | ||
> | ||
<SiteIcon className="edit-site-layout__view-mode-toggle-icon" /> | ||
</Button> | ||
) } | ||
</div> | ||
|
||
<HStack> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately it looks like moving the
SiteHub
to be a child ofSidebarContent
means that the side bar content's focusing behaviour now matches against the buttons within the site hub, which causes one of the e2e tests to fail ('Can use keyboard to navigate the site editor'
).From testing manually it seems that what's happening is that if you navigate to the Pages button from the root and hit Enter, when you're taken to the pages screen, the W icon is focused instead of the back button. I.e. here's where focus now lands:
Here's the function that handles the focusing:
gutenberg/packages/edit-site/src/components/sidebar/index.js
Line 22 in 4866c3b
I'm wondering if we need to either have a way for that focusing to skip the site hub and just look at the sidebar area, or if we need a way to give the site hub access to the navigation context without the other wrapping logic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've pushed a commit in 4401f60 that hopefully addresses the focus issue 🤞. It's a little hacky but let's see if it gets the test passing.