Skip to content

Commit

Permalink
Revert "Allow tab to be active but not selected"
Browse files Browse the repository at this point in the history
This reverts commit 4c6274f.
  • Loading branch information
jeryj committed Apr 16, 2024
1 parent 00c5c20 commit 1a44230
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 25 deletions.
22 changes: 4 additions & 18 deletions packages/components/src/tabs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,13 @@ function Tabs( {
orientation = 'horizontal',
onSelect,
children,
selectedOnMount = true,
selectedTabId,
}: TabsProps ) {
const instanceId = useInstanceId( Tabs, 'tabs' );

const store = Ariakit.useTabStore( {
selectOnMove,
orientation,
defaultSelectedId:
defaultTabId && selectedOnMount
? `${ instanceId }-${ defaultTabId }`
: null,
defaultSelectedId: defaultTabId && `${ instanceId }-${ defaultTabId }`,
setSelectedId: ( selectedId ) => {
const strippedDownId =
typeof selectedId === 'string'
Expand All @@ -53,6 +48,7 @@ function Tabs( {
} );

const isControlled = selectedTabId !== undefined;

const { items, selectedId, activeId } = store.useState();
const { setSelectedId, setActiveId } = store;

Expand Down Expand Up @@ -87,25 +83,17 @@ function Tabs( {
return;
}

const setInitialTab = ( tabId: string | undefined ) => {
if ( selectedOnMount ) {
setSelectedId( tabId );
} else {
setActiveId( tabId );
}
};

// If the currently selected tab is missing (i.e. removed from the DOM),
// fall back to the initial tab or the first enabled tab if there is
// one. Otherwise, no tab should be selected.
if ( ! items.find( ( item ) => item.id === selectedId ) ) {
if ( initialTab && ! initialTab.dimmed ) {
setInitialTab( initialTab?.id );
setSelectedId( initialTab?.id );
return;
}

if ( firstEnabledTab ) {
setInitialTab( firstEnabledTab.id );
setSelectedId( firstEnabledTab.id );
} else if ( tabsHavePopulated.current ) {
setSelectedId( null );
}
Expand All @@ -117,8 +105,6 @@ function Tabs( {
isControlled,
items,
selectedId,
selectedOnMount,
setActiveId,
setSelectedId,
] );

Expand Down
7 changes: 0 additions & 7 deletions packages/components/src/tabs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ export type TabsProps = {
* provided. (Controlled Mode)
*/
defaultTabId?: string;
/**
* If the initial tab should show the tab pane (be selected) or only
* show the active tab.
*
* @default true
*/
selectedOnMount?: boolean;
/**
* The function called when a tab has been selected.
* It is passed the id of the newly selected tab as an argument.
Expand Down

0 comments on commit 1a44230

Please sign in to comment.