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
15 changes: 15 additions & 0 deletions .changeset/35446-list-narrow-fixed-columns.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@object-ui/plugin-grid': patch
'@object-ui/components': patch
'@object-ui/app-shell': patch
---

fix(grid): a list in a narrowed main area keeps every data cell clear of its fixed columns, shows its horizontal scrollbar, and draws a short header

Clause-②: no
Metadata-protocol: none

- **Row actions column.** While a list's table is wider than its box (the AI panel docked, a small window, the record drawer open), the row actions column (the row's "⋮") is drawn right after the frozen name column and frozen with it, instead of pinned to the right edge, where it covered the data column reaching that edge (an amount cut to 「¥94,0」). Every data column then scrolls sideways under the frozen columns, and none is covered at rest. Once the box is wide enough for the whole table again, the column goes back to the right edge, so a list that fits looks as before. Inline primary row actions still fold into the "⋮" menu first, as before. Columns an author pinned to the right stay where the author put them; the grouped list is unchanged.
- **Horizontal scrollbar.** A table wider than its box draws its scrollbar at rest instead of only while the pointer is over it, so columns out of view are announced. A table that fits keeps the scrollbar that shows on hover.
- **List header.** While the list page's header is narrower than 768 px, it draws no description, and Import moves into the 「⋯」 menu beside New. A wider header is unchanged. This is opt-in: the console `PageHeader` gains `compactBelow` (a width in px; below it the one-row header drops its description and draws its folded actions), which only the list page passes, so other pages that use `PageHeader` are unchanged. Setup's two-line header ignores it.
- No column is hidden and no column configuration changes.
382 changes: 382 additions & 0 deletions ui/e2e/list-header-narrow-35446.spec.ts

Large diffs are not rendered by default.

