Persist active tab on refresh (#36112)

This commit is contained in:
Maikel David Pérez Gómez 2022-12-21 14:47:13 -03:00 committed by GitHub
parent 1e815be516
commit c7c0322163
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -4,6 +4,7 @@
import { __ } from '@wordpress/i18n';
import { Children, useEffect } from '@wordpress/element';
import { TabPanel, Tooltip } from '@wordpress/components';
import { navigateTo, getNewPath, getQuery } from '@woocommerce/navigation';
/**
* Internal dependencies
@ -14,6 +15,8 @@ import { ProductFormTab } from '../product-form-tab';
export const ProductFormLayout: React.FC< {
children: JSX.Element | JSX.Element[];
} > = ( { children } ) => {
const query = getQuery() as Record< string, string >;
useEffect( () => {
window.document.body.classList.add(
'woocommerce-admin-product-layout'
@ -63,7 +66,13 @@ export const ProductFormLayout: React.FC< {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore Disabled properties will be included in newer versions of Gutenberg.
tabs={ tabs }
onSelect={ () => ( window.document.documentElement.scrollTop = 0 ) }
initialTabName={ query.tab ?? tabs[ 0 ].name }
onSelect={ ( tabName: string ) => {
window.document.documentElement.scrollTop = 0;
navigateTo( {
url: getNewPath( { tab: tabName } ),
} );
} }
>
{ ( tab ) => (
<>

View File

@ -0,0 +1,4 @@
Significance: minor
Type: add
Persist active tab on refresh