feat(ui): scroll area (#54023)

## Problem

- on `/kb/guides/migrate-from-auth0` in safari 27 on macos, the mouse
wheel does not scroll the page and a trackpad does
- radix scroll area bar in the table of contents adds a non-passive
`wheel` listener on `document`
- webkit stops mouse-wheel page scroll when that listener meets
`overscroll-behavior-y: none` on `html`, which kb sets

## Solution

- replaces radix with base ui in the `ui` scroll area parts because base
ui binds its wheel listener to the scrollbar element
- replaces the radix `display: table` workarounds in the studio token
sheets and the connect sheet with a reset of the base ui content
`min-width`
- changes the docs ask ai scroll area to use the `ui` scroll area
- adds an inset focus ring to the scroll area viewport because base ui
makes an overflowing viewport focusable
- adds a `getAnimations` stub to the jsdom test setups because the base
ui viewport calls it
- adds `@base-ui/react` to the pnpm catalog + points the design system
scroll area page at the base ui docs

<!--
## Preview links

If relevant, include links to changed pages for easy review access.

Copy the preview base URL from the Vercel bot comment on this PR. Use
the following table as an example template.

| Site | Live | Preview | Search for |
| -------------- |
-------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------
| ----------------------------- |
| WWW | [/blog/your-post](https://supabase.com/blog/your-post) |
[/blog/your-post](https://zone-www-dot-com-git-branch-name-supabase.vercel.app/blog/your-post)
| unique phrase from the change |
| Docs |
[/docs/guides/your-page](https://supabase.com/docs/guides/your-page) |
[/docs/guides/your-page](https://docs-git-branch-name-supabase.vercel.app/docs/guides/your-page)
| unique phrase from the change |
| Studio | [/dashboard](https://supabase.com/dashboard) |
[/dashboard](https://studio-git-branch-name-supabase.vercel.app/dashboard)
| unique phrase from the change |
| Design system | [/design-system](https://supabase.com/design-system) |
[/design-system](https://design-system-git-branch-name-supabase.vercel.app/design-system)
| unique phrase from the change |
| UI library | [/library](https://supabase.com/library) |
[/library](https://ui-library-git-branch-name-supabase.vercel.app/library)
| unique phrase from the change |
| Knowledge base |
[/kb/guides/your-page](https://supabase.com/kb/guides/your-page) |
[/kb/guides/your-page](https://kb-git-branch-name-supabase.vercel.app/kb/guides/your-page)
| unique phrase from the change |
-->

<!-- ## Additional context

Optionally add any other context or screenshots.

-->

## Review instructions

1. open the preview
[/kb/guides/migrate-from-auth0](https://kb-git-antlio-ui-scroll-area-supabase.vercel.app/kb/guides/migrate-from-auth0)
in safari on macos with a mouse
2. turn the mouse wheel and make sure that the page scrolls and the
table of contents marks the active heading
3. open the preview
[/design-system/docs/components/scroll-area](https://design-system-git-antlio-ui-scroll-area-supabase.vercel.app/design-system/docs/components/scroll-area)
and make sure that each demo shows its bar on hover and scrolls with the
wheel
4. make sure that the horizontal demo scrolls sideways
5. press `tab` until a demo takes focus and make sure that it shows an
inset focus ring
6. open a project in the [studio
preview](https://studio-staging-git-antlio-ui-scroll-area-supabase.vercel.app/dashboard),
click `Connect` and make sure that a long code line scrolls inside its
code block and the sheet body does not scroll sideways
7. open the [docs
preview](https://docs-git-antlio-ui-scroll-area-supabase.vercel.app/docs),
press `cmd+k`, search for `auth` and make sure that the results list
scrolls

## 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)
This commit is contained in:
anthony lio authored and GitHub committed 2026-11-28 13:25:55 +02:00
1 parent 4e589266af
commit f05fe34966
15 files changed
+70 -76

No files matched your search

@@ -3,10 +3,9 @@ title: Scroll-area
description: Augments native scroll functionality for custom, cross-browser styling.
component: true
links:
doc: https://www.radix-ui.com/docs/primitives/components/scroll-area
api: https://www.radix-ui.com/docs/primitives/components/scroll-area#api-reference
doc: https://base-ui.com/react/components/scroll-area
api: https://base-ui.com/react/components/scroll-area#api-reference
source:
radix: true
shadcn: true
---
@@ -35,7 +34,7 @@ npx shadcn-ui@latest add scroll-area
<Step>Install the following dependencies:</Step>
```bash
npm install @radix-ui/react-scroll-area
npm install @base-ui/react
```
<Step>Copy and paste the following code into your project.</Step>
@@ -57,14 +57,14 @@ const resultsState: DocsSearchV2State = {
query: 'auth',
}
// cmdk and Radix lean on browser APIs jsdom doesn't ship
// cmdk and Base UI lean on browser APIs jsdom doesn't ship
beforeEach(() => {
globalThis.ResizeObserver ??= class {
observe() {}
unobserve() {}
disconnect() {}
}
Element.prototype.scrollIntoView ??= () => {}
Element.prototype.getAnimations ??= () => []
searchState = { status: 'initial', key: 0 }
aiMessages.length = 0
})
+7 -13
View File
@@ -1,6 +1,5 @@
'use client'
import { ScrollArea as ScrollAreaPrimitive } from 'radix-ui'
import {
useCallback,
useId,
@@ -11,7 +10,7 @@ import {
type Ref,
type UIEvent,
} from 'react'
import { cn } from 'ui'
import { cn, ScrollBar, ScrollRoot, ScrollViewport } from 'ui'
interface CurvedScrollAreaProps {
children: ReactNode
@@ -88,24 +87,19 @@ export function CurvedScrollArea({
}
return (
<ScrollAreaPrimitive.Root
<ScrollRoot
ref={measure}
style={{ '--curved-scroll-filter': `url(#${filterId})` } as CSSProperties}
className="curved-scroll-area relative"
>
<ScrollAreaPrimitive.Viewport
<ScrollViewport
ref={viewportRef}
onScroll={handleScroll}
className={cn('w-full', className)}
className={cn('w-full *:data-[slot=scroll-area-content]:min-w-0!', className)}
>
{children}
</ScrollAreaPrimitive.Viewport>
<ScrollAreaPrimitive.Scrollbar
orientation="vertical"
className="z-10 flex w-2.5 touch-none py-1.5 pr-1.5 select-none before:absolute before:inset-y-1.5 before:right-1.5 before:w-1 before:rounded-full before:bg-surface-300"
>
<ScrollAreaPrimitive.Thumb className="relative flex-1 rounded-full bg-foreground-muted/40 transition-colors hover:bg-foreground-muted/60" />
</ScrollAreaPrimitive.Scrollbar>
</ScrollViewport>
<ScrollBar className="z-10 before:bg-surface-300" />
<svg aria-hidden width="0" height="0" className="absolute">
<filter id={filterId} primitiveUnits="userSpaceOnUse" colorInterpolationFilters="sRGB">
<feFlood className="curved-scroll-area-neutral" result="neutral" />
@@ -139,6 +133,6 @@ export function CurvedScrollArea({
<feComposite in="blurredTop" in2="curved" operator="over" />
</filter>
</svg>
</ScrollAreaPrimitive.Root>
</ScrollRoot>
)
}
+1 -7
View File
@@ -1,13 +1,7 @@
.curved-scroll-area[data-scrolled] [data-radix-scroll-area-viewport] > * {
.curved-scroll-area[data-scrolled] [data-slot='scroll-area-content'] {
filter: var(--curved-scroll-filter);
}
.curved-scroll-area-neutral {
flood-color: rgb(128 128 128);
}
/* radix wraps the content in a display table, which grows to its widest line. a block keeps
long lines inside the area. radix sets the table inline, so this needs important */
.curved-scroll-area [data-radix-scroll-area-viewport] > div {
display: block !important;
}
@@ -166,7 +166,7 @@ export const NewScopedTokenForm = forwardRef<
return (
<>
<ScrollArea className="flex-1 [&>[data-radix-scroll-area-viewport]>div]:block!">
<ScrollArea className="flex-1 *:*:data-[slot=scroll-area-content]:min-w-0!">
{step === 'form' ? (
<Form {...form}>
<form id={FORM_ID} onSubmit={form.handleSubmit(handleReviewAccess)}>
@@ -150,10 +150,7 @@ export function ViewTokenSheet({ visible, tokenId, onClose }: ViewTokenSheetProp
</p>
<TokenDocsButtons />
</SheetHeader>
{/* Radix wraps viewport children in an inline-styled display:table div that grows to fit
the widest child, which would let one long endpoint path expand the sheet instead of
clipping — force it back to block so widths are bounded and rows can truncate. */}
<ScrollArea className="flex-1 [&>[data-radix-scroll-area-viewport]>div]:block!">
<ScrollArea className="flex-1 *:*:data-[slot=scroll-area-content]:min-w-0!">
<div className="space-y-6 px-5 sm:px-6 py-6">
{isTokenLoading && (
<div className="flex items-center justify-center py-8">
@@ -180,7 +180,7 @@ export const ConnectSheet = () => {
</SheetHeader>
<ScrollRoot className="flex min-h-0 min-w-0 flex-1 flex-col">
<ScrollViewport className="[&>div]:block!">
<ScrollViewport className="*:data-[slot=scroll-area-content]:min-w-0!">
<div className="flex min-w-0 flex-col divide-y">
<div className="p-8">
<ModeSelector
+3
View File
@@ -67,3 +67,6 @@ if (typeof window.localStorage?.getItem !== 'function') {
}
window.HTMLElement.prototype.hasPointerCapture = vi.fn()
// base ui scroll area calls getAnimations, which jsdom does not have
window.Element.prototype.getAnimations ??= () => []
@@ -155,7 +155,7 @@ export function SearchPanel({
{getStatusMessage()}
</div>
<ScrollRoot className="mx-px flex flex-col">
<ScrollViewport className="max-h-[min(477px,70dvh)] outline-hidden inset-shadow-2xs inset-shadow-border scroll-fade-bottom">
<ScrollViewport className="max-h-[min(477px,70dvh)] inset-shadow-2xs inset-shadow-border scroll-fade-bottom">
<CommandList
label={copy.resultsLabel}
className="h-(--cmdk-list-height) max-h-none overflow-visible transition-all duration-150 ease-enter motion-reduce:transition-none"
+3
View File
@@ -30,6 +30,9 @@ global.ResizeObserver = vi.fn().mockImplementation(function () {
// Mock scrollIntoView
Element.prototype.scrollIntoView = vi.fn()
// base ui scroll area calls getAnimations, which jsdom does not have
Element.prototype.getAnimations ??= () => []
afterEach(() => {
cleanup()
})
+1 -1
View File
@@ -15,7 +15,7 @@
"test:report": "open coverage/lcov-report/index.html"
},
"dependencies": {
"@base-ui/react": "^1.9.0",
"@base-ui/react": "catalog:",
"@tailwindcss/forms": "^0.5.11",
"@tailwindcss/typography": "^0.5.19",
"class-variance-authority": "^0.7.1",
@@ -1,15 +1,6 @@
import { act, render, screen } from '@testing-library/react'
import type { ComponentProps } from 'react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
vi.mock('radix-ui', async (importOriginal) => {
const actual = await importOriginal<typeof import('radix-ui')>()
const Root = ({ type }: ComponentProps<typeof actual.ScrollArea.Root>) => (
<div data-testid="scroll-root" data-type={type} />
)
return { ...actual, ScrollArea: { ...actual.ScrollArea, Root } }
})
const resizeCallbacks: Array<() => void> = []
// a detached element has no layout, so the browser reports zero for both widths
@@ -29,7 +20,7 @@ const mockScrollBarWidth = (width: number) => {
const renderScrollType = async () => {
// the scroll type lives in module state, so each test needs a fresh module
const { ScrollRoot } = await import('./scroll-area')
render(<ScrollRoot />)
render(<ScrollRoot data-testid="scroll-root" />)
return screen.getByTestId('scroll-root')
}
@@ -57,13 +48,13 @@ describe('ScrollRoot', () => {
it('always shows the bar when the os uses classic scroll bars', async () => {
mockScrollBarWidth(15)
expect(await renderScrollType()).toHaveAttribute('data-type', 'auto')
expect(await renderScrollType()).toHaveAttribute('data-scroll-type', 'classic')
})
it('shows the bar while scrolling when the os uses overlay scroll bars', async () => {
mockScrollBarWidth(0)
expect(await renderScrollType()).toHaveAttribute('data-type', 'scroll')
expect(await renderScrollType()).toHaveAttribute('data-scroll-type', 'overlay')
})
it('measures again when the os scroll bar setting changes', async () => {
@@ -73,13 +64,13 @@ describe('ScrollRoot', () => {
mockScrollBarWidth(15)
act(() => resizeCallbacks.forEach((callback) => callback()))
expect(root).toHaveAttribute('data-type', 'auto')
expect(root).toHaveAttribute('data-scroll-type', 'classic')
})
it('falls back to scroll without resizeobserver', async () => {
it('falls back to overlay without resizeobserver', async () => {
vi.stubGlobal('ResizeObserver', undefined)
mockScrollBarWidth(15)
expect(await renderScrollType()).toHaveAttribute('data-type', 'scroll')
expect(await renderScrollType()).toHaveAttribute('data-scroll-type', 'overlay')
})
})
@@ -1,12 +1,23 @@
'use client'
import { ScrollArea as ScrollAreaPrimitive } from 'radix-ui'
import { useSyncExternalStore, type ComponentProps } from 'react'
import { ScrollArea as ScrollAreaPrimitive } from '@base-ui/react/scroll-area'
import { useSyncExternalStore } from 'react'
import { cn } from '../../../lib/utils/cn'
type ScrollType = NonNullable<ScrollAreaPrimitive.ScrollAreaProps['type']>
type ScrollRootProps = Omit<ComponentProps<typeof ScrollAreaPrimitive.Root>, 'type'>
type ScrollType = 'classic' | 'overlay'
interface ScrollRootProps extends Omit<ScrollAreaPrimitive.Root.Props, 'className'> {
className?: string
}
interface ScrollViewportProps extends Omit<ScrollAreaPrimitive.Viewport.Props, 'className'> {
className?: string
}
interface ScrollBarProps extends Omit<ScrollAreaPrimitive.Scrollbar.Props, 'className'> {
className?: string
}
let scrollType: ScrollType | undefined
let probe: HTMLDivElement | undefined
@@ -15,7 +26,7 @@ const listeners = new Set<() => void>()
const getScrollType = (): ScrollType => {
if (scrollType) return scrollType
// jsdom has no resizeobserver. there is no cache here, so a test that adds a mock later still measures
if (typeof ResizeObserver === 'undefined') return 'scroll'
if (typeof ResizeObserver === 'undefined') return 'overlay'
// the os sends no event for its scroll bar setting. a change resizes this probe's content box, so the observer sees it
if (!probe) {
@@ -33,7 +44,7 @@ const getScrollType = (): ScrollType => {
if (!probe.isConnected) document.body.append(probe)
// classic scroll bars take layout width, overlay ones take none
scrollType = probe.offsetWidth > probe.clientWidth ? 'auto' : 'scroll'
scrollType = probe.offsetWidth > probe.clientWidth ? 'classic' : 'overlay'
return scrollType
}
@@ -46,12 +57,12 @@ const ScrollRoot = ({ className, ...props }: ScrollRootProps) => {
const type = useSyncExternalStore<ScrollType>(
subscribeToScrollType,
getScrollType,
() => 'scroll'
() => 'overlay'
)
return (
<ScrollAreaPrimitive.Root
type={type}
data-scroll-type={type}
className={cn('group/scroll-area overflow-hidden', className)}
{...props}
/>
@@ -66,27 +77,25 @@ const ScrollArea = ({ children, ...props }: ScrollRootProps) => (
</ScrollRoot>
)
const ScrollViewport = ({
className,
children,
...props
}: ComponentProps<typeof ScrollAreaPrimitive.Viewport>) => (
<ScrollAreaPrimitive.Viewport className={cn('size-full rounded-[inherit]', className)} {...props}>
{children}
const ScrollViewport = ({ className, children, ...props }: ScrollViewportProps) => (
<ScrollAreaPrimitive.Viewport
className={cn(
'size-full rounded-[inherit] focus-inset overflow-x-hidden! group-has-data-[orientation=horizontal]/scroll-area:overflow-x-scroll!',
className
)}
{...props}
>
<ScrollAreaPrimitive.Content data-slot="scroll-area-content">
{children}
</ScrollAreaPrimitive.Content>
</ScrollAreaPrimitive.Viewport>
)
const ScrollBar = ({
className,
orientation = 'vertical',
...props
}: ComponentProps<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>) => (
// radix hover mode ignores scroll. forcemount keeps the bar mounted, so css shows it on hover and scroll mode shows it on scroll
<ScrollAreaPrimitive.ScrollAreaScrollbar
forceMount
const ScrollBar = ({ className, orientation = 'vertical', ...props }: ScrollBarProps) => (
<ScrollAreaPrimitive.Scrollbar
orientation={orientation}
className={cn(
'flex touch-none select-none empty:hidden pointer-events-none opacity-0 transition-opacity data-[state=visible]:pointer-events-auto data-[state=visible]:opacity-100 group-hover/scroll-area:pointer-events-auto group-hover/scroll-area:opacity-100 group-has-[:focus-visible]/scroll-area:opacity-100 before:absolute before:rounded-full before:bg-tertiary-foreground/15',
'flex touch-none select-none pointer-events-none opacity-0 transition-opacity data-scrolling:pointer-events-auto data-scrolling:opacity-100 group-data-[scroll-type=classic]/scroll-area:pointer-events-auto group-data-[scroll-type=classic]/scroll-area:opacity-100 group-hover/scroll-area:pointer-events-auto group-hover/scroll-area:opacity-100 group-has-[:focus-visible]/scroll-area:opacity-100 before:absolute before:rounded-full before:bg-tertiary-foreground/15',
orientation === 'vertical' &&
'h-full w-2.5 py-1.5 pr-1.5 before:inset-y-1.5 before:right-1.5 before:w-1',
orientation === 'horizontal' &&
@@ -95,8 +104,8 @@ const ScrollBar = ({
)}
{...props}
>
<ScrollAreaPrimitive.ScrollAreaThumb className="relative flex-1 rounded-full bg-tertiary-foreground/40 transition-colors hover:bg-tertiary-foreground/60 forced-color-adjust-none forced-colors:bg-[CanvasText]" />
</ScrollAreaPrimitive.ScrollAreaScrollbar>
<ScrollAreaPrimitive.Thumb className="relative flex-1 rounded-full bg-tertiary-foreground/40 transition-colors hover:bg-tertiary-foreground/60 forced-color-adjust-none forced-colors:bg-[CanvasText]" />
</ScrollAreaPrimitive.Scrollbar>
)
export { ScrollArea, ScrollBar, ScrollRoot, ScrollViewport }
+4 -1
View File
@@ -199,6 +199,9 @@ settings:
catalogs:
default:
'@base-ui/react':
specifier: ^1.9.0
version: 1.9.0
'@monaco-editor/react':
specifier: 4.8.0-rc.3
version: 4.8.0-rc.3
@@ -3001,7 +3004,7 @@ importers:
packages/ui:
dependencies:
'@base-ui/react':
specifier: ^1.9.0
specifier: 'catalog:'
version: 1.9.0(@date-fns/tz@1.4.1)(@types/react@19.2.14)(date-fns@2.30.0)(react-dom@19.2.6(react@19.2.6))(react@19.2.6)
'@tailwindcss/forms':
specifier: ^0.5.11
+1
View File
@@ -11,6 +11,7 @@ updateNotifier: false
enableGlobalVirtualStore: false
catalog:
'@base-ui/react': ^1.9.0
'@monaco-editor/react': 4.8.0-rc.3
'@sentry/nextjs': ^10.75.2
'@sentry/node': ^10.75.2