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

Distraction Free: Avoid focus loss when enabling/disabling distraction free mode via the more menu #51627

Merged
merged 2 commits into from
Jun 20, 2023
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
9 changes: 2 additions & 7 deletions packages/edit-post/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ function Header( { setEntitiesSavedStatesCallback } ) {
isPublishSidebarOpened,
isSaving,
showIconLabels,
isDistractionFreeMode,
} = useSelect(
( select ) => ( {
hasActiveMetaboxes: select( editPostStore ).hasMetaBoxes(),
Expand All @@ -36,21 +35,17 @@ function Header( { setEntitiesSavedStatesCallback } ) {
isSaving: select( editPostStore ).isSavingMetaBoxes(),
showIconLabels:
select( editPostStore ).isFeatureActive( 'showIconLabels' ),
isDistractionFreeMode:
select( editPostStore ).isFeatureActive( 'distractionFree' ),
} ),
[]
);

const isDistractionFree = isDistractionFreeMode && isLargeViewport;

const slideY = {
hidden: isDistractionFree ? { y: '-50' } : { y: 0 },
hidden: { y: '-50px' },
hover: { y: 0, transition: { type: 'tween', delay: 0.2 } },
};

const slideX = {
hidden: isDistractionFree ? { x: '-100%' } : { x: 0 },
hidden: { x: '-100%' },
hover: { x: 0, transition: { type: 'tween', delay: 0.2 } },
};

Expand Down
10 changes: 0 additions & 10 deletions packages/edit-post/src/components/header/writing-menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,16 @@ function WritingMenu() {
[]
);

const blocks = useSelect(
( select ) => select( blockEditorStore ).getBlocks(),
[]
);

const { setIsInserterOpened, setIsListViewOpened, closeGeneralSidebar } =
useDispatch( postEditorStore );
const { set: setPreference } = useDispatch( preferencesStore );

const { selectBlock } = useDispatch( blockEditorStore );

const toggleDistractionFree = () => {
registry.batch( () => {
setPreference( 'core/edit-post', 'fixedToolbar', false );
setIsInserterOpened( false );
setIsListViewOpened( false );
closeGeneralSidebar();
if ( ! isDistractionFree && !! blocks.length ) {
selectBlock( blocks[ 0 ].clientId );
}
} );
};

Expand Down
36 changes: 23 additions & 13 deletions packages/interface/src/components/interface-skeleton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ function InterfaceSkeleton(
const mergedLabels = { ...defaultLabels, ...labels };

const headerVariants = {
hidden: isDistractionFree ? { opacity: 0 } : { opacity: 1 },
hidden: { opacity: 0 },
draganescu marked this conversation as resolved.
Show resolved Hide resolved
hover: {
opacity: 1,
transition: { type: 'tween', delay: 0.2, delayChildren: 0.2 },
},
distractionFreeInactive: { opacity: 1, transition: { delay: 0 } },
};

return (
Expand All @@ -97,23 +98,32 @@ function InterfaceSkeleton(
) }
>
<div className="interface-interface-skeleton__editor">
{ !! header && isDistractionFree && (
{ !! header && (
<NavigableRegion
as={ motion.div }
className="interface-interface-skeleton__header"
aria-label={ mergedLabels.header }
initial={ isDistractionFree ? 'hidden' : 'hover' }
whileHover="hover"
initial={
isDistractionFree
? 'hidden'
: 'distractionFreeInactive'
}
whileHover={
isDistractionFree
? 'hover'
: 'distractionFreeInactive'
}
animate={
isDistractionFree
? 'hidden'
: 'distractionFreeInactive'
}
variants={ headerVariants }
transition={ { type: 'tween', delay: 0.8 } }
>
{ header }
</NavigableRegion>
) }
{ !! header && ! isDistractionFree && (
<NavigableRegion
className="interface-interface-skeleton__header"
ariaLabel={ mergedLabels.header }
transition={
isDistractionFree
? { type: 'tween', delay: 0.8 }
: undefined
}
>
{ header }
</NavigableRegion>
Expand Down
Loading