Skip to content

Commit

Permalink
improve Tabs onSelect callback
Browse files Browse the repository at this point in the history
  • Loading branch information
chad1008 committed Nov 17, 2023
1 parent 839acc4 commit 27f696f
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
store as blockEditorStore,
} from '@wordpress/block-editor';
import { useSelect, useDispatch } from '@wordpress/data';
import { Platform, useContext } from '@wordpress/element';
import { Platform, useCallback, useContext } from '@wordpress/element';
import { isRTL, __ } from '@wordpress/i18n';
import { drawerLeft, drawerRight } from '@wordpress/icons';
import { store as interfaceStore } from '@wordpress/interface';
Expand Down Expand Up @@ -124,12 +124,20 @@ const SettingsSidebar = () => {
};

const { openGeneralSidebar } = useDispatch( editPostStore );

const onTabSelect = useCallback(
( newSelectedTabId ) => {
if ( !! newSelectedTabId ) {
openGeneralSidebar( newSelectedTabId );
}
},
[ openGeneralSidebar ]
);

return (
<Tabs
selectedTabId={ isSidebarOpen ? sidebarName : null }
onSelect={ ( selectedId ) => {
openGeneralSidebar( selectedId );
} }
onSelect={ onTabSelect }
>
<Content />
</Tabs>
Expand Down

0 comments on commit 27f696f

Please sign in to comment.