Skip to content

Commit

Permalink
fix: OverflowTab does not render when no tab is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
thunguyen19 committed Dec 6, 2023
1 parent cb8d09f commit d829f02
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
23 changes: 16 additions & 7 deletions modules/react/collection/lib/useOverflowListModel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export function getHiddenIds(
containerWidth: number,
overflowTargetWidth: number,
itemWidthCache: Record<string, number>,
selectedIds: string[] | 'all'
selectedIds: string[] | 'all',
items?: any[]
): string[] {
/** Allows us to prioritize showing the selected item */
let selectedKey: undefined | string;
Expand All @@ -16,9 +17,13 @@ export function getHiddenIds(
/** Tally ids that won't fit inside the container. These will be used by components to hide
* elements that won't fit in the container */
const hiddenIds: string[] = [];

if (selectedIds !== 'all' && selectedIds.length) {
selectedKey = selectedIds[0];
if (items?.length) {
// If selectedIds[0] is not in items, use the first id from items
selectedKey = items.find(item => item.id === selectedIds[0]) ? selectedIds[0] : items[0].id;
} else {
selectedKey = selectedIds[0];
}
}

if (
Expand Down Expand Up @@ -101,7 +106,8 @@ export const useOverflowListModel = createModelHook({
containerWidthRef.current,
overflowTargetWidthRef.current,
itemWidthCacheRef.current,
selectedIds
selectedIds,
config.items
);
model.events.select(data);

Expand All @@ -115,7 +121,8 @@ export const useOverflowListModel = createModelHook({
containerWidthRef.current,
overflowTargetWidthRef.current,
itemWidthCacheRef.current,
state.selectedIds
state.selectedIds,
config.items
);

setHiddenIds(ids);
Expand All @@ -136,7 +143,8 @@ export const useOverflowListModel = createModelHook({
containerWidthRef.current,
overflowTargetWidthRef.current,
itemWidthCacheRef.current,
state.selectedIds
state.selectedIds,
config.items
);

setHiddenIds(ids);
Expand All @@ -153,7 +161,8 @@ export const useOverflowListModel = createModelHook({
itemWidthCacheRef.current,
state.selectedIds !== 'all'
? state.selectedIds.filter(sId => data.id !== sId)
: state.selectedIds
: state.selectedIds,
config.items
);

setHiddenIds(ids);
Expand Down
2 changes: 1 addition & 1 deletion modules/react/tabs/stories/examples/OverflowTabs.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, {useEffect} from 'react';

import {Tabs, useTabsModel} from '@workday/canvas-kit-react/tabs';
import {SegmentedControl} from '@workday/canvas-kit-preview-react/segmented-control';
Expand Down

0 comments on commit d829f02

Please sign in to comment.