Skip to content

Commit

Permalink
make table of contents sticky if it has more than 5 items
Browse files Browse the repository at this point in the history
  • Loading branch information
HarryFischer committed Nov 21, 2024
1 parent 26d523e commit 306dd28
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions dotcom-rendering/src/components/TableOfContents.importable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ const detailsStyles = css`
summary::-webkit-details-marker {
display: none;
}
&.make-sticky {
position: sticky;
top: 0;
background: white;
z-index: 4;
max-height: 100vh;
overflow: scroll;
summary {
position: sticky;
top: 0;
z-index: 5;
background: white;
}
}
`;

const summaryStyles = css`
Expand Down Expand Up @@ -127,6 +142,7 @@ export const TableOfContents = ({ tableOfContents, format }: Props) => {
<details
open={open}
css={detailsStyles}
className={tableOfContents.length > 5 ? 'make-sticky' : ''}
data-component="table-of-contents"
>
<summary
Expand Down

0 comments on commit 306dd28

Please sign in to comment.