Files
supabase/apps/docs/components/Navigation/NavigationMenu/GlobalNavigationMenu.tsx
T
anthony lio a4c9fc145e fix(docs): sidebar wrapped rows (#53508)
## Problem

- in the new docs navigation (`docs-ia-mvp-v1=option-1`), a label that
wraps in an expandable sidebar row is centered, for example
`Architecture, limits and pricing` on the realtime pages in a narrow
window
- a section row has a fixed height so a two-line label such as `REST,
GraphQL and Realtime APIs` has no space above or below it

## Solution

- fixes the alignment of wrapped labels in expandable rows, because a
`button` centers its text by default
- changes the section rows so it grows when its label wraps
- adds a two-line limit to the section row labels, so a longer label
ends with an ellipsis
- changes the expandable rows in the page tree from 36px to 32px, so
they match the link rows

| before | after |
|
---------------------------------------------------------------------------
|
--------------------------------------------------------------------------
|
| <img width="267" height="248" alt="image"
src="https://github.com/user-attachments/assets/09f27102-8d4d-471b-bde2-83adec5d6623"
/> | <img width="267" height="248" alt="image"
src="https://github.com/user-attachments/assets/cb0259ba-86ff-484d-844b-b6fce597d6e1"
/> |

## Preview links

| Site | Live | Preview | Search for |
| ---- |
-------------------------------------------------------------------------------------------------------------------
|
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ---------------------------------- |
| Docs |
[/docs/guides/realtime?docs-ia-mvp-v1=option-1](https://supabase.com/docs/guides/realtime?docs-ia-mvp-v1=option-1)
|
[/docs/guides/realtime?docs-ia-mvp-v1=option-1](https://docs-git-fix-docs-sidebar-wrapped-rows-supabase.vercel.app/docs/guides/realtime?docs-ia-mvp-v1=option-1)
| `Architecture, limits and pricing` |

## Review instructions

1. open
[/docs/guides/realtime?docs-ia-mvp-v1=option-1](https://docs-git-fix-docs-sidebar-wrapped-rows-supabase.vercel.app/docs/guides/realtime?docs-ia-mvp-v1=option-1)
2. make the window narrower until `Architecture, limits and pricing`
wraps in the sidebar
3. make sure that the label is left-aligned and that its chevron is on
the first line
4. click the back button at the top of the sidebar to open the `Build`
list
5. make sure that the `REST, GraphQL and Realtime APIs` row is taller
than the other rows, and that its icon and chevron are on the first line
6. make sure that each one-line row is 32px tall and that its icon is
level with its label
7. open the menu at a phone width, and make sure that its rows did not
change

## Checklist

Check all before review:

- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [ ] If I wrote a new docs topic or edited an existing topic, I used
the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs
[style
guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
2026-11-17 17:35:26 +02:00

197 lines
6.0 KiB
TypeScript

'use client'
import Link from 'next/link'
import React, { FC, type ReactNode } from 'react'
import { Badge, cn } from 'ui'
import {
TopNavMenu,
TopNavMenuGroup,
TopNavMenuGroupLink,
TopNavMenuItem,
TopNavMenuLink,
TopNavMenuPanel,
} from 'ui-patterns/TopNav/TopNavMenu'
import type { DropdownMenuItem, GlobalMenuItems } from '../Navigation.types'
import MenuIconPicker from './MenuIconPicker'
import { getMenuGroupLabelByPath } from './NavigationMenu.utils'
import { IA_NAV_PENDING_CLASS, useDocsPathname, useIaNavReady, useNavItems } from '@/features/IaNav'
interface MenuItemLabelProps {
title: ReactNode
icon?: ReactNode
community?: boolean
isNew?: boolean
experimental?: boolean
}
const GlobalNavigationMenu: FC = () => {
const { GLOBAL_MENU_ITEMS } = useNavItems()
const isNavReady = useIaNavReady()
const pathname = useDocsPathname()
const activeLabel = getMenuGroupLabelByPath({ menu: GLOBAL_MENU_ITEMS, pathname })
const itemClassName = cn(!isNavReady && IA_NAV_PENDING_CLASS)
return (
<>
<TopNavMenu data-docs-nav="top-nav" className="ml-3.5">
{GLOBAL_MENU_ITEMS.filter(([section]) => section.enabled !== false).map(([section]) => {
const label =
section.label === 'Home' ? <MenuIconPicker icon={section.icon || ''} /> : section.label
const ariaCurrent = activeLabel === section.label ? 'true' : undefined
return section.menuItems ? (
<TopNavMenuItem
key={section.label}
label={label}
aria-current={ariaCurrent}
className={itemClassName}
>
<TopNavMenuPanel>
{section.menuItems.map((group, index) => (
<GlobalMenuGroup
key={group[0].label}
items={group}
fallbackLabel={index === 0 ? section.label : undefined}
/>
))}
</TopNavMenuPanel>
</TopNavMenuItem>
) : (
<TopNavMenuLink
key={section.label}
linkAs={Link}
href={section.href || '#'}
aria-current={ariaCurrent}
className={itemClassName}
>
{label}
</TopNavMenuLink>
)
})}
</TopNavMenu>
<GlobalMenuPanelsFallback menuItems={GLOBAL_MENU_ITEMS} />
</>
)
}
// the menu panels mount on the client, so their links are also rendered for readers without JavaScript
const GlobalMenuPanelsFallback = ({ menuItems }: { menuItems: GlobalMenuItems }) => (
<noscript>
<nav aria-label="Docs sections" data-docs-nav="top-nav-subheads" className="sr-only">
{menuItems
.filter(([section]) => section.enabled !== false && section.menuItems)
.map(([section]) => (
<section key={section.label}>
<h2>{section.label}</h2>
{section.menuItems?.map((group) => {
const enabledItems = group.filter((item) => item.enabled !== false)
const heading = enabledItems.find((item) => !item.href)?.label
return (
<ul key={group[0].label} aria-label={heading}>
{enabledItems.map((item) =>
item.href ? (
<li key={item.href}>
<Link href={item.href}>{item.label}</Link>
</li>
) : null
)}
</ul>
)
})}
</section>
))}
</nav>
</noscript>
)
// an item without a link is the heading of its group. the first group falls back to the menu name
const GlobalMenuGroup = ({
items,
fallbackLabel,
}: {
items: DropdownMenuItem[]
fallbackLabel?: string
}) => {
const enabledItems = items.filter((item) => item.enabled !== false)
return (
<TopNavMenuGroup label={enabledItems.find((item) => !item.href)?.label ?? fallbackLabel}>
{enabledItems
.filter((item) => item.href)
.map((item) => (
<TopNavMenuGroupLink key={item.href} linkAs={Link} href={item.href}>
{item.label}
{item.community ? <Badge>Community</Badge> : null}
{item.new ? <Badge variant="success">New</Badge> : null}
{item.experimental ? <Badge variant="warning">Experimental</Badge> : null}
</TopNavMenuGroupLink>
))}
</TopNavMenuGroup>
)
}
export const MenuItemLabel = ({
title,
icon,
community,
isNew,
experimental,
}: MenuItemLabelProps) => (
<>
{icon ? (
<span aria-hidden className="flex h-5 shrink-0 items-center self-start">
{icon}
</span>
) : null}
<span className="line-clamp-2 flex-1">{title}</span>
{community ? <Badge>Community</Badge> : null}
{isNew ? <Badge variant="success">New</Badge> : null}
{experimental ? <Badge variant="warning">Experimental</Badge> : null}
</>
)
export const MenuItem = React.forwardRef<
React.ElementRef<'a'>,
React.ComponentPropsWithoutRef<'a'> & {
icon?: string
community?: boolean
new?: boolean
experimental?: boolean
}
>(
(
{ className, title, href = '', icon, community, new: isNew, experimental, children, ...props },
ref
) => {
return (
<Link
href={href}
ref={ref}
className={cn(
'group/menu-item flex items-center gap-2',
'w-full flex min-h-8 items-center text-foreground-light text-sm hover:text-foreground select-none rounded-md px-2 py-1.5 leading-5 no-underline focus-ring focus-visible:text-foreground',
className
)}
{...props}
>
{children ?? (
<MenuItemLabel
title={title}
icon={icon ? <MenuIconPicker icon={icon} className="text-foreground-lighter" /> : null}
community={community}
isNew={isNew}
experimental={experimental}
/>
)}
</Link>
)
}
)
GlobalNavigationMenu.displayName = 'GlobalNavigationMenu'
MenuItem.displayName = 'MenuItem'
export default GlobalNavigationMenu