Skip to content

Commit

Permalink
fix: update side context on tab change
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Mar 14, 2021
1 parent 7d16d98 commit b85c625
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions ui/app/src/SideContext/SideContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {

export interface SideContext {
pageRef?: RefObject<HTMLDivElement>;
tab?: string;
}
interface ScrollElement {
href: string;
Expand All @@ -19,7 +20,7 @@ interface ScrollElement {
offset: number;
}

export const SideContext: FC<SideContext> = ({ pageRef }) => {
export const SideContext: FC<SideContext> = ({ pageRef, tab }) => {
const [items, setItems] = useState<ScrollElement[]>([]);
const [activeItem, setActiveItem] = useState<number>(-1);
const windRef = pageRef?.current;
Expand Down Expand Up @@ -80,7 +81,7 @@ export const SideContext: FC<SideContext> = ({ pageRef }) => {
} else {
setItems([]);
}
}, [windRef]);
}, [windRef, tab]);

useEffect(() => {
if (typeof window !== 'undefined' && window) {
Expand Down
2 changes: 1 addition & 1 deletion ui/app/src/SidebarsPage/SidebarsStoryPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export const SidebarsStoryPage: FC<DocPageProps> = ({
</PageContainer>
</Tabs>
</Box>
{doc.contextSidebar && <SideContext pageRef={pageRef} />}
{doc.contextSidebar && <SideContext pageRef={pageRef} tab={activeTab} />}
</Box>
);
};

0 comments on commit b85c625

Please sign in to comment.