mirror of
https://github.com/supabase/supabase.git
synced 2026-09-06 18:11:51 +08:00
## What kind of change does this PR introduce? Accessibility cleanup (DEPR-628). ## What is the current behavior? Leftover call sites still use ad-hoc focus recipes (`ring-foreground-muted`, `outline-brand`, Dialog/Sheet `focus:` rings, etc.) instead of the shared utilities from #41575. ## What is the new behavior? Converts those leftovers across `packages/ui`, Studio, www, docs, and design-system to `focus-ring`, preferring `focus-visible`. Keeps documented exceptions (`group-focus-visible`, InputGroup `:has()`). ## To test Tab through controls (keyboard only). Expect a consistent offset ring on `:focus-visible`, not a green/brand/custom stack, and no ring animation. ### www (marketing) Preview: https://zone-www-dot-com-git-danny-depr-628-focus-ring-fbccf9-supabase.vercel.app - Global nav on `/`: Product, Developers, Solutions dropdowns; logo; hamburger + mobile menu - `/features`: view toggles and feature cards - `/company`: card links - `/changelog`: timeline / entry links - `/partners/catalog`: grid/list toggle and partner cards - `/pricing`: compute section expand control - Product / Modules / Solutions sticky navs on product pages (e.g. `/database`, `/storage`) - `/state-of-startups`: TwoOptionToggle if present ### docs Preview: https://docs-git-danny-depr-628-focus-ring-long-tail-supabase.vercel.app - Any guide page: top nav dropdowns and items - Narrow viewport: hamburger, then mobile menu links + close - Guide with PromptPanel / tabs: tab to prompt actions and tab list ### studio (dashboard) Preview: https://studio-staging-git-danny-depr-628-focus-ring-long-tail-supabase.vercel.app - Project home: Connect section tiles; drag-handle focus on sortable sections - Integrations marketplace (`/project/<ref>/integrations`): featured cards, list/grid toggle, list rows - Auth (`/project/<ref>/auth/oauth-apps`, `/project/<ref>/auth/providers`): open create/edit sheet, tab to close (X) - Database policies (`/project/<ref>/database/policies`): open policy editor sheet, tab to close - Storage policies (`/project/<ref>/storage/files/policies`): bucket section links; policy modal close - Query performance (`/project/<ref>/observability/query-performance`): info icon buttons on metrics - Replication pipeline detail (if available): slot lag / status info icons - Support (`/support/new`): attachment add/remove controls - Table editor: spreadsheet import preview checkboxes; row text/JSON editor TwoOptionToggle - Any Dialog/Sheet/toast close (X): ring on keyboard focus only, not mouse click ### design-system Preview: https://design-system-git-danny-depr-628-focus-ring-long-tail-supabase.vercel.app - Colour palette swatches (keyboard focus) - Form patterns sidepanel example: avatar / focusable control in the example ## Additional context - Linear: [DEPR-628](https://linear.app/supabase/issue/DEPR-628) - Follow-ups: form-group CSS (DEPR-629), Storage columns selection (DEPR-630), ESLint rule (DEPR-632) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Accessibility & Usability** * Standardized keyboard focus indicators across navigation, dialogs, forms, buttons, toggles, links, and tooltips using a consolidated focus style. * Improved toggle controls to use proper button semantics (instead of clickable text), including `aria-pressed`/disabled handling and better keyboard navigation. * **Visual Updates** * Harmonized hover/focus ring visuals across the design system, Studio, documentation, and marketing pages while preserving existing layout and interaction behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
196 lines
7.5 KiB
TypeScript
196 lines
7.5 KiB
TypeScript
'use client'
|
|
|
|
import Link from 'next/link'
|
|
import { usePathname } from 'next/navigation'
|
|
import React, { FC, Fragment, useEffect, useState } from 'react'
|
|
import {
|
|
Badge,
|
|
cn,
|
|
MenubarSeparator,
|
|
NavigationMenu,
|
|
NavigationMenuContent,
|
|
NavigationMenuItem,
|
|
NavigationMenuLink,
|
|
NavigationMenuList,
|
|
NavigationMenuTrigger,
|
|
navigationMenuTriggerStyle,
|
|
} from 'ui'
|
|
|
|
import MenuIconPicker from './MenuIconPicker'
|
|
import { GLOBAL_MENU_ITEMS } from './NavigationMenu.constants'
|
|
|
|
/**
|
|
* Get TopNav active label based on current pathname
|
|
*/
|
|
export const useActiveMenuLabel = (menu: typeof GLOBAL_MENU_ITEMS) => {
|
|
const pathname = usePathname()
|
|
const [activeLabel, setActiveLabel] = useState('')
|
|
|
|
useEffect(() => {
|
|
// check if homepage
|
|
if (pathname === '/') {
|
|
return setActiveLabel('Home')
|
|
}
|
|
|
|
for (let index = 0; index < menu.length; index++) {
|
|
const section = menu[index]
|
|
if (section[0].enabled === false) continue
|
|
|
|
// check if first level menu items match beginning of url
|
|
if (section[0].href?.startsWith(pathname)) {
|
|
return setActiveLabel(section[0].label)
|
|
}
|
|
// check if second level menu items match beginning of url
|
|
if (section[0].menuItems) {
|
|
section[0].menuItems.map((menuItemGroup) =>
|
|
menuItemGroup
|
|
.filter((menuItem) => menuItem.enabled !== false)
|
|
.map(
|
|
(menuItem) => menuItem.href?.startsWith(pathname) && setActiveLabel(section[0].label)
|
|
)
|
|
)
|
|
}
|
|
}
|
|
}, [pathname, menu])
|
|
|
|
return activeLabel
|
|
}
|
|
|
|
const GlobalNavigationMenu: FC = () => {
|
|
const activeLabel = useActiveMenuLabel(GLOBAL_MENU_ITEMS)
|
|
const triggerClassName =
|
|
'h-(--header-height) p-2 bg-transparent border-0 border-b-2 border-transparent font-normal rounded-none text-foreground-light hover:bg-transparent hover:text-foreground data-open:bg-transparent! data-open:text-foreground! focus-ring focus-visible:text-foreground h-full focus-visible:rounded-sm shadow-none!'
|
|
|
|
return (
|
|
<div className="flex relative gap-2 justify-start items-end w-full h-full">
|
|
<NavigationMenu
|
|
delayDuration={0}
|
|
skipDelayDuration={0}
|
|
className="w-full flex justify-start h-full"
|
|
renderViewport={false}
|
|
viewportClassName="mt-0 max-w-screen overflow-hidden border-0 rounded-none mt-1.5 rounded-md border-x!"
|
|
>
|
|
<NavigationMenuList className="px-6 space-x-2 h-(--header-height)">
|
|
{GLOBAL_MENU_ITEMS.filter((section) => section[0].enabled !== false).map(
|
|
(section, sectionIdx) =>
|
|
section[0].menuItems ? (
|
|
<NavigationMenuItem
|
|
key={`desktop-docs-menu-section-${section[0].label}-${sectionIdx}`}
|
|
className="text-sm relative h-full"
|
|
>
|
|
<NavigationMenuTrigger
|
|
className={cn(
|
|
navigationMenuTriggerStyle(),
|
|
triggerClassName,
|
|
activeLabel === section[0].label && 'text-foreground border-foreground'
|
|
)}
|
|
>
|
|
{section[0].label === 'Home' ? (
|
|
<MenuIconPicker icon={section[0].icon || ''} />
|
|
) : (
|
|
section[0].label
|
|
)}
|
|
</NavigationMenuTrigger>
|
|
<NavigationMenuContent className="top-[calc(100%+4px)]! min-w-56 max-h-[calc(100vh-4rem)] border-y w-screen md:w-64 overflow-hidden overflow-y-auto rounded-none md:rounded-md md:border border-overlay bg-overlay text-foreground-light shadow-md duration-0!">
|
|
<div className="p-3 md:p-1">
|
|
{section[0].menuItems?.map((menuItem, menuItemIndex) => (
|
|
<Fragment
|
|
key={`desktop-docs-menu-section-${menuItemIndex}-${menuItemIndex}`}
|
|
>
|
|
{menuItemIndex !== 0 && <MenubarSeparator className="bg-border-muted" />}
|
|
{menuItem
|
|
.filter((item) => item.enabled !== false)
|
|
.map((item, itemIdx) =>
|
|
!item.href ? (
|
|
<div
|
|
key={`desktop-docs-menu-section-label-${item.label}-${itemIdx}`}
|
|
className="font-mono tracking-wider flex items-center text-foreground-muted text-xs uppercase rounded-md p-2 leading-none"
|
|
>
|
|
{item.label}
|
|
</div>
|
|
) : (
|
|
<NavigationMenuLink
|
|
key={`desktop-docs-menu-section-label-${item.label}-${itemIdx}`}
|
|
asChild
|
|
>
|
|
<MenuItem
|
|
href={item.href}
|
|
title={item.label}
|
|
community={item.community}
|
|
new={item.new}
|
|
icon={item.icon}
|
|
/>
|
|
</NavigationMenuLink>
|
|
)
|
|
)}
|
|
</Fragment>
|
|
))}
|
|
</div>
|
|
</NavigationMenuContent>
|
|
</NavigationMenuItem>
|
|
) : (
|
|
<NavigationMenuItem
|
|
key={`desktop-docs-menu-section-${section[0].label}-${sectionIdx}`}
|
|
className="text-sm relative h-full"
|
|
>
|
|
<NavigationMenuLink asChild>
|
|
<Link
|
|
href={section[0].href || '#'}
|
|
className={cn(
|
|
navigationMenuTriggerStyle(),
|
|
triggerClassName,
|
|
activeLabel === section[0].label && 'text-foreground border-foreground'
|
|
)}
|
|
>
|
|
{section[0].label === 'Home' ? (
|
|
<MenuIconPicker icon={section[0].icon || ''} />
|
|
) : (
|
|
section[0].label
|
|
)}
|
|
</Link>
|
|
</NavigationMenuLink>
|
|
</NavigationMenuItem>
|
|
)
|
|
)}
|
|
</NavigationMenuList>
|
|
</NavigationMenu>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export const MenuItem = React.forwardRef<
|
|
React.ElementRef<'a'>,
|
|
React.ComponentPropsWithoutRef<'a'> & {
|
|
icon?: string
|
|
community?: boolean
|
|
new?: boolean
|
|
}
|
|
>(({ className, title, href = '', icon, community, new: isNew, children, ...props }, ref) => {
|
|
return (
|
|
<Link
|
|
href={href}
|
|
ref={ref}
|
|
className={cn(
|
|
'group/menu-item flex items-center gap-2',
|
|
'w-full flex h-8 items-center text-foreground-light text-sm hover:text-foreground select-none rounded-md p-2 leading-none no-underline focus-ring focus-visible:text-foreground',
|
|
className
|
|
)}
|
|
{...props}
|
|
>
|
|
{children ?? (
|
|
<>
|
|
{icon && <MenuIconPicker icon={icon} className="text-foreground-lighter" />}
|
|
<span className="flex-1">{title}</span>
|
|
{community && <Badge>Community</Badge>}
|
|
{isNew && <Badge variant="success">New</Badge>}
|
|
</>
|
|
)}
|
|
</Link>
|
|
)
|
|
})
|
|
|
|
GlobalNavigationMenu.displayName = 'GlobalNavigationMenu'
|
|
MenuItem.displayName = 'MenuItem'
|
|
|
|
export default GlobalNavigationMenu
|