Skip to content

Commit

Permalink
fix(components-ArticleToc): scroll to fixed header below position (#861)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabertazimi authored May 21, 2022
1 parent a4f2138 commit b04e94a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions components/Article/ArticleToc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import styles from './ArticleToc.module.css';

interface Props {
slug: string;
offset?: number;
}

interface TocItem {
id: string;
title: string;
}

const ArticleToc = ({ slug }: Props): JSX.Element => {
const ArticleToc = ({ slug, offset = 120 }: Props): JSX.Element => {
const [tocItems, setTocItems] = useState<TocItem[]>([]);

useEffect(() => {
Expand All @@ -24,7 +25,7 @@ const ArticleToc = ({ slug }: Props): JSX.Element => {
}, [slug]);

return (
<Anchor className={styles.toc}>
<Anchor className={styles.toc} targetOffset={offset}>
{tocItems.map(item => (
<Link key={item.id} href={item.id} title={item.title} />
))}
Expand Down

1 comment on commit b04e94a

@vercel
Copy link

@vercel vercel bot commented on b04e94a May 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

blog – ./

blog.tazimi.dev
blog-git-main-sabertaz.vercel.app
blog-sabertaz.vercel.app

Please sign in to comment.