mirror of
https://github.com/supabase/supabase.git
synced 2026-09-07 02:20:52 +08:00
## What kind of change does this PR introduce? A11y cleanup follow-up to #47984 / [DEPR-626](https://linear.app/supabase/issue/DEPR-626). ## What is the current behavior? Studio had 82 ratcheted `supabase/require-explicit-tabindex` violations (raw `<button>` / `role="button"` without explicit `tabIndex`). ## What is the new behavior? - Explicit `tabIndex={0}` (or disabled → `-1`) on those Studio call sites across nav, `components/ui`, Database, Storage, and the remainder - Ratchet baseline cleared (**82 → 0**) and the rule **removed from the Studio ratchet** (debt is gone; ratchet is temporary) - Rule remains a shared **`warn`** for now — promoting to `error` (and sweeping www/docs/design-system) is a follow-up - Also fixed the learn/ui-library call sites that surfaced while experimenting with error promotion - Small follow-ups where making controls focusable exposed gaps: accessible names, disabled/focus consistency, focus-ring polish on To-test surfaces, home section `KeyboardSensor`, and an E2E locator tightened after `aria-label="Remove column"` Prefer migrating to `Button` from `ui` in future touch-ups; this PR takes the minimal path so Studio debt can stay at zero. ## Additional context Batches landed together so baseline conflicts stayed simple while chipping away: - Hotspots / nav (FirstLevelNav, Marketplace, AttachmentUpload, Column, Tabs, …) - `components/ui` shared - Database + Storage - Remainder **Out of scope / intentional deferrals** - Promoting `supabase/require-explicit-tabindex` to a lint **error** (follow-up after www/docs/design-system sweeps) - Tabs/Radio roving, tooltips, context menus, in-menu items - Full keyboard-accessible tab-close UX (close stays hover + `tabIndex={-1}`; context menu still closes tabs) - Data API docs links (`/project/<ref>/api` redirect) **Reviewer notes** - Rule only flags raw `<button>` / `role="button"` without a `tabIndex` prop. `Button` from `ui` already bakes this in - `tabIndex={-1}` is intentional for disabled controls, in-menu / roving-focus children, and hover-only tab close - For dnd-kit grips, put `tabIndex` **after** `{...attributes}` so it isn’t overwritten (TS2783) ### To test Use **Safari** with macOS Keyboard navigation **off** (System Settings → Keyboard). Chrome once for a sanity pass. For each surface below: Tab until the control is focused, then activate with Enter/Space where relevant. 1. **API Docs side panel** (Table Editor → open a table → **API docs**) - Floating API Docs panel — **not** `/project/<ref>/api` (that redirects to Data API docs; language ToggleGroup uses arrow keys; links are out of scope) - Left nav buttons — Tab through several and activate one; active highlight / navigation still works 2. **Integrations → Marketplace** - Enable **Integrations layout** feature preview first (avatar menu → Feature previews) - `/org/<slug>/integrations` or project integrations marketplace - “Clear all”, grid/list toggles — Tab + activate 3. **Table Editor → create a table → Columns** - Drag handles only appear while **creating** (not when editing an existing table) - Tab to grip / remove (X) / sensitive-data eye if shown 4. **Project Home** — section drag handles - Tab to a grip (visible focus ring) - Optional: Space to pick up, arrows to move, Space/Esc to drop (KeyboardSensor added) - Mouse dnd still works 5. **Storage → Policies** — expand/collapse bucket list chevron (design-system focus ring, no stuck grey open bg) 6. **Support form** (Help → Support) — attachment remove (×) and add-attachment control when visible Disabled controls should be **skipped** by Tab. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Accessibility Improvements** * Improved keyboard navigation throughout Studio by explicitly managing focus (`tabIndex`) across many interactive controls (menus, tabs, tables, charts, dialogs, navigation, and form actions). * Disabled or non-interactive controls are now removed from the tab order (or made unfocusable), while available actions remain reachable. * Ensured `type="button"` on relevant controls to prevent unintended submissions, and refined keyboard focus behavior for various toggles and copy/remove actions. * **Chores** * Updated the ESLint rule baseline configuration to match the new focus behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
328 lines
10 KiB
TypeScript
328 lines
10 KiB
TypeScript
import { useParams } from 'common'
|
|
import { Book, BookOpen } from 'lucide-react'
|
|
import Link from 'next/link'
|
|
import { Fragment, type ReactNode } from 'react'
|
|
import SVG from 'react-inlinesvg'
|
|
import { Button, cn } from 'ui'
|
|
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
|
|
|
|
import { navigateToSection } from './Content/Content.utils'
|
|
import { API_DOCS_CATEGORIES, DOCS_CONTENT, DOCS_MENU } from './ProjectAPIDocs.constants'
|
|
import { useApiDocsFunctions, useApiDocsTables } from './useApiDocsEntities'
|
|
import { InfiniteListDefault, type RowComponentBaseProps } from '@/components/ui/InfiniteList'
|
|
import { NotExposedEntitiesIndicator } from '@/components/ui/NotExposedEntitiesIndicator'
|
|
import { useEdgeFunctionsQuery } from '@/data/edge-functions/edge-functions-query'
|
|
import { usePaginatedBucketsQuery, type Bucket } from '@/data/storage/buckets-query'
|
|
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
|
|
import { BASE_PATH, DOCS_URL } from '@/lib/constants'
|
|
import { useAppStateSnapshot } from '@/state/app-state'
|
|
|
|
type DocsSections = typeof DOCS_MENU
|
|
type DocsSection = DocsSections[number]
|
|
type DocsSectionsSubset = readonly DocsSection[]
|
|
type DocsCategory = DocsSection['key']
|
|
type DocsContentRegistry = typeof DOCS_CONTENT
|
|
type DocsSnippet = DocsContentRegistry[keyof DocsContentRegistry]
|
|
|
|
const Separator = () => <hr className="border-t mt-3! pb-1 mx-3" />
|
|
|
|
const MENU_BUTTON_CLASSES = cn(
|
|
'w-full px-4',
|
|
'text-left text-sm text-foreground-light',
|
|
'transition hover:text-foreground'
|
|
)
|
|
|
|
/**
|
|
* Gets the docs menu items based on feature flags.
|
|
* @returns An array of menu items to be displayed in the docs navigation.
|
|
*/
|
|
const useDocsMenu = (): DocsSectionsSubset => {
|
|
const {
|
|
projectAuthAll: authEnabled,
|
|
projectStorageAll: storageEnabled,
|
|
projectEdgeFunctionAll: edgeFunctionsEnabled,
|
|
realtimeAll: realtimeEnabled,
|
|
} = useIsFeatureEnabled([
|
|
'project_auth:all',
|
|
'project_storage:all',
|
|
'project_edge_function:all',
|
|
'realtime:all',
|
|
])
|
|
|
|
return DOCS_MENU.filter((item) => {
|
|
if (item.key === 'user-management') return authEnabled
|
|
if (item.key === 'storage') return storageEnabled
|
|
if (item.key === 'edge-functions') return edgeFunctionsEnabled
|
|
if (item.key === 'realtime') return realtimeEnabled
|
|
return true
|
|
})
|
|
}
|
|
|
|
/**
|
|
* Gets the content snippets for a given documentation category.
|
|
* @param category - The category of documentation to retrieve snippets for.
|
|
* @returns An array of content snippets belonging to the specified category.
|
|
*/
|
|
const getSectionSnippets = (category: DocsCategory): DocsSnippet[] =>
|
|
Object.values(DOCS_CONTENT).filter((snippet) => snippet.category === category)
|
|
|
|
export const FirstLevelNav = (): ReactNode => {
|
|
const { ref } = useParams()
|
|
|
|
const snap = useAppStateSnapshot()
|
|
const currentSection = snap.activeDocsSection[0]
|
|
|
|
const docsMenu = useDocsMenu()
|
|
|
|
return (
|
|
<>
|
|
<nav aria-labelledby="api-docs-rest-categories" className="px-2 py-4 border-b">
|
|
<h2 id="api-docs-rest-categories" className="sr-only">
|
|
REST API Docs
|
|
</h2>
|
|
{docsMenu.map((item) => {
|
|
const isActive = currentSection === item.key
|
|
|
|
return (
|
|
<Fragment key={item.key}>
|
|
<button
|
|
tabIndex={0}
|
|
aria-current={isActive ? 'page' : undefined}
|
|
className={cn(
|
|
'w-full px-3 py-2 rounded-md',
|
|
'text-left text-sm',
|
|
'transition',
|
|
isActive && 'bg-surface-300'
|
|
)}
|
|
onClick={() => snap.setActiveDocsSection([item.key])}
|
|
>
|
|
{item.name}
|
|
</button>
|
|
{isActive && <Subsections category={item.key} />}
|
|
</Fragment>
|
|
)
|
|
})}
|
|
</nav>
|
|
|
|
<div className="px-2 py-4 border-b">
|
|
<Button
|
|
block
|
|
asChild
|
|
variant="text"
|
|
size="small"
|
|
icon={
|
|
<SVG
|
|
src={`${BASE_PATH}/img/graphql.svg`}
|
|
style={{ width: `${16}px`, height: `${16}px` }}
|
|
className="text-foreground"
|
|
preProcessor={(code) => code.replace(/svg/, 'svg class="m-auto text-color-inherit"')}
|
|
/>
|
|
}
|
|
onClick={() => snap.setShowProjectApiDocs(false)}
|
|
>
|
|
<Link className="justify-start!" href={`/project/${ref}/integrations/graphiql`}>
|
|
GraphiQL
|
|
</Link>
|
|
</Button>
|
|
<Button block asChild variant="text" size="small" icon={<BookOpen />}>
|
|
<Link
|
|
href={`${DOCS_URL}/guides/graphql`}
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
className="justify-start!"
|
|
>
|
|
GraphQL guide
|
|
</Link>
|
|
</Button>
|
|
</div>
|
|
|
|
<div className="px-2 py-4">
|
|
<Button block asChild variant="text" size="small" icon={<Book />}>
|
|
<Link href={`${DOCS_URL}`} target="_blank" rel="noreferrer" className="justify-start!">
|
|
Documentation
|
|
</Link>
|
|
</Button>
|
|
<Button block asChild variant="text" size="small" icon={<BookOpen />}>
|
|
<Link
|
|
href={`${DOCS_URL}/guides/api`}
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
className="justify-start!"
|
|
>
|
|
REST guide
|
|
</Link>
|
|
</Button>
|
|
</div>
|
|
</>
|
|
)
|
|
}
|
|
|
|
type SubsectionsProps = {
|
|
category: DocsCategory
|
|
}
|
|
|
|
const Subsections = ({ category }: SubsectionsProps): ReactNode => {
|
|
const snippets = getSectionSnippets(category)
|
|
|
|
return (
|
|
<div className="space-y-2 py-2">
|
|
{snippets.map((snippet) => (
|
|
<button
|
|
key={snippet.key}
|
|
tabIndex={0}
|
|
className={MENU_BUTTON_CLASSES}
|
|
onClick={() => {
|
|
navigateToSection(snippet.key)
|
|
}}
|
|
>
|
|
{snippet.title}
|
|
</button>
|
|
))}
|
|
{category === API_DOCS_CATEGORIES.ENTITIES && <TablesSubsections />}
|
|
{category === API_DOCS_CATEGORIES.STORED_PROCEDURES && <DbFunctionsSubsections />}
|
|
{category === API_DOCS_CATEGORIES.STORAGE && <StorageSubsections />}
|
|
{category === API_DOCS_CATEGORIES.EDGE_FUNCTIONS && <EdgeFunctionsSubsections />}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
const TablesSubsections = (): ReactNode => {
|
|
const snap = useAppStateSnapshot()
|
|
|
|
const { visibleEntities: tables, excludedCount, isLoading } = useApiDocsTables()
|
|
|
|
// TODO: handle infinite loading of tables
|
|
return (
|
|
<>
|
|
{isLoading && <LoadingIndicator />}
|
|
{(tables.length > 0 || excludedCount > 0) && <Separator />}
|
|
{tables.map((table) => (
|
|
<button
|
|
key={table.name}
|
|
tabIndex={0}
|
|
className={MENU_BUTTON_CLASSES}
|
|
onClick={() => snap.setActiveDocsSection([API_DOCS_CATEGORIES.ENTITIES, table.name])}
|
|
>
|
|
{table.name}
|
|
</button>
|
|
))}
|
|
<NotExposedEntitiesIndicator
|
|
count={excludedCount}
|
|
entityNoun="table"
|
|
entityNounPlural="tables"
|
|
onNavigate={() => snap.setShowProjectApiDocs(false)}
|
|
/>
|
|
</>
|
|
)
|
|
}
|
|
|
|
const DbFunctionsSubsections = (): ReactNode => {
|
|
const snap = useAppStateSnapshot()
|
|
|
|
const { visibleEntities: functions, excludedCount, isLoading } = useApiDocsFunctions()
|
|
|
|
// TODO: handle virtualization of DB functions
|
|
return (
|
|
<>
|
|
{isLoading && <LoadingIndicator />}
|
|
{(functions.length > 0 || excludedCount > 0) && <Separator />}
|
|
{functions.map((fn) => (
|
|
<button
|
|
key={fn.name}
|
|
tabIndex={0}
|
|
className={MENU_BUTTON_CLASSES}
|
|
onClick={() =>
|
|
snap.setActiveDocsSection([API_DOCS_CATEGORIES.STORED_PROCEDURES, fn.name])
|
|
}
|
|
>
|
|
{fn.name}
|
|
</button>
|
|
))}
|
|
<NotExposedEntitiesIndicator
|
|
count={excludedCount}
|
|
entityNoun="function"
|
|
entityNounPlural="functions"
|
|
onNavigate={() => snap.setShowProjectApiDocs(false)}
|
|
/>
|
|
</>
|
|
)
|
|
}
|
|
|
|
const BucketButton = ({ item: bucket, style }: RowComponentBaseProps<Bucket>) => {
|
|
const snap = useAppStateSnapshot()
|
|
|
|
return (
|
|
<button
|
|
key={bucket.name}
|
|
tabIndex={0}
|
|
className={cn(MENU_BUTTON_CLASSES, 'py-1')}
|
|
style={style}
|
|
onClick={() => snap.setActiveDocsSection([API_DOCS_CATEGORIES.STORAGE, bucket.name])}
|
|
>
|
|
{bucket.name}
|
|
</button>
|
|
)
|
|
}
|
|
|
|
const StorageSubsections = (): ReactNode => {
|
|
const { ref } = useParams()
|
|
|
|
const { data, isLoading, isFetchingNextPage, hasNextPage, fetchNextPage } =
|
|
usePaginatedBucketsQuery({
|
|
projectRef: ref,
|
|
})
|
|
const buckets = data?.pages.flatMap((page) => page) ?? []
|
|
|
|
return (
|
|
<>
|
|
{isLoading && <LoadingIndicator />}
|
|
{buckets.length > 0 && <Separator />}
|
|
<InfiniteListDefault
|
|
className="max-h-80"
|
|
items={buckets}
|
|
getItemKey={(idx) => buckets[idx]?.name}
|
|
getItemSize={() => 28}
|
|
hasNextPage={!!hasNextPage}
|
|
isLoadingNextPage={isFetchingNextPage}
|
|
onLoadNextPage={fetchNextPage}
|
|
ItemComponent={BucketButton}
|
|
LoaderComponent={({ style }) => <LoadingIndicator style={{ ...style, width: '75%' }} />}
|
|
/>
|
|
</>
|
|
)
|
|
}
|
|
|
|
const EdgeFunctionsSubsections = (): ReactNode => {
|
|
const { ref } = useParams()
|
|
const snap = useAppStateSnapshot()
|
|
|
|
const { data: edgeFunctions, isLoading } = useEdgeFunctionsQuery({ projectRef: ref })
|
|
|
|
// TODO: handle virtualization of edge functions
|
|
return (
|
|
<>
|
|
{isLoading && <LoadingIndicator />}
|
|
{(edgeFunctions ?? []).length > 0 && <Separator />}
|
|
{(edgeFunctions ?? []).map((fn) => (
|
|
<button
|
|
key={fn.name}
|
|
tabIndex={0}
|
|
className={MENU_BUTTON_CLASSES}
|
|
onClick={() => snap.setActiveDocsSection([API_DOCS_CATEGORIES.EDGE_FUNCTIONS, fn.name])}
|
|
>
|
|
{fn.name}
|
|
</button>
|
|
))}
|
|
</>
|
|
)
|
|
}
|
|
|
|
type LoadingIndicatorProps = {
|
|
className?: string
|
|
style?: React.CSSProperties
|
|
}
|
|
|
|
const LoadingIndicator = ({ className, style }: LoadingIndicatorProps) => (
|
|
<ShimmeringLoader style={style} className={cn('mx-2', className)} />
|
|
)
|