Skip to content

Commit

Permalink
Remove code handling selected tab being removed from the DOM
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Oct 14, 2024
1 parent 3bfe633 commit 86950b8
Showing 1 changed file with 2 additions and 20 deletions.
22 changes: 2 additions & 20 deletions packages/components/src/tabs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ function Tabs( {

const isControlled = selectedTabId !== undefined;

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

// Keep track of whether tabs have been populated. This is used to prevent
// certain effects from firing too early while tab data and relevant
Expand All @@ -60,29 +60,11 @@ function Tabs( {
tabsHavePopulatedRef.current = true;
}

const selectedTab = items.find( ( item ) => item.id === selectedId );
const firstEnabledTab = items.find( ( item ) => {
// Ariakit internally refers to disabled tabs as `dimmed`.
return ! item.dimmed;
} );

// Clear `selectedId` if the active tab is removed from the DOM in controlled mode.
useLayoutEffect( () => {
if ( ! isControlled ) {
return;
}

// Once the tabs have populated, if the `selectedTabId` still can't be
// found, clear the selection.
if (
tabsHavePopulatedRef.current &&
!! selectedTabId &&
! selectedTab
) {
setSelectedId( null );
}
}, [ isControlled, selectedTab, selectedTabId, setSelectedId ] );

useEffect( () => {
// If there is no active tab, fallback to place focus on the first enabled tab
// so there is always an active element
Expand Down

0 comments on commit 86950b8

Please sign in to comment.