Skip to content
Open
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
6 changes: 6 additions & 0 deletions .changeset/fix-component-menu-scroll-lock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@keystar/ui': patch
'@keystatic/core': patch
---

Lock background wheel and touch scrolling while component-selection dropdowns and popovers are open, and prevent overscroll chaining from option lists
4 changes: 3 additions & 1 deletion design-system/pkg/src/combobox/ComboboxMulti.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, { ForwardedRef, ReactElement, useRef } from 'react';
import { useProviderProps } from '@keystar/ui/core';
import { FieldPrimitive } from '@keystar/ui/field';
import { ListBoxBase, listStyles, useListBoxLayout } from '@keystar/ui/listbox';
import { Popover } from '@keystar/ui/overlays';
import { Popover, usePreventBackgroundScroll } from '@keystar/ui/overlays';
import { useIsMobileDevice } from '@keystar/ui/style';
import { validateTextFieldProps } from '@keystar/ui/text-field';

Expand Down Expand Up @@ -86,6 +86,8 @@ const ComboboxMultiBase = React.forwardRef(function ComboboxMultiBase<
fieldRef,
});

usePreventBackgroundScroll(popoverRef, state.isOpen);

return (
<>
<FieldPrimitive
Expand Down
24 changes: 17 additions & 7 deletions design-system/pkg/src/combobox/test/Combobox.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import userEvent from '@testing-library/user-event';
import { forwardRef } from 'react';
import { beforeAll, expect, vi, describe, it } from 'vitest';
import { afterAll, beforeAll, expect, vi, describe, it } from 'vitest';

import { act, fireEvent, firePress, renderWithProvider } from '#test-utils';

Expand Down Expand Up @@ -50,6 +50,10 @@ describe('combobox/Combobox', () => {
vi.useFakeTimers();
});

afterAll(function () {
vi.useRealTimers();
});

it('renders correctly', function () {
let { getByRole, getByText } = renderCombobox();

Expand All @@ -72,12 +76,15 @@ describe('combobox/Combobox', () => {
expect(combobox).toHaveAttribute('name', 'test name');
});

it('can be disabled', function () {
let user = userEvent.setup();
it('can be disabled', async function () {
let user = userEvent.setup({
delay: null,
advanceTimers: vi.advanceTimersByTimeAsync,
});
let { getByRole, queryByRole } = renderCombobox({ isDisabled: true });

let combobox = getByRole('combobox');
user.type(combobox, 'One');
await user.type(combobox, 'One');
act(() => {
vi.runAllTimers();
});
Expand Down Expand Up @@ -106,8 +113,11 @@ describe('combobox/Combobox', () => {
expect(onInputChange).not.toHaveBeenCalled();
});

it('can be readonly', function () {
let user = userEvent.setup();
it('can be readonly', async function () {
let user = userEvent.setup({
delay: null,
advanceTimers: vi.advanceTimersByTimeAsync,
});
let { getByRole, queryByRole } = renderCombobox({
isReadOnly: true,
defaultInputValue: 'default input value',
Expand All @@ -117,7 +127,7 @@ describe('combobox/Combobox', () => {
act(() => {
combobox.focus();
});
user.type(combobox, 'One');
await user.type(combobox, 'One');

expect(queryByRole('listbox')).toBeNull();
expect(combobox.value).toBe('default input value');
Expand Down
6 changes: 5 additions & 1 deletion design-system/pkg/src/listbox/ListBoxBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { RefObject, forwardRef, ReactElement, ReactNode, useMemo } from 'react';

import { useProvider } from '@keystar/ui/core';
import { ProgressCircle } from '@keystar/ui/progress';
import { useStyleProps } from '@keystar/ui/style';
import { classNames, css, useStyleProps } from '@keystar/ui/style';

import localizedMessages from './l10n';
import { ListBoxContext } from './context';
Expand Down Expand Up @@ -120,6 +120,10 @@ function ListBoxBase<T>(
<Virtualizer
{...styleProps}
{...mergeProps(listBoxProps, domProps)}
className={classNames(
styleProps.className,
css({ overscrollBehavior: 'contain' })
)}
ref={forwardedRef}
persistedKeys={persistedKeys}
autoFocus={!!props.autoFocus}
Expand Down
12 changes: 12 additions & 0 deletions design-system/pkg/src/overlays/Blanket.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { useRef } from 'react';

import {
classNames,
css,
Expand All @@ -7,6 +9,7 @@ import {
useStyleProps,
} from '@keystar/ui/style';

import { usePreventBackgroundScroll } from './scrollLock';
import { BlanketProps } from './types';

/**
Expand All @@ -15,10 +18,17 @@ import { BlanketProps } from './types';
*/
export function Blanket(props: BlanketProps) {
const { isOpen, isTransparent, ...otherProps } = props;
const blanketRef = useRef<HTMLDivElement>(null);
const styleProps = useStyleProps(otherProps);

usePreventBackgroundScroll(
() => blanketRef.current?.nextElementSibling ?? null,
Boolean(isOpen)
);

return (
<div
ref={blanketRef}
{...filterStyleProps(otherProps)}
{...toDataAttributes({
fill: isTransparent ? 'transparent' : 'translucent',
Expand All @@ -30,8 +40,10 @@ export function Blanket(props: BlanketProps) {
inset: 0,
opacity: 0,
overflow: 'hidden',
overscrollBehavior: 'none',
pointerEvents: 'none',
position: 'fixed',
touchAction: 'none',
visibility: 'hidden',
zIndex: 1,

Expand Down
4 changes: 4 additions & 0 deletions design-system/pkg/src/overlays/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export { DirectionIndicator } from './DirectionIndicator';
export { Modal } from './Modal';
export { Overlay } from './Overlay';
export { Popover } from './Popover';
export {
PreventBackgroundScroll,
usePreventBackgroundScroll,
} from './scrollLock';
export { Transition } from './Transition';
export { Tray } from './Tray';

Expand Down
Loading
Loading