|
@@ -1,6 +1,6 @@
|
|
|
'use client'
|
|
'use client'
|
|
|
|
|
|
|
|
-import { useEffect, useMemo, useRef, useState } from 'react'
|
|
|
|
|
|
|
+import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
|
|
import Link from 'next/link'
|
|
import Link from 'next/link'
|
|
|
import { usePathname, useRouter } from 'next/navigation'
|
|
import { usePathname, useRouter } from 'next/navigation'
|
|
|
import { useTranslations } from 'next-intl'
|
|
import { useTranslations } from 'next-intl'
|
|
@@ -203,6 +203,31 @@ export function SettingsNav({
|
|
|
|
|
|
|
|
const pages = visibleSettingsPages({ isCloud, supportEnabled })
|
|
const pages = visibleSettingsPages({ isCloud, supportEnabled })
|
|
|
|
|
|
|
|
|
|
+ // The list is longer than the window: after a link or the search lands on a
|
|
|
|
|
+ // page further down, bring that page's row into view so the person can see
|
|
|
|
|
+ // where they are. "nearest" moves nothing when the row is already visible.
|
|
|
|
|
+ const navRef = useRef<HTMLElement>(null)
|
|
|
|
|
+ const showCurrent = useCallback(() => {
|
|
|
|
|
+ navRef.current
|
|
|
|
|
+ ?.querySelector<HTMLElement>('[aria-current="page"]')
|
|
|
|
|
+ ?.scrollIntoView?.({ block: 'nearest' })
|
|
|
|
|
+ }, [])
|
|
|
|
|
+ useEffect(showCurrent, [pathname, showCurrent])
|
|
|
|
|
+ // On a narrow window this list is hidden and cannot scroll; when the window
|
|
|
|
|
+ // widens and it appears, the page has not changed, so look again then.
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ const nav = navRef.current
|
|
|
|
|
+ if (!nav || typeof ResizeObserver === 'undefined') return
|
|
|
|
|
+ let shown = nav.offsetHeight > 0
|
|
|
|
|
+ const observer = new ResizeObserver(() => {
|
|
|
|
|
+ const now = nav.offsetHeight > 0
|
|
|
|
|
+ if (now && !shown) showCurrent()
|
|
|
|
|
+ shown = now
|
|
|
|
|
+ })
|
|
|
|
|
+ observer.observe(nav)
|
|
|
|
|
+ return () => observer.disconnect()
|
|
|
|
|
+ }, [showCurrent])
|
|
|
|
|
+
|
|
|
const newPill = (item: SettingsPage) =>
|
|
const newPill = (item: SettingsPage) =>
|
|
|
newItems.includes(item.href) ? (
|
|
newItems.includes(item.href) ? (
|
|
|
<span className="shrink-0 rounded bg-primary/15 px-1.5 py-0.5 text-[10px] font-semibold uppercase text-primary">
|
|
<span className="shrink-0 rounded bg-primary/15 px-1.5 py-0.5 text-[10px] font-semibold uppercase text-primary">
|
|
@@ -236,7 +261,7 @@ export function SettingsNav({
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
- <nav className="flex flex-col gap-4">
|
|
|
|
|
|
|
+ <nav ref={navRef} className="flex flex-col gap-4">
|
|
|
<SettingsSearch features={features} isCloud={isCloud} supportEnabled={supportEnabled} />
|
|
<SettingsSearch features={features} isCloud={isCloud} supportEnabled={supportEnabled} />
|
|
|
{SETTINGS_CATEGORIES.map((category) => {
|
|
{SETTINGS_CATEGORIES.map((category) => {
|
|
|
const visibleItems = pages.filter((p) => p.category === category)
|
|
const visibleItems = pages.filter((p) => p.category === category)
|
|
@@ -255,6 +280,7 @@ export function SettingsNav({
|
|
|
<Link
|
|
<Link
|
|
|
key={item.href}
|
|
key={item.href}
|
|
|
href={item.href}
|
|
href={item.href}
|
|
|
|
|
+ aria-current={isActive ? 'page' : undefined}
|
|
|
className={cn(
|
|
className={cn(
|
|
|
'flex items-center gap-3 rounded-lg px-3 py-2.5 text-sm transition-colors',
|
|
'flex items-center gap-3 rounded-lg px-3 py-2.5 text-sm transition-colors',
|
|
|
isActive
|
|
isActive
|