-
Notifications
You must be signed in to change notification settings - Fork 23
Responsive grid layout: fixed TopBar/Sidebar with document scroll #3178
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
base: main
Are you sure you want to change the base?
Changes from all commits
41c10c1
ecf1870
5bce8f8
680e6c5
979e8e3
33e9efa
e0e7e52
e28ae94
5d810ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,20 +18,19 @@ function setScrollPosition(key: string, pos: number) { | |
| } | ||
|
|
||
| /** | ||
| * Given a ref to a scrolling container element, keep track of its scroll | ||
| * position before navigation and restore it on return (e.g., back/forward nav). | ||
| * Note that `location.key` is used in the cache key, not `location.pathname`, | ||
| * so the same path navigated to at different points in the history stack will | ||
| * not share the same scroll position. | ||
| * Keep track of window scroll position before navigation and restore it on | ||
| * return (e.g., back/forward nav). Note that `location.key` is used in the | ||
| * cache key, not `location.pathname`, so the same path navigated to at | ||
| * different points in the history stack will not share the same scroll position. | ||
| */ | ||
| export function useScrollRestoration(container: React.RefObject<HTMLElement | null>) { | ||
| export function useScrollRestoration() { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we even need this hook now? Since we're using a regular window scroll, perhaps we can use the built-in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to #2450 if I remove it I was unable to get |
||
| const key = `scroll-position-${useLocation().key}` | ||
| const { state } = useNavigation() | ||
| useEffect(() => { | ||
| if (state === 'loading') { | ||
| setScrollPosition(key, container.current?.scrollTop ?? 0) | ||
| setScrollPosition(key, window.scrollY) | ||
| } else if (state === 'idle') { | ||
| container.current?.scrollTo(0, getScrollPosition(key)) | ||
| window.scrollTo(0, getScrollPosition(key)) | ||
| } | ||
| }, [key, state, container]) | ||
| }, [key, state]) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,6 @@ | |
| * | ||
| * Copyright Oxide Computer Company | ||
| */ | ||
| import { useRef } from 'react' | ||
| import { Outlet } from 'react-router' | ||
|
|
||
| import { PageActionsTarget } from '~/components/PageActions' | ||
|
|
@@ -14,18 +13,12 @@ import { useScrollRestoration } from '~/hooks/use-scroll-restoration' | |
| import { SkipLinkTarget } from '~/ui/lib/SkipLink' | ||
| import { classed } from '~/util/classed' | ||
|
|
||
| export const PageContainer = classed.div`grid h-screen grid-cols-[14.25rem_1fr] grid-rows-[var(--top-bar-height)_1fr]` | ||
| export const PageContainer = classed.div`min-h-full pt-(--top-bar-height)` | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Top bar is fixed, this leaves space for it. Alternatively we use |
||
|
|
||
| export function ContentPane() { | ||
| const ref = useRef<HTMLDivElement>(null) | ||
| useScrollRestoration(ref) | ||
| useScrollRestoration() | ||
| return ( | ||
| <div | ||
| ref={ref} | ||
| className="light:bg-raise flex flex-col overflow-auto" | ||
| id="scroll-container" | ||
| data-testid="scroll-container" | ||
| > | ||
| <div className="light:bg-raise ml-(--sidebar-width) flex min-h-[calc(100vh-var(--top-bar-height))] flex-col"> | ||
| <div className="flex grow flex-col pb-8"> | ||
| <SkipLinkTarget /> | ||
| <main className="*:gutter"> | ||
|
|
@@ -47,12 +40,10 @@ export function ContentPane() { | |
| * `<div>` because we don't need it. | ||
| */ | ||
| export const SerialConsoleContentPane = () => ( | ||
| <div className="flex flex-col overflow-auto"> | ||
| <div className="flex grow flex-col"> | ||
| <SkipLinkTarget /> | ||
| <main className="*:gutter h-full"> | ||
| <Outlet /> | ||
| </main> | ||
| </div> | ||
| <div className="ml-(--sidebar-width) flex h-[calc(100vh-var(--top-bar-height))] flex-col overflow-hidden"> | ||
| <SkipLinkTarget /> | ||
| <main className="*:gutter h-full"> | ||
| <Outlet /> | ||
| </main> | ||
| </div> | ||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an argument to say we should define the shared classes between the skeleton and regular layout to avoid drift but the juice might not be worth the squeeze.