436 changes: 436 additions & 0 deletions ui/e2e/list-narrow-pinned-columns-35446.spec.ts

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions ui/e2e/related-list-pinned-actions-width.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,11 @@ test.describe('enlarged related list in a record drawer — the pinned Actions c
report(testInfo, c, r);
expect(r.folded).toBe(true);
expect(r.inlineButtons).toBe(0);
// Still wider than the drawer: the pinned column sits at the box's edge
// over whichever column scrolls under it, as on any list that scrolls
// sideways. A scroll to the end shows Status whole.
// Still wider than the drawer: the Actions column leaves the right edge
// for the frozen zone beside the name column (objectstack#35446), and a
// scroll to the end shows Status whole.
expect(r.box.scrollWidth).toBeGreaterThan(r.box.clientWidth);
expect(r.actions.left, 'the Actions column still sits at the right edge').toBeLessThan(r.box.clientWidth / 2);
const end = await page.evaluate(async () => {
const box = document.querySelector<HTMLElement>('[data-table-scroll-box]')!;
box.scrollLeft = box.scrollWidth;
Expand Down
61 changes: 52 additions & 9 deletions ui/packages/app-shell/src/layout/PageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
* the header is too narrow for `actions` and its text, it draws that instead,
* so the actions fold before the title or the description is cut:
* [icon] Title [kind] | the whole description [refresh] [primary] [⋯]
*
* The compact form — a page may opt in with `compactBelow` (objectstack#35446):
* while the one-row header is narrower than that, it drops the description and
* draws `foldedActions` whatever the text needs, so a main area narrowed by a
* docked panel, a small window or the record drawer gets a short header row:
* [icon] Title [kind] [refresh] [primary] [⋯]
*/

import * as React from 'react';
Expand Down Expand Up @@ -140,6 +146,17 @@ export interface ConsolePageHeaderProps {
* trade the page's actions for its description.
*/
foldedActions?: React.ReactNode;
/**
* Opt-in compact form for a narrow header (objectstack#35446): while the
* one-row header is narrower than this many pixels, the description (and
* the hairline before it) is not drawn and `foldedActions`, when given, is
* drawn in place of `actions`. At this width and above the header behaves
* exactly as without it. Read from the header's own width, never the
* viewport's, so any narrowing of the main area counts. Setup's posture,
* whose description sits on its own line, ignores it. A page that passes
* nothing keeps today's header at every width.
*/
compactBelow?: number;
/**
* CSS color used to tint the top hairline, icon chip background, and
* icon stroke. Defaults to the Shadcn `--primary` token so the header
Expand Down Expand Up @@ -184,6 +201,7 @@ export function PageHeader({
refresh,
actions,
foldedActions,
compactBelow,
accentColor,
sticky = false,
className,
Expand All @@ -198,8 +216,12 @@ export function PageHeader({

// objectui#12705 — the actions fold before the text is cut.
const canFold = foldedActions != null && foldedActions !== false;
const { rootRef, textRef, descriptionRef, clusterRef, folded } = useActionsFold(canFold, setup);
const drawnActions = canFold && folded ? foldedActions : actions;
const { rootRef, textRef, descriptionRef, clusterRef, folded, compact } = useActionsFold(
canFold,
setup,
setup ? undefined : compactBelow,
);
const drawnActions = canFold && (folded || compact) ? foldedActions : actions;

const refreshButton = refresh ? (
<Button
Expand All @@ -222,7 +244,7 @@ export function PageHeader({
ref={clusterRef}
className="flex items-center gap-1.5 sm:gap-2 shrink-0"
data-testid="page-header-actions"
data-folded={canFold ? String(folded) : undefined}
data-folded={canFold ? String(folded || compact) : undefined}
>
{refreshButton}
{drawnActions}
Expand All @@ -241,6 +263,7 @@ export function PageHeader({
)}
data-testid={testId ?? 'page-header'}
data-posture={setup ? 'setup' : 'row'}
data-compact={compact ? 'true' : undefined}
>
{/* Accent hairline — a 2px gradient strip that fades to transparent at
both edges. Picks up the app's accent color, or the default primary
Expand Down Expand Up @@ -290,11 +313,14 @@ export function PageHeader({
`border-box` a min-height there would count that row's padding. */}
<div ref={textRef} className="flex items-center gap-2.5 min-w-0 flex-1 min-h-9">
{icon && <IconTile size="row">{icon}</IconTile>}
<h1 className="min-w-0 max-w-full sm:max-w-[60%] shrink-0 text-base sm:text-lg font-semibold tracking-tight text-foreground truncate leading-tight">
{/* The 60 % cap keeps room for the description beside the title;
the compact form draws none, so its title takes the whole row
(objectstack#35446). */}
<h1 className={cn('min-w-0 max-w-full shrink-0 text-base sm:text-lg font-semibold tracking-tight text-foreground truncate leading-tight', !compact && 'sm:max-w-[60%]')}>
{title}
</h1>
{badge}
{(subtitle || breadcrumb) && (
{(subtitle || breadcrumb) && !compact && (
<>
<span aria-hidden="true" className="hidden sm:block h-4 w-px shrink-0 bg-border" />
<p ref={descriptionRef} className="hidden sm:block min-w-0 flex-1 truncate text-sm text-muted-foreground">
Expand Down Expand Up @@ -327,8 +353,12 @@ export function PageHeader({
* Without layout (no `ResizeObserver`, every width 0) nothing ever overflows
* and the header stays unfolded.
*/
function useActionsFold(canFold: boolean, setup: boolean) {
function useActionsFold(canFold: boolean, setup: boolean, compactBelow: number | undefined) {
const rootRef = React.useRef<HTMLDivElement>(null);
// objectstack#35446 — the opt-in compact form, read from the header's own
// width. Without layout (width 0) the header is never compact.
const [compact, setCompact] = React.useState(false);
const compactRef = React.useRef(false);
const textRef = React.useRef<HTMLDivElement>(null);
const descriptionRef = React.useRef<HTMLParagraphElement>(null);
const clusterRef = React.useRef<HTMLDivElement>(null);
Expand All @@ -340,6 +370,18 @@ function useActionsFold(canFold: boolean, setup: boolean) {
// observer below never keys on a callback's identity (AGENTS.md #10).
const measureRef = React.useRef<() => void>(() => {});
const measure = () => {
const rootWidth = rootRef.current?.getBoundingClientRect().width ?? 0;
const nextCompact = compactBelow !== undefined && rootWidth > 0 && rootWidth < compactBelow;
// The compact face is decided by width alone. The content fold below reads
// the full face, so it is measured only once that face is drawn: never
// while the compact one is, nor in the pass that switches between them
// (the render that follows measures again).
if (nextCompact !== compactRef.current) {
compactRef.current = nextCompact;
setCompact(nextCompact);
return;
}
if (nextCompact) return;
if (!canFold) {
// A page that stops offering the fold starts unfolded when it offers it
// again.
Expand Down Expand Up @@ -372,16 +414,17 @@ function useActionsFold(canFold: boolean, setup: boolean) {
measure();
});

const observes = canFold || compactBelow !== undefined;
React.useEffect(() => {
const root = rootRef.current;
if (!canFold || !root || typeof ResizeObserver === 'undefined') return;
if (!observes || !root || typeof ResizeObserver === 'undefined') return;
const observer = new ResizeObserver(() => measureRef.current());
observer.observe(root);
if (clusterRef.current) observer.observe(clusterRef.current);
return () => observer.disconnect();
}, [canFold]);
}, [observes]);

return { rootRef, textRef, descriptionRef, clusterRef, folded: canFold && folded };
return { rootRef, textRef, descriptionRef, clusterRef, folded: canFold && folded, compact };
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ function installLayout() {
};
const rectWidth = (el: Element): number => {
if (el.matches('[data-testid="page-header-actions"]')) return clusterWidth(el);
// The header's own width, read by the opt-in compact form (objectstack#35446).
if (el.matches('[data-testid="page-header"]')) return headerWidth;
if (!el.closest('[data-testid="page-header"]')) return 0;
if (el.tagName === 'H1') return (el.textContent ?? '').length * 10;
if (el.matches('span[aria-hidden="true"]')) return 1;
Expand Down Expand Up @@ -166,7 +168,12 @@ function PageMenu({ children }: { children?: React.ReactNode }) {
);
}

function mount({ appName = 'crm', fold = true, onImport = vi.fn() } = {}) {
function mount({
appName = 'crm',
fold = true,
onImport = vi.fn(),
compactBelow,
}: { appName?: string; fold?: boolean; onImport?: () => void; compactBelow?: number } = {}) {
installLayout();
render(
<MemoryRouter initialEntries={[`/apps/${appName}/page`]}>
Expand All @@ -179,6 +186,7 @@ function mount({ appName = 'crm', fold = true, onImport = vi.fn() } = {}) {
subtitle={DESCRIPTION}
actions={<Actions onImport={onImport} />}
foldedActions={fold ? <FoldedActions onImport={onImport} /> : undefined}
compactBelow={compactBelow}
/>
}
/>
Expand Down Expand Up @@ -268,3 +276,55 @@ describe('the console page header folds its actions before its text (objectui#12
expect(labelled()).toEqual(['New', 'Import', 'Update Stage']);
});
});

/**
* objectstack#35446 — the opt-in compact form: below `compactBelow` px of its
* own width the one-row header drops its description and draws the folded
* actions, even where the content fold above would keep them (700 px fits all
* three actions beside the description in this model).
*/
describe('the console page header’s opt-in compact form (objectstack#35446)', () => {
it('a 700 px header with compactBelow 768 draws no description and folds Import into the ⋯', () => {
headerWidth = 700;
const onImport = vi.fn();
const { header, cluster, labelled } = mount({ compactBelow: 768, onImport });
expect(header.getAttribute('data-compact')).toBe('true');
expect(within(header).queryByText(DESCRIPTION)).toBeNull();
// No description to share the row with: the title is not capped to 60 % of it.
expect(header.querySelector('h1')!.className).not.toContain('sm:max-w-[60%]');
expect(cluster.getAttribute('data-folded')).toBe('true');
expect(labelled()).toEqual(['New']);
fireEvent.pointerDown(within(cluster).getByTestId('more'), { button: 0, pointerType: 'mouse' });
fireEvent.click(screen.getByTestId('folded-import'));
expect(onImport).toHaveBeenCalledTimes(1);
});

it('follows the header’s width both ways: the full row at 1000 px, compact again at 700 px', () => {
headerWidth = 700;
const { header, labelled } = mount({ compactBelow: 768 });
expect(labelled()).toEqual(['New']);
resizeTo(1000);
expect(header.getAttribute('data-compact')).toBeNull();
expect(within(header).getByText(DESCRIPTION)).toBeTruthy();
expect(labelled()).toEqual(['New', 'Import', 'Update Stage']);
resizeTo(700);
expect(within(header).queryByText(DESCRIPTION)).toBeNull();
expect(labelled()).toEqual(['New']);
});

it('CONTROL — without compactBelow a 700 px header keeps its description and all three actions', () => {
headerWidth = 700;
const { header, labelled } = mount();
expect(header.getAttribute('data-compact')).toBeNull();
expect(within(header).getByText(DESCRIPTION)).toBeTruthy();
expect(header.querySelector('h1')!.className).toContain('sm:max-w-[60%]');
expect(labelled()).toEqual(['New', 'Import', 'Update Stage']);
});

it('CONTROL — the Setup posture ignores compactBelow; its description is its own line', () => {
headerWidth = 600;
const { header } = mount({ appName: 'setup', compactBelow: 768 });
expect(header.getAttribute('data-compact')).toBeNull();
expect(within(header).getByTestId('page-header-description').textContent).toBe(DESCRIPTION);
});
});
10 changes: 10 additions & 0 deletions ui/packages/app-shell/src/views/objectViewPageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ import type { useObjectViewHeaderToolbar } from './objectViewHeaderToolbar.js';
import type { useObjectViewHeaderChrome } from './objectViewHeaderChrome.js';
import type { ConsoleObjectViewProps } from './ObjectView.js';

/**
* objectstack#35446 — the list header's width under which it takes
* `PageHeader`'s compact form: no description, and the folded actions (New
* labelled, Import and the rest in the 「⋯」 menu). The `md` breakpoint, read
* against the header's own width, so a main area narrowed by the AI panel, a
* small window or the record drawer gets it, and a full-width list does not.
*/
const LIST_HEADER_COMPACT_WIDTH = 768;

/**
* The list title 「OBJECT / VIEW ▾」 (objectstack#27950): the page
* header is the one place a page is named (objectui#12461), and with the view
Expand Down Expand Up @@ -230,6 +239,7 @@ export function ObjectViewPageHeader({
</>
}
foldedActions={foldedHeaderActions}
compactBelow={LIST_HEADER_COMPACT_WIDTH}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,50 @@ describe('data-table scroll box, sticky columns and right-edge shadow (objectui#
expect(queryByTestId('data-table-scroll-shadow-right')).toBeNull();
});
});

/**
* objectstack#35446 — while the table is wider than its box the box draws its
* scrollbar at rest, so columns out of view are announced without the pointer
* over the box; a table that fits keeps the shared hover-only bar
* (objectui#12708). The box's geometry is stubbed before the table mounts,
* because the read is taken at mount and on resize, not on scroll.
*/
describe('data-table scrollbar at rest while the table scrolls sideways (objectstack#35446)', () => {
const AT_REST = '[scrollbar-color:var(--color-muted-foreground)_transparent]!';
const TRANSPARENT = '[scrollbar-color:transparent_transparent]!';

function stubBoxWidths(scrollWidth: number, clientWidth: number): () => void {
const proto = HTMLElement.prototype;
const isBox = (el: HTMLElement) => el.hasAttribute('data-table-scroll-box');
Object.defineProperty(proto, 'scrollWidth', { configurable: true, get(this: HTMLElement) { return isBox(this) ? scrollWidth : 0; } });
Object.defineProperty(proto, 'clientWidth', { configurable: true, get(this: HTMLElement) { return isBox(this) ? clientWidth : 0; } });
return () => {
delete (proto as unknown as Record<string, unknown>).scrollWidth;
delete (proto as unknown as Record<string, unknown>).clientWidth;
};
}

it('a table wider than its box draws the bar at rest', () => {
const restore = stubBoxWidths(1400, 700);
try {
const { getByTestId } = renderTable(baseSchema);
const classes = getByTestId('data-table-scroll-box').className.split(/\s+/);
expect(classes).toContain(AT_REST);
expect(classes).not.toContain(TRANSPARENT);
} finally {
restore();
}
});

it('CONTROL: a table that fits keeps the hover-only bar', () => {
const restore = stubBoxWidths(700, 700);
try {
const { getByTestId } = renderTable(baseSchema);
const classes = getByTestId('data-table-scroll-box').className.split(/\s+/);
expect(classes).toContain(TRANSPARENT);
expect(classes).not.toContain(AT_REST);
} finally {
restore();
}
});
});
Loading
Loading