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 23, 2022
1 parent 7c2f34d commit 6aaf5f1
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

0 comments on commit 6aaf5f1

Please sign in to comment.