Commit 54e7744e authored by tom's avatar tom

mitigate flickering

parent bf49b2b5
...@@ -67,7 +67,13 @@ const RoutedTabs = ({ tabs, defaultActiveTab }: Props) => { ...@@ -67,7 +67,13 @@ const RoutedTabs = ({ tabs, defaultActiveTab }: Props) => {
activeTab={ tabs[activeTab] } activeTab={ tabs[activeTab] }
tabsCut={ tabsCut } tabsCut={ tabsCut }
isActive={ activeTab >= tabsCut } isActive={ activeTab >= tabsCut }
styles={ tabsCut < tabs.length ? {} : hiddenItemStyles } styles={ tabsCut < tabs.length ?
// initially our cut is 0 and we don't want to show the menu button too
// but we want to keep it in the tabs row so it won't collapse
// that's why we only change opacity but not the position itself
{ opacity: tabsCut === 0 ? 0 : 1 } :
hiddenItemStyles
}
onItemClick={ handleItemInMenuClick } onItemClick={ handleItemInMenuClick }
buttonRef={ tabsRefs[index] } buttonRef={ tabsRefs[index] }
/> />
......
...@@ -6,7 +6,9 @@ import type { RoutedTab } from './types'; ...@@ -6,7 +6,9 @@ import type { RoutedTab } from './types';
import { menuButton } from './utils'; import { menuButton } from './utils';
export default function useAdaptiveTabs(tabs: Array<RoutedTab>) { export default function useAdaptiveTabs(tabs: Array<RoutedTab>) {
const [ tabsCut, setTabsCut ] = React.useState(tabs.length); // to avoid flickering we set initial value to 0
// so there will be no displayed tabs initially
const [ tabsCut, setTabsCut ] = React.useState(0);
const [ tabsRefs, setTabsRefs ] = React.useState<Array<React.RefObject<HTMLButtonElement>>>([]); const [ tabsRefs, setTabsRefs ] = React.useState<Array<React.RefObject<HTMLButtonElement>>>([]);
const listRef = React.useRef<HTMLDivElement>(null); const listRef = React.useRef<HTMLDivElement>(null);
......
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