Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Austenem/CAT-955 Fix header bug #3575

Merged
merged 3 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG-fix-header-bug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Resolve issues of header cutting off the top of detail pages and header shifting off-screen when scrolling.
5 changes: 2 additions & 3 deletions context/app/static/js/components/Header/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';

import Box from '@mui/material/Box';
import EntityHeader from 'js/components/detailPage/entityHeader/EntityHeader';
import HeaderAppBar from '../HeaderAppBar';
import HeaderContent from '../HeaderContent';
Expand All @@ -10,12 +9,12 @@ function Header() {
const { shouldDisplayHeader, ...props } = useEntityHeaderVisibility();

return (
<Box sx={(theme) => ({ position: 'fixed', width: '100%', zIndex: theme.zIndex.header })}>
<>
<HeaderAppBar {...props}>
<HeaderContent />
</HeaderAppBar>
{shouldDisplayHeader && <EntityHeader />}
</Box>
</>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@ function DetailPageSection({ children, ...rest }: PropsWithChildren<React.HTMLAt
const strippedHash = initialHash.slice(1);
if (strippedHash === rest.id) {
setTimeout(() => {
sectionRef.current?.scrollIntoView({
// Manually scroll to section and account for header offset
const sectionTop = sectionRef.current?.getBoundingClientRect().top ?? 0;
const scrollPosition = window.scrollY + sectionTop - offset;

window.scrollTo({
top: Math.max(scrollPosition, 0),
behavior: 'smooth',
});
}, 1000);
}
}
// We do not want to re-scroll down to the section if the header view changes (aka offset changes)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [initialHash, rest.id]);

return (
Expand Down
Loading