Commit 6575bdfd authored by tom goriunov's avatar tom goriunov Committed by GitHub

'Contract' tab doesn't open from '...' on narrow desktop (#1230)

Fixes #1228
parent 5d628aff
...@@ -33,7 +33,7 @@ const TabsMenu = ({ tabs, tabsCut, isActive, styles, onItemClick, buttonRef, act ...@@ -33,7 +33,7 @@ const TabsMenu = ({ tabs, tabsCut, isActive, styles, onItemClick, buttonRef, act
const handleItemClick = React.useCallback((event: React.MouseEvent<HTMLButtonElement>) => { const handleItemClick = React.useCallback((event: React.MouseEvent<HTMLButtonElement>) => {
onClose(); onClose();
const tabIndex = (event.target as HTMLButtonElement).getAttribute('data-index'); const tabIndex = event.currentTarget.getAttribute('data-index');
if (tabIndex) { if (tabIndex) {
onItemClick(tabsCut + Number(tabIndex)); onItemClick(tabsCut + Number(tabIndex));
} }
......
...@@ -23,17 +23,26 @@ export default function useAdaptiveTabs(tabs: Array<RoutedTab>, disabled?: boole ...@@ -23,17 +23,26 @@ export default function useAdaptiveTabs(tabs: Array<RoutedTab>, disabled?: boole
return tabs.length; return tabs.length;
} }
const { visibleNum } = tabWidths.slice(0, -1).reduce((result, item, index) => { const { visibleNum } = tabWidths.slice(0, -1).reduce((result, item, index, array) => {
if (!item) { if (!item) {
return result; return result;
} }
if (result.accWidth + item <= listWidth - rightSlotWidth - menuWidth) { if (result.visibleNum < index) {
return { visibleNum: result.visibleNum + 1, accWidth: result.accWidth + item }; // means that we haven't increased visibleNum on the previous iteration, so there is no space left
// we skip now till the rest of the loop
return result;
} }
if (result.accWidth + item <= listWidth - rightSlotWidth && index === tabWidths.length - 2) { if (index === array.length - 1) {
return { visibleNum: result.visibleNum + 1, accWidth: result.accWidth + item }; // last element
if (result.accWidth + item < listWidth - rightSlotWidth) {
return { visibleNum: result.visibleNum + 1, accWidth: result.accWidth + item };
}
} else {
if (result.accWidth + item + menuWidth < listWidth - rightSlotWidth) {
return { visibleNum: result.visibleNum + 1, accWidth: result.accWidth + item };
}
} }
return result; return result;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment