Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions frontend/src/components/legacy-design/LegacyDesignScope.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import NiceModal from '@ebay/nice-modal-react';
import { cn } from '@/lib/utils';
import { useTheme } from '@/components/ThemeProvider';
import { Theme as AstryxTheme } from '@astryxdesign/core/theme';
import { OverlayScrollbar } from '@/components/legacy-design/OverlayScrollbar';
import { NativeTitleTooltipHost } from '@/components/ui/native-title-tooltip-host';
import { neutralTheme } from '@astryxdesign/theme-neutral/built';
// Astryx CSS cascade: reset → component styles → theme token overrides.
Expand Down Expand Up @@ -53,6 +54,7 @@ export function LegacyDesignScope({
<NiceModal.Provider>
{children}
<NativeTitleTooltipHost />
<OverlayScrollbar />
</NiceModal.Provider>
</AstryxTheme>
</WorkspaceOverlayProvider>
Expand Down
29 changes: 29 additions & 0 deletions frontend/src/components/legacy-design/OverlayScrollbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { useEffect, useRef } from 'react';
import { attachOverlayScrollbars } from './scrollbarOverlay';

export function OverlayScrollbar() {
const verticalRef = useRef<HTMLDivElement>(null);
const horizontalRef = useRef<HTMLDivElement>(null);

useEffect(() => {
const vertical = verticalRef.current;
const horizontal = horizontalRef.current;
if (!vertical || !horizontal) return undefined;
return attachOverlayScrollbars(document, { vertical, horizontal });
}, []);

return (
<>
<div
ref={verticalRef}
className="overlay-scrollbar-thumb overlay-scrollbar-thumb--y"
aria-hidden="true"
/>
<div
ref={horizontalRef}
className="overlay-scrollbar-thumb overlay-scrollbar-thumb--x"
aria-hidden="true"
/>
</>
);
}
149 changes: 149 additions & 0 deletions frontend/src/components/legacy-design/overlayScrollbar.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import { describe, expect, it } from 'vitest';
import {
EDGE_INSET,
THUMB_PX,
attachOverlayScrollbars,
findScroller,
thumbGeometry,
} from './scrollbarOverlay';

describe('thumbGeometry', () => {
it('returns null when the content fits', () => {
expect(
thumbGeometry({
clientSize: 100,
scrollSize: 100,
scrollOffset: 0,
trackSize: 100,
minThumb: 24,
})
).toBeNull();
});

it('places a thumb along the overflow without growing the track', () => {
const geo = thumbGeometry({
clientSize: 100,
scrollSize: 400,
scrollOffset: 150,
trackSize: 100,
minThumb: 24,
});

expect(geo).toEqual({ size: 25, offset: 37.5 });
});
});

describe('overlay scrollbar host', () => {
it('ignores scrollbars that already paint their own indicator', () => {
const editor = document.createElement('div');
editor.className = 'monaco-editor';
const scroller = document.createElement('div');
scroller.style.overflowY = 'auto';
Object.defineProperty(scroller, 'clientHeight', { value: 40 });
Object.defineProperty(scroller, 'scrollHeight', { value: 200 });
editor.append(scroller);
document.body.append(editor);

expect(findScroller(scroller, 'y')).toBeNull();
editor.remove();
});

it('shows a thumb on scroll without narrowing the scroller', () => {
const vertical = document.createElement('div');
const horizontal = document.createElement('div');
document.body.append(vertical, horizontal);
const detach = attachOverlayScrollbars(document, {
vertical,
horizontal,
});
const scroller = document.createElement('div');
scroller.style.overflowY = 'auto';
scroller.style.overflowX = 'hidden';
document.body.append(scroller);
Object.defineProperty(scroller, 'clientWidth', { value: 200 });
Object.defineProperty(scroller, 'clientHeight', { value: 100 });
Object.defineProperty(scroller, 'scrollWidth', { value: 200 });
Object.defineProperty(scroller, 'scrollHeight', { value: 400 });
Object.defineProperty(scroller, 'scrollTop', {
value: 0,
writable: true,
});
scroller.getBoundingClientRect = () =>
({
top: 10,
left: 20,
right: 220,
bottom: 110,
width: 200,
height: 100,
x: 20,
y: 10,
toJSON: () => ({}),
}) as DOMRect;
scroller.getClientRects = () =>
({
length: 1,
0: scroller.getBoundingClientRect(),
item: () => scroller.getBoundingClientRect(),
}) as unknown as DOMRectList;

scroller.dispatchEvent(new Event('scroll', { bubbles: true }));

expect(scroller.clientWidth).toBe(200);
expect(vertical.classList.contains('is-visible')).toBe(true);
expect(vertical.style.width).toBe(`${THUMB_PX}px`);
expect(vertical.style.left).toBe(`${220 - THUMB_PX - EDGE_INSET}px`);
detach();
vertical.remove();
horizontal.remove();
scroller.remove();
});

it('hides the thumb immediately when the pointer moves to another panel', () => {
const vertical = document.createElement('div');
const horizontal = document.createElement('div');
document.body.append(vertical, horizontal);
const detach = attachOverlayScrollbars(document, {
vertical,
horizontal,
});
const scroller = document.createElement('div');
scroller.style.overflowY = 'auto';
document.body.append(scroller);
Object.defineProperty(scroller, 'clientHeight', { value: 100 });
Object.defineProperty(scroller, 'scrollHeight', { value: 400 });
Object.defineProperty(scroller, 'clientWidth', { value: 200 });
Object.defineProperty(scroller, 'scrollWidth', { value: 200 });
scroller.getBoundingClientRect = () =>
({
top: 0,
left: 0,
right: 200,
bottom: 100,
width: 200,
height: 100,
x: 0,
y: 0,
toJSON: () => ({}),
}) as DOMRect;
scroller.getClientRects = () =>
({
length: 1,
item: () => scroller.getBoundingClientRect(),
}) as unknown as DOMRectList;

scroller.dispatchEvent(new Event('scroll', { bubbles: true }));
expect(vertical.classList.contains('is-visible')).toBe(true);

const otherPanel = document.createElement('button');
document.body.append(otherPanel);
otherPanel.dispatchEvent(new Event('pointerover', { bubbles: true }));

expect(vertical.classList.contains('is-visible')).toBe(false);
detach();
vertical.remove();
horizontal.remove();
scroller.remove();
otherPanel.remove();
});
});
Loading
Loading