Skip to content

Commit

Permalink
Fixed typescript errors and tabs sorting.
Browse files Browse the repository at this point in the history
  • Loading branch information
Foxhoundn committed Feb 16, 2021
1 parent bb903d4 commit f887a1a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion __tests__/tabs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ test('Renders shortened <Tabs /> properly', () => {
);
});

expect(document.querySelectorAll('.reqore-tabs-list-item').length).toBe(2);
expect(document.querySelectorAll('.reqore-tabs-list-item').length).toBe(3);
expect(
document.querySelectorAll('.reqore-tabs-list .reqore-popover-wrapper')
.length
Expand Down
13 changes: 11 additions & 2 deletions src/components/Breadcrumbs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ const getBreadcrumbsLength = (
}

if (item.withTabs) {
return len + getTabsLength(item.withTabs.tabs);
return (
len +
getTabsLength(item.withTabs.tabs, 'width', item.withTabs.activeTab)
);
}

return len + 27 + item.label.length * 10 + 35;
Expand All @@ -105,9 +108,11 @@ const getTransformedItems = (
if (!width) {
return items;
}

let stop = false;
let newItems = [...items];

while (getBreadcrumbsLength(newItems) > width) {
while (getBreadcrumbsLength(newItems) > width && !stop) {
if (isArray(newItems[1])) {
newItems[1].push(newItems[2] as IReqoreBreadcrumbItem);
newItems[2] = undefined;
Expand All @@ -117,6 +122,10 @@ const getTransformedItems = (
}

newItems = newItems.filter((i) => i);

if ((newItems[2] as IReqoreBreadcrumbItem).withTabs) {
stop = true;
}
}

return newItems;
Expand Down
7 changes: 3 additions & 4 deletions src/stories/Breadcrumbs/Breadcrumbs.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,16 +276,15 @@ WithTabsDark.args = {
label: 'Tab 4',
id: 'tab4',
icon: 'notifications',
active: true,
disabled: true,
},
{
label: 'Tab 5',
label: 'Really long tab name',
id: 'tab5',
icon: 'notifications',
disabled: true,
},
],
activeTab: 'tab1',
activeTab: 'tab5',
onTabChange: (tabId) => {
alert(`Tab ${tabId} clicked`);
},
Expand Down

0 comments on commit f887a1a

Please sign in to comment.