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
10 changes: 10 additions & 0 deletions .changeset/36852-peoplepicker-dialog-scroll.md
Original file line number Diff line number Diff line change
@@ -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.
58 changes: 58 additions & 0 deletions ui/packages/fields/src/widgets/PeoplePicker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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(
<Dialog open onOpenChange={vi.fn()}>
<DialogContent data-testid="host-dialog">
<DialogTitle>Form</DialogTitle>
<PeoplePicker
{...baseProps}
open={open}
inline
trigger={<button data-testid="inline-trigger">open</button>}
dataSource={makeDataSource()}
onOpenChange={vi.fn()}
onSelect={vi.fn()}
/>
</DialogContent>
</Dialog>,
);
}

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();
});
});
15 changes: 12 additions & 3 deletions ui/packages/fields/src/widgets/PeoplePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,12 @@ export function PeoplePicker({
)}
</div>

{/* Candidate area */}
<ScrollArea className="min-h-0 flex-1" data-testid="people-picker-list">
{/* 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. */}
<ScrollArea className="flex min-h-0 flex-1 flex-col" data-testid="people-picker-list">
<div
id="people-picker-list"
role="listbox"
Expand Down Expand Up @@ -722,8 +726,13 @@ export function PeoplePicker({
</Sheet>
);
}
// `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 (
<Popover open={open} onOpenChange={onOpenChange}>
<Popover modal open={open} onOpenChange={onOpenChange}>
<PopoverTrigger asChild>{trigger}</PopoverTrigger>
<PopoverContent
align="start"
Expand Down
Loading