fix: Prevent gallery auto-scrolling from scrolling entire browser (#1824)

- Closes #1814
This commit is contained in:
Dermot Duffy
2025-01-11 16:44:05 -08:00
committed by GitHub
parent addf6edb30
commit 1f37895793
6 changed files with 60 additions and 2 deletions
+33
View File
@@ -0,0 +1,33 @@
import { compute as computeScroll } from 'compute-scroll-into-view';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { scrollIntoView } from '../../src/utils/scroll';
vi.mock('compute-scroll-into-view');
// @vitest-environment jsdom
describe('scrollIntoView', () => {
beforeEach(() => {
vi.clearAllMocks();
});
it('should call computeScroll with the correct arguments', () => {
const element = document.createElement('div');
vi.mocked(computeScroll).mockReturnValue([
{
el: element,
top: 42,
left: 142,
},
]);
const options = { block: 'start' as const, inline: 'nearest' as const };
expect(element.scrollTop).toBe(0);
expect(element.scrollLeft).toBe(0);
scrollIntoView(element, options);
expect(computeScroll).toBeCalledWith(element, options);
expect(element.scrollTop).toBe(42);
expect(element.scrollLeft).toBe(142);
});
});