Skip to content

Commit

Permalink
fix: Fix corner case behaviour of MiniToc and Toc (#300)
Browse files Browse the repository at this point in the history
* fix: When toc.items.length === 0 toc not rendered

* fix: Fix mobile miniToc overflow-mode behavour

---------

Co-authored-by: Ruslan Bagautdinov <[email protected]>
  • Loading branch information
JeikZim and Ruslan Bagautdinov authored Sep 23, 2024
1 parent 2598974 commit 765b38e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 32 deletions.
21 changes: 16 additions & 5 deletions src/components/MiniToc/MiniToc.scss
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,22 @@
margin-bottom: $miniTocTitleMargin;
}

&:has(&_overflowed) &__bottom {
$bottomHeight: 20px;
&:has(&_overflowed) {
#{$class}__bottom {
$bottomHeight: 36px;

display: block;
height: $bottomHeight;
display: block;
height: $bottomHeight;
}

#{$class}__sections {
max-height: calc(
100vh - var(--dc-header-height, #{$headerHeight}) - var(
--dc-subnavigation-height,
#{$subNavigationHeight}
) - #{$mobileMiniTocOffset} - #{$bottomHeight}
);
}
}

&__section {
Expand All @@ -105,7 +116,7 @@
100vh - var(--dc-header-height, #{$headerHeight}) - var(
--dc-subnavigation-height,
#{$subNavigationHeight}
) - #{$mobileMiniTocOffset} - #{$bottomHeight}
) - #{$mobileMiniTocOffset}
);
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/components/Scrollspy/Scrollspy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class Scrollspy extends React.Component<ScrollspyInnerProps, ScrollspySta
scrollByClick: boolean;
firstItemIndexInView: number;
lastItemIndexInView: number;
overflowChecked: boolean;

constructor(props: ScrollspyInnerProps) {
super(props);
Expand All @@ -57,6 +58,7 @@ export class Scrollspy extends React.Component<ScrollspyInnerProps, ScrollspySta
inViewState: [],
};

this.overflowChecked = false;
this.scrollByClick = false;
this.firstItemIndexInView = -1;
this.lastItemIndexInView = -1;
Expand Down Expand Up @@ -86,6 +88,12 @@ export class Scrollspy extends React.Component<ScrollspyInnerProps, ScrollspySta
this.initItems();
}

if (!this.overflowChecked) {
this.overflowChecked = true;

this.checkListOverflow();
}

if (router.hash !== prevProps.router.hash) {
this.pauseScrollHandler();
this.saveActiveItems(router.hash);
Expand Down
2 changes: 1 addition & 1 deletion src/components/SubNavigation/SubNavigation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
100vh - var(--dc-header-height, $headerHeight) - var(
--dc-subnavigation-height,
$subNavigationHeight
) - #{$mobileMiniTocOffset}
)
);
transition: max-height 300ms 0s;
}
Expand Down
60 changes: 34 additions & 26 deletions src/components/navigation/SidebarContent/SidebarContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,17 @@ export const SidebarContent: React.FC<SidebarContentProps & PropsWithChildren> =
mobileControlsData,
children,
}) => {
const mainMenuIsOpened = mainMenuOpenessData && mainMenuOpenessData.isMainMenuOpened;
const mainMenuIsClosed = mainMenuOpenessData && !mainMenuOpenessData.isMainMenuOpened;

const toc = navigationTocData &&
navigationTocData.toc &&
mainMenuOpenessData &&
!mainMenuOpenessData.isMainMenuOpened && (
navigationTocData.toc.items.length > 0 &&
mainMenuIsClosed && (
<React.Fragment>
<div className={b('to-main-menu')}>
<ToMainMenu
mainMenuIsOpen={mainMenuOpenessData.isMainMenuOpened}
mainMenuIsOpen={mainMenuIsOpened}
openMainMenu={mainMenuOpenessData.openMainMenu}
/>
</div>
Expand All @@ -69,29 +72,34 @@ export const SidebarContent: React.FC<SidebarContentProps & PropsWithChildren> =
</React.Fragment>
);

const mainMenu = pcNavigationData &&
((mainMenuOpenessData && mainMenuOpenessData.isMainMenuOpened) || !navigationTocData) && (
<div className={b('main-menu')}>
{pcNavigationData.leftItemsWithIconSize && (
<NavigationList
items={pcNavigationData.leftItemsWithIconSize}
itemClassName={b('main-menu-item')}
column={ItemColumnName.Top}
onActiveItemChange={pcNavigationData.onActiveItemChange}
menuLayout={NavigationLayout.Mobile}
/>
)}
{pcNavigationData.rightItemsWithIconSize && (
<NavigationList
items={pcNavigationData.rightItemsWithIconSize}
itemClassName={b('main-menu-item')}
column={ItemColumnName.Bottom}
onActiveItemChange={pcNavigationData.onActiveItemChange}
menuLayout={NavigationLayout.Mobile}
/>
)}
</div>
);
const withoutToc =
!navigationTocData ||
!navigationTocData.toc ||
(typeof navigationTocData.toc.items.length === 'number' &&
navigationTocData.toc.items.length === 0);

const mainMenu = pcNavigationData && (mainMenuIsOpened || withoutToc) && (
<div className={b('main-menu')}>
{pcNavigationData.leftItemsWithIconSize && (
<NavigationList
items={pcNavigationData.leftItemsWithIconSize}
itemClassName={b('main-menu-item')}
column={ItemColumnName.Top}
onActiveItemChange={pcNavigationData.onActiveItemChange}
menuLayout={NavigationLayout.Mobile}
/>
)}
{pcNavigationData.rightItemsWithIconSize && (
<NavigationList
items={pcNavigationData.rightItemsWithIconSize}
itemClassName={b('main-menu-item')}
column={ItemColumnName.Bottom}
onActiveItemChange={pcNavigationData.onActiveItemChange}
menuLayout={NavigationLayout.Mobile}
/>
)}
</div>
);

const data = mobileControlsData;
const mobileControls = data && (
Expand Down

0 comments on commit 765b38e

Please sign in to comment.