From dcfe97f837fa16a88d58c868e75d010092ad611f Mon Sep 17 00:00:00 2001 From: chad1008 <13856531+chad1008@users.noreply.github.com> Date: Wed, 14 Feb 2024 14:27:36 -0500 Subject: [PATCH 1/3] rename `initialTabId` prop --- .../components/colors-gradients/control.js | 2 +- .../components/global-styles/color-panel.js | 2 +- .../inspector-controls-tabs/index.js | 2 +- packages/components/src/tabs/index.tsx | 14 ++--- packages/components/src/tabs/test/index.tsx | 60 +++++++++---------- packages/components/src/tabs/types.ts | 2 +- .../components/global-styles/font-families.js | 2 +- .../global-styles/font-library-modal/index.js | 4 +- .../src/components/list-view-sidebar/index.js | 2 +- .../preferences-modal-tabs/index.js | 2 +- 10 files changed, 46 insertions(+), 46 deletions(-) diff --git a/packages/block-editor/src/components/colors-gradients/control.js b/packages/block-editor/src/components/colors-gradients/control.js index 5a1cda78f86683..946b5dd486b042 100644 --- a/packages/block-editor/src/components/colors-gradients/control.js +++ b/packages/block-editor/src/components/colors-gradients/control.js @@ -133,7 +133,7 @@ function ColorGradientControlInner( { { canChooseAColor && canChooseAGradient && (
) } { tabs.length > 1 && ( - + { tabs.map( ( tab ) => ( - + { tabs.map( ( tab ) => ( { const strippedDownId = typeof selectedId === 'string' @@ -66,7 +66,7 @@ function Tabs( { return ! item.dimmed; } ); const initialTab = items.find( - ( item ) => item.id === `${ instanceId }-${ initialTabId }` + ( item ) => item.id === `${ instanceId }-${ defaultTabId }` ); // Handle selecting the initial tab. @@ -78,8 +78,8 @@ function Tabs( { // Wait for the denoted initial tab to be declared before making a // selection. This ensures that if a tab is declared lazily it can // still receive initial selection, as well as ensuring no tab is - // selected if an invalid `initialTabId` is provided. - if ( initialTabId && ! initialTab ) { + // selected if an invalid `defaultTabId` is provided. + if ( defaultTabId && ! initialTab ) { return; } @@ -101,7 +101,7 @@ function Tabs( { }, [ firstEnabledTab, initialTab, - initialTabId, + defaultTabId, isControlled, items, selectedId, @@ -122,7 +122,7 @@ function Tabs( { } // If the currently selected tab becomes disabled, fall back to the - // `initialTabId` if possible. Otherwise select the first + // `defaultTabId` if possible. Otherwise select the first // enabled tab (if there is one). if ( initialTab && ! initialTab.dimmed ) { setSelectedId( initialTab.id ); diff --git a/packages/components/src/tabs/test/index.tsx b/packages/components/src/tabs/test/index.tsx index 7262a53702c31d..e8672ba6f55618 100644 --- a/packages/components/src/tabs/test/index.tsx +++ b/packages/components/src/tabs/test/index.tsx @@ -588,7 +588,7 @@ describe( 'Tabs', () => { } ); } ); describe( 'Uncontrolled mode', () => { - describe( 'Without `initialTabId` prop', () => { + describe( 'Without `defaultTabId` prop', () => { it( 'should render first tab', async () => { render( ); @@ -645,20 +645,20 @@ describe( 'Tabs', () => { } ); } ); - describe( 'With `initialTabId`', () => { - it( 'should render the tab set by `initialTabId` prop', async () => { + describe( 'With `defaultTabId`', () => { + it( 'should render the tab set by `defaultTabId` prop', async () => { render( - + ); expect( await getSelectedTab() ).toHaveTextContent( 'Beta' ); } ); - it( 'should not select a tab when `initialTabId` does not match any known tab', () => { + it( 'should not select a tab when `defaultTabId` does not match any known tab', () => { render( ); @@ -672,25 +672,25 @@ describe( 'Tabs', () => { screen.queryByRole( 'tabpanel' ) ).not.toBeInTheDocument(); } ); - it( 'should not change tabs when initialTabId is changed', async () => { + it( 'should not change tabs when defaultTabId is changed', async () => { const { rerender } = render( - + ); rerender( - + ); expect( await getSelectedTab() ).toHaveTextContent( 'Beta' ); } ); - it( 'should fall back to the tab associated to `initialTabId` if the currently active tab is removed', async () => { + it( 'should fall back to the tab associated to `defaultTabId` if the currently active tab is removed', async () => { const mockOnSelect = jest.fn(); const { rerender } = render( ); @@ -704,7 +704,7 @@ describe( 'Tabs', () => { rerender( ); @@ -712,13 +712,13 @@ describe( 'Tabs', () => { expect( await getSelectedTab() ).toHaveTextContent( 'Gamma' ); } ); - it( 'should fall back to the tab associated to `initialTabId` if the currently active tab becomes disabled', async () => { + it( 'should fall back to the tab associated to `defaultTabId` if the currently active tab becomes disabled', async () => { const mockOnSelect = jest.fn(); const { rerender } = render( ); @@ -744,7 +744,7 @@ describe( 'Tabs', () => { rerender( ); @@ -752,9 +752,9 @@ describe( 'Tabs', () => { expect( await getSelectedTab() ).toHaveTextContent( 'Gamma' ); } ); - it( 'should have no active tabs when the tab associated to `initialTabId` is removed while being the active tab', async () => { + it( 'should have no active tabs when the tab associated to `defaultTabId` is removed while being the active tab', async () => { const { rerender } = render( - + ); expect( await getSelectedTab() ).toHaveTextContent( 'Gamma' ); @@ -763,7 +763,7 @@ describe( 'Tabs', () => { rerender( ); @@ -778,9 +778,9 @@ describe( 'Tabs', () => { ).not.toBeInTheDocument(); } ); - it( 'waits for the tab with the `initialTabId` to be present in the `tabs` array before selecting it', async () => { + it( 'waits for the tab with the `defaultTabId` to be present in the `tabs` array before selecting it', async () => { const { rerender } = render( - + ); // There should be no selected tab yet. @@ -791,7 +791,7 @@ describe( 'Tabs', () => { rerender( ); @@ -880,7 +880,7 @@ describe( 'Tabs', () => { expect( await getSelectedTab() ).toHaveTextContent( 'Beta' ); } ); - it( 'should select first enabled tab when the tab associated to `initialTabId` is disabled', async () => { + it( 'should select first enabled tab when the tab associated to `defaultTabId` is disabled', async () => { const TABS_ONLY_GAMMA_ENABLED = TABS.map( ( tabObj ) => tabObj.tabId !== 'gamma' ? { @@ -895,7 +895,7 @@ describe( 'Tabs', () => { const { rerender } = render( ); @@ -905,7 +905,7 @@ describe( 'Tabs', () => { // Re-enable all tabs rerender( - + ); // Even if the initial tab becomes enabled again, the selected tab doesn't @@ -957,14 +957,14 @@ describe( 'Tabs', () => { expect( mockOnSelect ).toHaveBeenLastCalledWith( 'beta' ); } ); - it( 'should select the first enabled tab when the tab associated to `initialTabId` becomes disabled while being the active tab', async () => { + it( 'should select the first enabled tab when the tab associated to `defaultTabId` becomes disabled while being the active tab', async () => { const mockOnSelect = jest.fn(); const { rerender } = render( ); @@ -987,7 +987,7 @@ describe( 'Tabs', () => { ); @@ -1000,7 +1000,7 @@ describe( 'Tabs', () => { ); @@ -1021,12 +1021,12 @@ describe( 'Tabs', () => { await screen.findByRole( 'tabpanel', { name: 'Beta' } ) ).toBeInTheDocument(); } ); - it( 'should render the specified `selectedTabId`, and ignore the `initialTabId` prop', async () => { + it( 'should render the specified `selectedTabId`, and ignore the `defaultTabId` prop', async () => { render( ); diff --git a/packages/components/src/tabs/types.ts b/packages/components/src/tabs/types.ts index 389665b13357fe..1a9e6477385f67 100644 --- a/packages/components/src/tabs/types.ts +++ b/packages/components/src/tabs/types.ts @@ -43,7 +43,7 @@ export type TabsProps = { * Note: this prop will be overridden by the `selectedTabId` prop if it is * provided. (Controlled Mode) */ - initialTabId?: string; + defaultTabId?: string; /** * The function called when a tab has been selected. * It is passed the id of the newly selected tab as an argument. diff --git a/packages/edit-site/src/components/global-styles/font-families.js b/packages/edit-site/src/components/global-styles/font-families.js index 5e66f705334c8e..55ca6d0b5222c9 100644 --- a/packages/edit-site/src/components/global-styles/font-families.js +++ b/packages/edit-site/src/components/global-styles/font-families.js @@ -33,7 +33,7 @@ function FontFamilies() { { !! modalTabOpen && ( toggleModal() } - initialTabId={ modalTabOpen } + defaultTabId={ modalTabOpen } /> ) } diff --git a/packages/edit-site/src/components/global-styles/font-library-modal/index.js b/packages/edit-site/src/components/global-styles/font-library-modal/index.js index 71966449eb616d..dc0fcd7ea373b0 100644 --- a/packages/edit-site/src/components/global-styles/font-library-modal/index.js +++ b/packages/edit-site/src/components/global-styles/font-library-modal/index.js @@ -41,7 +41,7 @@ const tabsFromCollections = ( collections ) => function FontLibraryModal( { onRequestClose, - initialTabId = 'installed-fonts', + defaultTabId = 'installed-fonts', } ) { const { collections, setNotice } = useContext( FontLibraryContext ); @@ -63,7 +63,7 @@ function FontLibraryModal( { className="font-library-modal" >
- + { tabs.map( ( { id, title } ) => ( diff --git a/packages/editor/src/components/list-view-sidebar/index.js b/packages/editor/src/components/list-view-sidebar/index.js index 9484ddcf3943dd..a08b9a73c3c982 100644 --- a/packages/editor/src/components/list-view-sidebar/index.js +++ b/packages/editor/src/components/list-view-sidebar/index.js @@ -127,7 +127,7 @@ export default function ListViewSidebar() { // render where no tab is selected. This ensures that the // tabpanel height is correct so the relevant scroll container // can be rendered internally. - initialTabId="list-view" + defaultTabId="list-view" >