Skip to content

Commit

Permalink
Add new prop selectedTabName to TabPanel
Browse files Browse the repository at this point in the history
  • Loading branch information
madhusudhand committed Dec 21, 2022
1 parent 05bef82 commit 6a1da2d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/components/src/tab-panel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export function TabPanel( {
tabs,
selectOnMove = true,
initialTabName,
selectedTabName,
orientation = 'horizontal',
activeClass = 'is-active',
onSelect,
Expand Down Expand Up @@ -110,6 +111,12 @@ export function TabPanel( {
}
}, [ tabs, selectedTab?.name, initialTabName, handleTabSelection ] );

useEffect( () => {
if ( selectedTabName ) {
setSelected( selectedTabName );
}
}, [ selectedTabName ] );

return (
<div className={ className }>
<NavigableMenu
Expand Down
4 changes: 4 additions & 0 deletions packages/components/src/tab-panel/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export type TabPanelProps = {
* If this prop is not set, the first tab will be selected by default.
*/
initialTabName?: string;
/**
* The name of the tab to be selected.
*/
selectedTabName?: string;
/**
* The function called when a tab has been selected.
* It is passed the `tabName` as an argument.
Expand Down

1 comment on commit 6a1da2d

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3749374144
📝 Reported issues:

Please sign in to comment.