Files
Danny White c8aca8d3a0 chore(design-system): standardise keyboard focus rings (#41575)
## I have read the
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
file.

YES

## What kind of change does this PR introduce?

UI / design-system consistency (accessibility).

## What is the current behavior?

Keyboard focus rings are inconsistent across Studio and `packages/ui`:

- Custom Button uses thick `outline` with per-variant colours (brand /
grey / destructive / warning)
- Form controls use muted grey rings (`ring-background-control`)
- Tabs / NavMenu / Radio use soft brand `ring-ring`
- Studio `.inset-focus` uses dark green `outline-brand-600`

Related: [DEPR-354](https://linear.app/supabase/issue/DEPR-354).

## What is the new behavior?

One shared focus recipe, exposed as Tailwind `@utility` classes in
`packages/config/css/utilities.css`:

| Utility | Use when |
| --- | --- |
| `focus-ring` | Buttons, inputs, most controls (offset ring) |
| `focus-inset` | Dense/flush surfaces such as interactive table rows
(renamed from `inset-focus`) |

```txt
# focus-ring
outline-hidden
focus-visible:ring-2
focus-visible:ring-ring
focus-visible:ring-offset-2
focus-visible:ring-offset-background
```

Applied on Button, shadcn form controls, Menu/NavMenu, Command palette
trigger, Studio table rows, and related call sites. Documented in the
design-system accessibility docs. Variants do not change focus ring
colour.

When the ring must appear on a different element than the focused one
(e.g. Menu + ProductMenu `Link` via `group-focus-visible`, or InputGroup
via `:has()`), keep an explicit ring stack. The utilities bake in
`:focus-visible` on the same element.

## Additional context

**Out of scope**

- Full `packages/ui` / Studio / www sweep
- Legacy Studio form-group green box-shadow cleanup
- ESLint rule for bare `outline-none`

## Test plan

Prefer Safari (“hard mode” for `tabIndex`). Expect one soft brand ring
everywhere: not grey, not solid green outline.

### Design system

- [ ]
[Accessibility](https://design-system-git-dnywh-choreimprove-tab-focus-styles-supabase.vercel.app/design-system/docs/accessibility):
recipe docs match what you see
- [ ]
[Button](https://design-system-git-dnywh-choreimprove-tab-focus-styles-supabase.vercel.app/design-system/docs/components/button):
Tab primary / default / danger; same ring colour
- [ ] [Table → Row-level
navigation](https://design-system-git-dnywh-choreimprove-tab-focus-styles-supabase.vercel.app/design-system/docs/components/table#row-level-navigation):
Tab an interactive row; inset outline (`focus-inset`) sits inside the
row

### Studio

- [ ] **Org home → table view** (`/organizations/_` or org projects):
switch to the table layout, Tab onto a project row; inset outline sits
inside the row (list/card view uses CardButton, not `focus-inset`)
- [ ] **Project sidebar** (Database, Auth, Storage, …): Tab the main
product nav links; ring follows the focused item (not the nested section
menus like Tables / Roles)
- [ ] **Storage → Files**: Tab a bucket row; same inset outline as org
table rows
- [ ] **Project Settings → General** (or Compute and Disk): Tab through
inputs, checkboxes, switches, selects; same offset ring, no ring on
mouse click
- [ ] **Header ⌘K** (desktop width): Tab to the search control after
Feedback; same soft brand `focus-ring` (was a thicker
`ring-border-strong` before)
- [ ] **Table Editor or SQL Editor tabs**: focus a tab, Tab to × if
active; close shows a ring
- [ ] **Light + dark**: ring stays visible against both backgrounds
2026-07-22 12:10:07 -04:00

158 lines
5.4 KiB
TypeScript

import { FilesBucket as FilesBucketIcon } from 'icons'
import { ChevronRight } from 'lucide-react'
import { KeyboardEventHandler, MouseEventHandler } from 'react'
import { Badge, cn, TableCell, TableRow, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
import type { AllowedBucketType } from './types'
import { PUBLIC_BUCKET_TOOLTIP } from '@/components/interfaces/Storage/Storage.constants'
import { useBucketPolicyCount } from '@/components/interfaces/Storage/useBucketPolicyCount'
import { VirtualizedTableCell, VirtualizedTableRow } from '@/components/ui/VirtualizedTable'
import { Bucket } from '@/data/storage/buckets-query'
import { formatBytes } from '@/lib/helpers'
type BucketTableMode = 'standard' | 'virtualized'
type BucketTableEmptyStateProps = {
mode: BucketTableMode
filterString: string
}
export const BucketTableEmptyState = ({ mode, filterString }: BucketTableEmptyStateProps) => {
const BucketTableRow = mode === 'standard' ? TableRow : VirtualizedTableRow
const BucketTableCell = mode === 'standard' ? TableCell : VirtualizedTableCell
return (
<BucketTableRow className="[&>td]:hover:bg-inherit">
<BucketTableCell colSpan={5}>
<p className="text-sm text-foreground">No results found</p>
<p className="text-sm text-foreground-lighter">
Your search for {filterString} did not return any results
</p>
</BucketTableCell>
</BucketTableRow>
)
}
type BucketTableRowProps = {
mode: BucketTableMode
bucket: Bucket
onSelectBucket: (bucket: Bucket) => void
allowedBucketType: AllowedBucketType
formattedGlobalUploadLimit: string
}
export const BucketTableRow = ({
mode,
bucket,
onSelectBucket,
allowedBucketType,
formattedGlobalUploadLimit,
}: BucketTableRowProps) => {
const { getPolicyCount } = useBucketPolicyCount()
const BucketTableRow = mode === 'standard' ? TableRow : VirtualizedTableRow
const BucketTableCell = mode === 'standard' ? TableCell : VirtualizedTableCell
const isDisabled = !(
allowedBucketType === 'all' ||
(allowedBucketType === 'public' && bucket.public) ||
(allowedBucketType === 'private' && !bucket.public)
)
const handleRowActivate: MouseEventHandler<HTMLTableRowElement> = (e) => {
e.preventDefault()
if (isDisabled) return
onSelectBucket(bucket)
}
const handleRowKeyDown: KeyboardEventHandler<HTMLTableRowElement> = (e) => {
if (isDisabled) return
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault()
onSelectBucket(bucket)
}
}
return (
<Tooltip>
<TooltipTrigger asChild>
<BucketTableRow
key={bucket.id}
data-bucket-id={bucket.id}
className={cn(
'relative cursor-pointer h-16 group focus-inset',
isDisabled && 'opacity-50 [&>td]:hover:bg-transparent cursor-not-allowed'
)}
onClick={handleRowActivate}
onKeyDown={handleRowKeyDown}
tabIndex={isDisabled ? -1 : 0}
aria-disabled={isDisabled || undefined}
>
<BucketTableCell className="w-2 pr-1">
<FilesBucketIcon aria-label="bucket icon" size={16} className="text-foreground-muted" />
</BucketTableCell>
<BucketTableCell className="flex-1">
<div className="flex items-center gap-2.5">
<p className="whitespace-nowrap max-w-[512px] truncate">{bucket.id}</p>
{bucket.public && (
<Tooltip>
<TooltipTrigger asChild>
<Badge variant="warning" className="flex">
Public
</Badge>
</TooltipTrigger>
<TooltipContent side="top">{PUBLIC_BUCKET_TOOLTIP}</TooltipContent>
</Tooltip>
)}
</div>
</BucketTableCell>
<BucketTableCell>
<p className="text-foreground-light">{getPolicyCount(bucket.id)}</p>
</BucketTableCell>
<BucketTableCell>
<p
className={`whitespace-nowrap ${bucket.file_size_limit ? 'text-foreground-light' : 'text-foreground-muted'}`}
>
{bucket.file_size_limit
? formatBytes(bucket.file_size_limit)
: `Unset (${formattedGlobalUploadLimit})`}
</p>
</BucketTableCell>
<BucketTableCell>
<p
className={
bucket.allowed_mime_types ? 'text-foreground-light' : 'text-foreground-muted'
}
>
{bucket.allowed_mime_types ? bucket.allowed_mime_types.join(', ') : 'Any'}
</p>
</BucketTableCell>
<BucketTableCell>
{!isDisabled && (
<>
<div className="flex justify-end items-center h-full">
<ChevronRight aria-hidden={true} size={14} className="text-foreground-muted/60" />
</div>
<button tabIndex={-1} className="sr-only">
Go to bucket details
</button>
</>
)}
</BucketTableCell>
</BucketTableRow>
</TooltipTrigger>
{isDisabled && (
<TooltipContent>
{allowedBucketType === 'public'
? 'Private buckets are not selectable for this action. Please select a public bucket.'
: 'Public buckets are not selectable for this action. Please select a private bucket.'}
</TooltipContent>
)}
</Tooltip>
)
}