Skip to content

Commit

Permalink
detect when sidebar is closed. pass selectedTabId of null
Browse files Browse the repository at this point in the history
  • Loading branch information
chad1008 committed Nov 17, 2023
1 parent a582154 commit 839acc4
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ const SIDEBAR_ACTIVE_BY_DEFAULT = Platform.select( {
} );

const SettingsSidebar = () => {
const { sidebarName, keyboardShortcut, isTemplateMode } = useSelect(
( select ) => {
const { sidebarName, isSidebarOpen, keyboardShortcut, isTemplateMode } =
useSelect( ( select ) => {
// The settings sidebar is used by the edit-post/document and edit-post/block sidebars.
// sidebarName represents the sidebar that is active or that should be active when the SettingsSidebar toggle button is pressed.
// If one of the two sidebars is active the component will contain the content of that sidebar.
Expand All @@ -51,6 +51,7 @@ const SettingsSidebar = () => {
let sidebar = select( interfaceStore ).getActiveComplementaryArea(
editPostStore.name
);
const isOpen = sidebar !== null;
if (
! [ 'edit-post/document', 'edit-post/block' ].includes(
sidebar
Expand All @@ -66,12 +67,11 @@ const SettingsSidebar = () => {
).getShortcutRepresentation( 'core/edit-post/toggle-sidebar' );
return {
sidebarName: sidebar,
isSidebarOpen: isOpen,
keyboardShortcut: shortcut,
isTemplateMode: select( editPostStore ).isEditingTemplate(),
};
},
[]
);
}, [] );

const Content = () => {
// Because `PluginSidebarEditPost` renders a `ComplementaryArea`, we
Expand Down Expand Up @@ -126,7 +126,7 @@ const SettingsSidebar = () => {
const { openGeneralSidebar } = useDispatch( editPostStore );
return (
<Tabs
selectedTabId={ sidebarName }
selectedTabId={ isSidebarOpen ? sidebarName : null }
onSelect={ ( selectedId ) => {
openGeneralSidebar( selectedId );
} }
Expand Down

0 comments on commit 839acc4

Please sign in to comment.