Skip to content

Commit

Permalink
Inserter: Set initial active tab ID during render (WordPress#67103)
Browse files Browse the repository at this point in the history
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: tyxla <[email protected]>
  • Loading branch information
3 people authored Nov 19, 2024
1 parent ede2993 commit cf59c28
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
privateApis as componentsPrivateApis,
__unstableMotion as motion,
} from '@wordpress/components';
import { useState, useEffect } from '@wordpress/element';
import { useState } from '@wordpress/element';

/**
* Internal dependencies
Expand Down Expand Up @@ -35,14 +35,13 @@ function CategoryTabs( {
const selectedTabId = selectedCategory ? selectedCategory.name : null;
const [ activeTabId, setActiveId ] = useState();
const firstTabId = categories?.[ 0 ]?.name;
useEffect( () => {
// If there is no active tab, make the first tab the active tab, so that
// when focus is moved to the tablist, the first tab will be focused
// despite not being selected
if ( selectedTabId === null && ! activeTabId && firstTabId ) {
setActiveId( firstTabId );
}
}, [ selectedTabId, activeTabId, firstTabId, setActiveId ] );

// If there is no active tab, make the first tab the active tab, so that
// when focus is moved to the tablist, the first tab will be focused
// despite not being selected
if ( selectedTabId === null && ! activeTabId && firstTabId ) {
setActiveId( firstTabId );
}

return (
<Tabs
Expand Down

0 comments on commit cf59c28

Please sign in to comment.