some tweaks

This commit is contained in:
tom
2022-09-19 17:06:06 +03:00
parent 0cf1d10a1e
commit be83d48947
2 changed files with 12 additions and 12 deletions
+1 -9
View File
@@ -47,14 +47,6 @@ const RoutedTabs = ({ tabs, defaultActiveTab }: Props) => {
setActiveTab(index);
}, [ tabs, router ]);
const handleItemInMenuClick = React.useCallback((event: React.MouseEvent<HTMLButtonElement>) => {
const tabIndex = (event.target as HTMLButtonElement).getAttribute('data-index');
if (tabIndex) {
handleTabChange(tabsCut + Number(tabIndex));
}
}, [ handleTabChange, tabsCut ]);
return (
<Tabs variant="soft-rounded" colorScheme="blue" isLazy onChange={ handleTabChange } index={ activeTab }>
<TabList marginBottom={{ base: 6, lg: 8 }} flexWrap="nowrap" whiteSpace="nowrap" ref={ listRef }>
@@ -74,7 +66,7 @@ const RoutedTabs = ({ tabs, defaultActiveTab }: Props) => {
{ opacity: tabsCut === 0 ? 0 : 1 } :
hiddenItemStyles
}
onItemClick={ handleItemInMenuClick }
onItemClick={ handleTabChange }
buttonRef={ tabsRefs[index] }
/>
);
+11 -3
View File
@@ -18,12 +18,20 @@ interface Props {
tabsCut: number;
isActive: boolean;
styles?: StyleProps;
onItemClick: (event: React.MouseEvent<HTMLButtonElement>) => void;
onItemClick: (index: number) => void;
buttonRef: React.RefObject<HTMLButtonElement>;
}
const RoutedTabsMenu = ({ tabs, tabsCut, isActive, styles, onItemClick, buttonRef, activeTab }: Props) => {
const { isOpen, onToggle } = useDisclosure();
const { isOpen, onToggle, onClose } = useDisclosure();
const handleItemClick = React.useCallback((event: React.MouseEvent<HTMLButtonElement>) => {
onClose();
const tabIndex = (event.target as HTMLButtonElement).getAttribute('data-index');
if (tabIndex) {
onItemClick(tabsCut + Number(tabIndex));
}
}, [ onClose, onItemClick, tabsCut ]);
return (
<Popover isLazy placement="bottom-end" key="more">
@@ -44,7 +52,7 @@ const RoutedTabsMenu = ({ tabs, tabsCut, isActive, styles, onItemClick, buttonRe
<Button
key={ tab.routeName }
variant="subtle"
onClick={ onItemClick }
onClick={ handleItemClick }
isActive={ activeTab.routeName === tab.routeName }
justifyContent="left"
data-index={ index }