mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
scroll to the correct position regardless of the position or height of the header
This commit is contained in:
@@ -89,10 +89,14 @@ export const Constants = {
|
|||||||
mobileBreakpointName: "md",
|
mobileBreakpointName: "md",
|
||||||
headerHeight: 60,
|
headerHeight: 60,
|
||||||
entryMaxWidth: 650,
|
entryMaxWidth: 650,
|
||||||
isTopVisible: (div: HTMLElement) => div.getBoundingClientRect().top >= Constants.layout.headerHeight,
|
isTopVisible: (div: HTMLElement) => {
|
||||||
|
const header = document.getElementById(Constants.dom.headerId)?.getBoundingClientRect()
|
||||||
|
return div.getBoundingClientRect().top >= (header?.bottom ?? 0)
|
||||||
|
},
|
||||||
isBottomVisible: (div: HTMLElement) => div.getBoundingClientRect().bottom <= window.innerHeight,
|
isBottomVisible: (div: HTMLElement) => div.getBoundingClientRect().bottom <= window.innerHeight,
|
||||||
},
|
},
|
||||||
dom: {
|
dom: {
|
||||||
|
headerId: "header",
|
||||||
entryId: (entry: Entry) => `entry-id-${entry.id}`,
|
entryId: (entry: Entry) => `entry-id-${entry.id}`,
|
||||||
entryContextMenuId: (entry: Entry) => entry.id,
|
entryContextMenuId: (entry: Entry) => entry.id,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -174,10 +174,11 @@ export const selectEntry = createAppAsyncThunk(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
const scrollToEntry = (entryElement: HTMLElement, scrollSpeed: number | undefined, onScrollEnded: () => void) => {
|
const scrollToEntry = (entryElement: HTMLElement, scrollSpeed: number | undefined, onScrollEnded: () => void) => {
|
||||||
|
const header = document.getElementById(Constants.dom.headerId)?.getBoundingClientRect()
|
||||||
|
const offset = (header?.bottom ?? 0) + 3
|
||||||
scrollToWithCallback({
|
scrollToWithCallback({
|
||||||
options: {
|
options: {
|
||||||
// add a small gap between the top of the content and the top of the page
|
top: entryElement.offsetTop - offset,
|
||||||
top: entryElement.offsetTop - Constants.layout.headerHeight - 3,
|
|
||||||
behavior: scrollSpeed && scrollSpeed > 0 ? "smooth" : "auto",
|
behavior: scrollSpeed && scrollSpeed > 0 ? "smooth" : "auto",
|
||||||
},
|
},
|
||||||
onScrollEnded,
|
onScrollEnded,
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ export default function Layout(props: LayoutProps) {
|
|||||||
}}
|
}}
|
||||||
padding={{ base: 6, [Constants.layout.mobileBreakpointName]: "md" }}
|
padding={{ base: 6, [Constants.layout.mobileBreakpointName]: "md" }}
|
||||||
>
|
>
|
||||||
<AppShell.Header id="header">
|
<AppShell.Header id={Constants.dom.headerId}>
|
||||||
<OnMobile>
|
<OnMobile>
|
||||||
{mobileMenuOpen && (
|
{mobileMenuOpen && (
|
||||||
<Group justify="space-between" p="md">
|
<Group justify="space-between" p="md">
|
||||||
|
|||||||
Reference in New Issue
Block a user