Sync active tab with browser URL

This commit is contained in:
Philipp Stracker 2024-10-28 15:58:40 +01:00
parent 69ca811b96
commit b95af5c1b3
No known key found for this signature in database
3 changed files with 1163 additions and 24 deletions

View file

@ -1,14 +1,19 @@
import { TabPanel } from '@wordpress/components';
import { useState } from '@wordpress/element';
import { getQuery, updateQueryString } from '@woocommerce/navigation';
import { useEffect, useState } from '@wordpress/element';
const TabNavigation = ( { tabs } ) => {
const initialPanel = tabs[ 0 ].name;
const initialPanel = getQuery()?.panel ?? tabs[ 0 ].name;
const [ activePanel, setActivePanel ] = useState( initialPanel );
const updatePanelUri = ( tabName ) => {
setActivePanel( tabName );
};
useEffect( () => {
updateQueryString( { panel: activePanel }, '/', getQuery() );
}, [ activePanel ] );
return (
<TabPanel
className={ `ppcp-r-tabs ${ activePanel }` }