Skip to content

Commit

Permalink
Reset active inserter when closing inserter panel
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed May 8, 2024
1 parent ba800c3 commit beba18c
Showing 1 changed file with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,27 @@ function Inserter( {
function ZoomOutModeInserters( { __unstableContentRef } ) {
const [ isReady, setIsReady ] = useState( false );
const [ activeInserter, setActiveInserter ] = useState( null );
const { blockOrder, sectionRootClientId } = useSelect( ( select ) => {
const { sectionRootClientId: root } = unlock(
select( blockEditorStore ).getSettings()
);
return {
blockOrder: select( blockEditorStore ).getBlockOrder( root ),
sectionRootClientId: root,
};
}, [] );
const { blockOrder, sectionRootClientId, blockInsertionPoint } = useSelect(
( select ) => {
const { sectionRootClientId: root } = unlock(
select( blockEditorStore ).getSettings()
);
return {
blockOrder: select( blockEditorStore ).getBlockOrder( root ),
// To do: move ZoomOutModeInserters to core/editor.
// eslint-disable-next-line @wordpress/data-no-store-string-literals
blockInsertionPoint: select( 'core/editor' ).isInserterOpened(),
sectionRootClientId: root,
};
},
[]
);

useEffect( () => {
if ( ! blockInsertionPoint ) {
setActiveInserter( null );
}
}, [ blockInsertionPoint ] );

// Defer the initial rendering to avoid the jumps due to the animation.
useEffect( () => {
Expand Down

0 comments on commit beba18c

Please sign in to comment.