Skip to content

Commit

Permalink
Try restoring the site editor animation (#51956)
Browse files Browse the repository at this point in the history
* Try restoring the site editor animation

* fix header animation

* Remove accidental addition of layout prop

* tidy up formatting

* fix animate presence issue

* Fix animation between sidebar view and distraction free edit view

* Leave sidebar present and maintain canvas to
sidebar animation

The sidebar is necessary for routing on mobile so we have to maintain its presence in the DOM. Just hiding it isn't enough though, as it is still able to be reached with keyboard tabs and screen readers. Using the relatively new `inert` property disables the element from user interaction, so we add that when we don't want the sidebar to be shown.

* Fix mobile view for pattern library

On Mobile, the canvas mode wasn't being set to edit when using the pattern library. This updates it to use the showSidbar value instead, keeping it in sync with the inert setting.

---------

Co-authored-by: Saxon Fletcher <saxonafletcher@gmail.com>
Co-authored-by: Jerry Jones <jones.jeremydavid@gmail.com>
  • Loading branch information
3 people authored and tellthemachines committed Jul 17, 2023
1 parent 57ab3bd commit d733cc5
Showing 1 changed file with 38 additions and 43 deletions.
81 changes: 38 additions & 43 deletions packages/edit-site/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,66 +224,61 @@ export default function Layout() {
<AnimatePresence initial={ false }>
{ isEditorPage && isEditing && (
<NavigableRegion
key="header"
className="edit-site-layout__header"
ariaLabel={ __( 'Editor top bar' ) }
as={ motion.div }
variants={ {
isDistractionFree: { opacity: 0 },
isDistractionFreeHovering: { opacity: 1 },
view: { opacity: 1 },
edit: { opacity: 1 },
isDistractionFree: { opacity: 0, y: 0 },
isDistractionFreeHovering: {
opacity: 1,
y: 0,
},
view: { opacity: 1, y: '-100%' },
edit: { opacity: 1, y: 0 },
} }
exit={ {
y: '-100%',
} }
initial={ {
opacity: isDistractionFree ? 1 : 0,
y: isDistractionFree ? 0 : '-100%',
} }
transition={ {
type: 'tween',
duration: disableMotion ? 0 : 0.2,
ease: 'easeOut',
} }
>
{ isEditing && <Header /> }
<Header />
</NavigableRegion>
) }
</AnimatePresence>
</motion.div>

<div className="edit-site-layout__content">
<AnimatePresence initial={ false }>
{
<motion.div
initial={ {
opacity: 0,
} }
animate={
showSidebar
? { opacity: 1, display: 'block' }
: {
opacity: 0,
transitionEnd: {
display: 'none',
},
}
}
exit={ {
opacity: 0,
} }
transition={ {
type: 'tween',
duration:
// Disable transition in mobile to emulate a full page transition.
disableMotion || isMobileViewport
? 0
: ANIMATION_DURATION,
ease: 'easeOut',
} }
className="edit-site-layout__sidebar"
>
<NavigableRegion
ariaLabel={ __( 'Navigation' ) }
>
<Sidebar />
</NavigableRegion>
</motion.div>
}
</AnimatePresence>
<motion.div
// The sidebar is needed for routing on mobile
// (https://github.com/WordPress/gutenberg/pull/51558/files#r1231763003),
// so we can't remove the element entirely. Using `inert` will make
// it inaccessible to screen readers and keyboard navigation.
inert={ showSidebar ? undefined : 'inert' }
animate={ { opacity: showSidebar ? 1 : 0 } }
transition={ {
type: 'tween',
duration:
// Disable transition in mobile to emulate a full page transition.
disableMotion || isMobileViewport
? 0
: ANIMATION_DURATION,
ease: 'easeOut',
} }
className="edit-site-layout__sidebar"
>
<NavigableRegion ariaLabel={ __( 'Navigation' ) }>
<Sidebar />
</NavigableRegion>
</motion.div>

<SavePanel />

Expand Down

0 comments on commit d733cc5

Please sign in to comment.