diff --git a/.changeset/36852-peoplepicker-dialog-scroll.md b/.changeset/36852-peoplepicker-dialog-scroll.md new file mode 100644 index 00000000000..6020ea87de7 --- /dev/null +++ b/.changeset/36852-peoplepicker-dialog-scroll.md @@ -0,0 +1,10 @@ +--- +'@object-ui/fields': patch +--- + +fix(fields): the people picker's list scrolls by wheel and touch inside a dialog, and in its desktop dialog + +Clause-②: no +Metadata-protocol: none + +A user field's inline people picker could not be scrolled when it was opened inside a dialog form. Two things held it. The dropdown is rendered outside the dialog, so the form dialog's scroll lock cancelled every wheel and touch move over it; the dropdown is now modal, its own scroll-lock layer, as the lookup dropdown already is. Under that, the list area took the full height of its rows instead of the room the dropdown gives it, so the rows past the bottom edge were clipped rather than scrollable, inside a dialog or not; the list now shrinks to that room and scrolls. The same list in the people picker's centred desktop dialog scrolls now too. While the inline dropdown is open, the page behind it is hidden from assistive technology and a click outside closes it first, as with the other dropdown menus. The phone's bottom sheet is unchanged. diff --git a/ui/packages/fields/src/widgets/PeoplePicker.test.tsx b/ui/packages/fields/src/widgets/PeoplePicker.test.tsx index ee0974bb691..c7814e6fb78 100644 --- a/ui/packages/fields/src/widgets/PeoplePicker.test.tsx +++ b/ui/packages/fields/src/widgets/PeoplePicker.test.tsx @@ -8,6 +8,7 @@ import { render, screen, fireEvent, waitFor } from '@testing-library/react'; import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { Dialog, DialogContent, DialogTitle } from '@object-ui/components'; import { PeoplePicker } from './PeoplePicker'; import { pushRecentLookupId } from './recentLookups'; @@ -358,3 +359,60 @@ describe('PeoplePicker', () => { expect(onOpenChange).toHaveBeenCalledWith(false); }); }); + +/** + * The inline popover inside a dialog (objectstack#36852). Radix Dialog's + * scroll lock treats the dialog content as its only shard; the popover is + * portalled to the body, outside it, so a non-modal popover gets every wheel + * and touch move cancelled. `modal` makes the popover its own, topmost lock + * layer. A second cause sat under it: the popover is capped by `max-h-*` + * only, so the list area's viewport (`h-full`) took its content height and + * the list was clipped, not scrolled; the list area is a flex column so the + * viewport shrinks to the room it is given. + * + * jsdom does no layout or scrolling, so the pins read the observable half of + * `modal` (while the popover is open the dialog behind it is hidden from + * assistive technology) and the list area's flex column; the wheel and touch + * readings are on the pull request. + */ +describe('PeoplePicker inline popover inside a dialog', () => { + function renderInDialog(open: boolean) { + render( + + + Form + open} + dataSource={makeDataSource()} + onOpenChange={vi.fn()} + onSelect={vi.fn()} + /> + + , + ); + } + + it('while the popover is open, the dialog behind it is hidden (the popover is modal)', async () => { + renderInDialog(true); + const popover = await screen.findByTestId('people-picker-inline'); + await waitFor(() => expect(screen.getByText('Amy Lin')).toBeTruthy()); + expect(screen.getByTestId('host-dialog').closest('[aria-hidden="true"]')).not.toBeNull(); + expect(popover.closest('[aria-hidden="true"]')).toBeNull(); + }); + + it('the list area is a flex column, so its viewport shrinks to the popover and scrolls', async () => { + renderInDialog(true); + await waitFor(() => expect(screen.getByText('Amy Lin')).toBeTruthy()); + expect(screen.getByTestId('people-picker-list')).toHaveClass('flex', 'flex-col', 'min-h-0', 'flex-1'); + }); + + it('CONTROL: with the popover closed, the dialog is not hidden', async () => { + renderInDialog(false); + const dialog = await screen.findByTestId('host-dialog'); + expect(screen.queryByTestId('people-picker-inline')).toBeNull(); + expect(dialog.closest('[aria-hidden="true"]')).toBeNull(); + }); +}); diff --git a/ui/packages/fields/src/widgets/PeoplePicker.tsx b/ui/packages/fields/src/widgets/PeoplePicker.tsx index c315561cbd8..84e90069ac0 100644 --- a/ui/packages/fields/src/widgets/PeoplePicker.tsx +++ b/ui/packages/fields/src/widgets/PeoplePicker.tsx @@ -603,8 +603,12 @@ export function PeoplePicker({ )} - {/* Candidate area */} - + {/* Candidate area. `flex flex-col` makes the viewport a flex item that + shrinks to the room this area is given: a container capped only by + `max-h-*` (the inline popover, the desktop dialog) has no definite + height, so the viewport's own `h-full` falls back to its content + height and the list is clipped instead of scrolling. */} +
); } + // `modal`: the popover is its own scroll-lock layer. It is portalled out of + // a modal form's DOM, so a non-modal popover's list sits outside that + // dialog's scroll lock, which cancels every wheel and touch move on it; as + // the topmost lock its list scrolls. The same treatment as the lookup + // popover (objectstack#36825, #36852). return ( - + {trigger}