fix(ui): keep floating menus within viewport

This commit is contained in:
2026-08-21 01:33:12 +03:30
parent 9722adc93e
commit 35472979d6
7 changed files with 109 additions and 7 deletions

View File

@@ -0,0 +1,33 @@
import { cleanup, render, screen } from '@testing-library/svelte';
import { afterEach, describe, expect, it } from 'vitest';
import FloatingContentHarness from './floating-content.test.svelte';
afterEach(cleanup);
describe('floating content primitives', () => {
it('bounds select menus to the available viewport with an internal scroll region', async () => {
render(FloatingContentHarness, { kind: 'select' });
const content = await screen.findByRole('listbox');
const viewport = content.querySelector('[data-select-viewport]');
expect(content.className).toContain('var(--bits-select-content-available-height)');
expect(viewport?.className).toContain('overscroll-contain');
expect(content.closest('[data-bits-floating-content-wrapper]')?.getAttribute('dir')).toBe('rtl');
});
it('bounds popovers and menus to their collision-aware available height', async () => {
const popoverView = render(FloatingContentHarness, { kind: 'popover' });
const popover = screen.getByText('محتوای جزئیات');
expect(popover.className).toContain('var(--bits-popover-content-available-height)');
expect(popover.closest('[data-bits-floating-content-wrapper]')?.getAttribute('dir')).toBe('rtl');
popoverView.unmount();
render(FloatingContentHarness, { kind: 'menu' });
const menu = screen.getByRole('menu');
expect(menu.className).toContain('var(--bits-dropdown-menu-content-available-height)');
expect(menu.className).toContain('overscroll-contain');
expect(menu.closest('[data-bits-floating-content-wrapper]')?.getAttribute('dir')).toBe('rtl');
});
});