mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
✨ Sync active tab with browser URL
This commit is contained in:
parent
69ca811b96
commit
b95af5c1b3
3 changed files with 1163 additions and 24 deletions
|
@ -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 }` }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue