Skip to content

Commit

Permalink
fix design system scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenji Shiroma committed Dec 6, 2023
1 parent 736da48 commit 7ec4b29
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client';

import { BREAKPOINTS } from '@westpac/ui/themes-constants';
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
import { Key, useCallback, useMemo } from 'react';

Expand Down Expand Up @@ -38,6 +39,8 @@ const TabPanelByKey = ({ tabKey, content }: { content: ContentTabsProps; tabKey:
return <></>;
};

const FIXED_HEADER = 162; // 228 - 66 = height to stick

export function ContentTabs({ content }: { content: ContentTabsProps }) {
const router = useRouter();
const pathname = usePathname();
Expand All @@ -47,7 +50,11 @@ export function ContentTabs({ content }: { content: ContentTabsProps }) {

const handleChange = useCallback(
(key: Key) => {
return router.push(`${pathname}?brand=${brand}&tab=${key}`);
const isLargeScreen = window.innerWidth > parseInt(BREAKPOINTS.lg, 10);
router.push(`${pathname}?brand=${brand}&tab=${key}`, { scroll: !isLargeScreen });
if (isLargeScreen) {
window.scrollTo({ top: FIXED_HEADER });
}
},
[brand, pathname, router],
);
Expand Down

0 comments on commit 7ec4b29

Please sign in to comment.