Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,10 @@ public function to_json( $load ) {
$container_data['fields'][] = $field_data;
}

if ( isset( $_GET['cftab'] ) ) {
$container_data['settings']['current_tab'] = sanitize_text_field( $_GET['cftab'] );
}

return $container_data;
}

Expand Down
23 changes: 20 additions & 3 deletions packages/metaboxes/components/container/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,27 @@ class Container extends Component {
const { container } = this.props;

if ( this.isTabbed( container ) ) {
this.setState( {
currentTab: Object.keys( container.settings.tabs )[ 0 ]
} );
const tabNames = Object.keys( container.settings.tabs );
const currentTab = tabNames.includes( container.settings.current_tab ) ? container.settings.current_tab : tabNames[ 0 ];

this.setState( { currentTab } );
}
}

/**
* Adds "cftab" query parameter to the current url.
*
* @param {string} tabName
* @return {void}
*/
addTabNameToUrl( tabName ) {
const url = new URL( window.location.href );

url.searchParams.set( 'cftab', tabName );

history.pushState( {}, '', url.href );
}

/**
* Returns whether the container uses tabs.
*
Expand Down Expand Up @@ -83,6 +98,8 @@ class Container extends Component {
* @return {void}
*/
handleTabClick = ( tab ) => {
this.addTabNameToUrl( tab );

this.setState( {
currentTab: tab
} );
Expand Down