Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

Commit 326a6e5

Browse files
os-zhuangclaude
andauthored
fix(plugin-kanban): give the swimlane axis rows one horizontal padding (objectui#8797) (#8805)
objectui#8448 gave the swimlane board one horizontal axis by copying `scrollLeft` from the driven row onto every other row. Equal `scrollLeft` is equal alignment only while the rows share a scrollable RANGE, and they did not: the lane content rows carried `px-2` the column-header row did not, so their `scrollWidth` was 8px larger. Driven to a lane's maximum the header row clamped at its own smaller one and every column title sat 9px off its column until the user scrolled back. Both class lists now interpolate one `SWIMLANE_AXIS_X_PADDING` constant, so the two ranges cannot drift apart by hand. Measured in Chromium 1194 at 1600x1000, five columns and six swimlanes, driven with `mouse.wheel`: the worst title/cell offset across the whole range including the extreme right drops from 9px to the 1px lane-border baseline, and card layout inside the lanes is unchanged. The new pin asserts the RANGE contract — every axis row carries the same horizontal padding — as an invariant rather than a spelling. It deliberately does not re-assert propagation: that is objectui#8448's, and it is the assertion structurally blind to this clamp. Claude-Session: https://claude.ai/code/session_01611D6ZaRaMmwTNQmSbk8MH Co-authored-by: Claude <noreply@anthropic.com>
1 parent faeed81 commit 326a6e5

3 files changed

Lines changed: 308 additions & 5 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
"@object-ui/plugin-kanban": patch
3+
---
4+
5+
Fix swimlane column titles sliding 9px off their columns at the right end of the board
6+
7+
A swimlane board scrolls on one horizontal axis: a scroll handler copies
8+
`scrollLeft` from whichever row the user drove onto every other row. Equal
9+
`scrollLeft` is equal alignment only while the rows have the same scrollable
10+
range, and they did not — the lane content rows carried `px-2` that the
11+
column-header row did not, making their maximum `scrollLeft` larger. Scrolled
12+
fully right, the header row clamped at its own smaller maximum and every column
13+
title sat 9px off its column until the user scrolled back.
14+
15+
The column-header row and the lane content rows now take their horizontal
16+
padding from one shared constant, so the two ranges cannot drift apart. Measured
17+
in Chromium at 1600x1000: the worst title/cell offset across the whole range,
18+
including the extreme right, drops from 9px to the 1px lane-border baseline.
19+
Card layout inside the lanes is unchanged.

‎packages/plugin-kanban/src/KanbanImpl.tsx‎

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,40 @@ const UNCATEGORIZED_LANE = 'Uncategorized'
8484
*/
8585
const SWIMLANE_SCROLL_ROW_ATTR = 'data-swimlane-scroll-row'
8686

87+
/**
88+
* The horizontal padding carried by EVERY row on the swimlane board's shared
89+
* horizontal axis — the column-header row and each lane content row alike.
90+
*
91+
* It is one constant, used twice, because equal `scrollLeft` is only equal
92+
* ALIGNMENT while the two kinds of row have the same scrollable RANGE, and the
93+
* range is `scrollWidth - clientWidth` — which horizontal padding moves
94+
* (objectui#8797). The rows carried different padding before this: the lane
95+
* rows had `px-2`, the header row had none, so the lane rows' `scrollWidth` was
96+
* 8px larger. objectui#8448's sync copies one `scrollLeft` onto every row, so
97+
* driving a lane to its own maximum asked the header row for a position past
98+
* ITS maximum, the header row CLAMPED, and every column title stopped tracking
99+
* its column — permanently, until the user scrolled back.
100+
*
101+
* ⚠️ `pl-36 sm:pl-44` must stay AFTER `px-2`, and both must stay in this one
102+
* string. Tailwind emits `pl-*` after `px-*`, so the indent wins the left side
103+
* and `px-2`'s only live effect is the 8px on the RIGHT — measured, both rows
104+
* read `padding-left: 176px` at `sm`. Splitting them across two class lists is
105+
* what let them drift apart in the first place.
106+
*
107+
* Measured in Chromium 1194 at 1600x1000, five columns and six swimlanes, the
108+
* axis driven through the real input pipeline with `mouse.wheel`:
109+
*
110+
* before header max scrollLeft 288, lane max 298 -> worst title/cell dx 9px
111+
* after header max scrollLeft 296, lane max 298 -> worst title/cell dx 1px
112+
*
113+
* ⚠️ The residual 2px of range is NOT padding and cannot be closed from here:
114+
* each lane row sits inside the lane's `border rounded-lg` wrapper, so its
115+
* `clientWidth` is 1550 against the header row's 1552. That same 1px border is
116+
* the 1px title/cell baseline objectui#7303 and objectui#8448 already record.
117+
* Reported on objectui#8797 rather than compensated for with a magic offset.
118+
*/
119+
const SWIMLANE_AXIS_X_PADDING = 'px-2 pl-36 sm:pl-44'
120+
87121
// `KanbanCard` / `KanbanColumn` have ONE authority in this package: `./types`
88122
// (objectui#6172 / #6155). This file used to redeclare both, and the copies had
89123
// drifted — the local `KanbanCard` carried `cardSubtitle` / `cardFieldCells` /
@@ -877,9 +911,13 @@ function KanbanBoardInner({ columns, onCardMove, onCardClick, className, dnd, qu
877911
a title's own centre returning the lane-collapse `<button>` behind
878912
it. Pinned by `__tests__/swimlaneColumnHeaderRow-7303.test.tsx`.
879913
880-
The `pl-36 sm:pl-44` indent is shared with the lane content rows
881-
below and is what lines the titles up with their columns — it must
882-
move on both rows or neither.
914+
The horizontal padding is shared with the lane content rows
915+
below, as the single `SWIMLANE_AXIS_X_PADDING` constant both class
916+
lists interpolate — the `pl-36 sm:pl-44` half is what lines the
917+
titles up with their columns, and the `px-2` half is what keeps
918+
the two rows' scroll RANGES equal (objectui#8797). It must move on
919+
both rows or neither, which is now a property of the source rather
920+
than of two class lists agreeing by hand.
883921
884922
`pt-3 sm:pt-4` is the region's former TOP padding, moved onto this
885923
row on purpose. A scroll container's padding is inside its
@@ -904,7 +942,7 @@ function KanbanBoardInner({ columns, onCardMove, onCardClick, className, dnd, qu
904942
a sticky box is still in flow — so `shrink-0` above stays exactly
905943
as load-bearing as objectui#7303's pin says it is. */}
906944
<div
907-
className="flex shrink-0 gap-3 sm:gap-4 pl-36 sm:pl-44 pt-3 sm:pt-4 overflow-x-auto sticky top-0 z-10 bg-background"
945+
className={`flex shrink-0 gap-3 sm:gap-4 ${SWIMLANE_AXIS_X_PADDING} pt-3 sm:pt-4 overflow-x-auto sticky top-0 z-10 bg-background`}
908946
ref={adoptSwimlaneScroll}
909947
onScroll={syncSwimlaneScroll}
910948
data-swimlane-scroll-row=""
@@ -943,7 +981,7 @@ function KanbanBoardInner({ columns, onCardMove, onCardClick, className, dnd, qu
943981
{/* Lane content */}
944982
{!isCollapsed && (
945983
<div
946-
className="flex gap-3 sm:gap-4 overflow-x-auto px-2 pb-3 pl-36 sm:pl-44"
984+
className={`flex gap-3 sm:gap-4 overflow-x-auto ${SWIMLANE_AXIS_X_PADDING} pb-3`}
947985
ref={adoptSwimlaneScroll}
948986
onScroll={syncSwimlaneScroll}
949987
data-swimlane-scroll-row=""
Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* objectui#8797 — every row on the swimlane axis has the SAME scroll RANGE.
11+
*
12+
* ## What broke
13+
*
14+
* objectui#8448 gave the board one horizontal axis: a scroll handler copies
15+
* `scrollLeft` from whichever row the user drove onto every other row. Equal
16+
* `scrollLeft` is equal ALIGNMENT only while the rows have the same scrollable
17+
* RANGE, and they did not. The lane content rows carried `px-2`; the header row
18+
* did not. `scrollLeft`'s maximum is `scrollWidth - clientWidth`, so the lane
19+
* rows' maximum was larger. Driven to a lane's maximum, the header row CLAMPED
20+
* at its own smaller one and every column title sat off its column — and stayed
21+
* there, because nothing moves again until the user scrolls back.
22+
*
23+
* Measured in Chromium 1194 at 1600x1000, five columns and six swimlanes, real
24+
* Tailwind CSS, the axis driven through the real input pipeline (`mouse.wheel`,
25+
* not an assignment — see the warning below):
26+
*
27+
* before header max scrollLeft 288 | lane max 298 | worst title/cell dx 9px
28+
* after header max scrollLeft 296 | lane max 298 | worst title/cell dx 1px
29+
*
30+
* 1px is the baseline objectui#7303 and objectui#8448 already record: the lane
31+
* content row sits inside the lane's `border rounded-lg` wrapper, so it starts
32+
* 1px right of the header row. That same border is why the two maxima are still
33+
* 2px apart after the fix — `clientWidth` 1550 against 1552. That 2px is NOT
34+
* padding and is not closable from the class lists this file guards; it is
35+
* reported on objectui#8797 rather than papered over with a magic offset.
36+
*
37+
* ## ⚠️ What this file can and cannot measure — read before extending it
38+
*
39+
* Vitest runs here in happy-dom, which performs NO layout and applies NO CSS.
40+
* `scrollWidth`, `clientWidth` and every `scrollLeft` MAXIMUM are therefore
41+
* indistinguishable between the broken build and the fixed one — the numbers
42+
* above cannot be reproduced here, and asserting them would be a pin that
43+
* cannot fail. That half is out-of-band browser work and is reported in the PR,
44+
* exactly as objectui#7303, objectui#8448 and objectui#8449 all document for
45+
* this surface.
46+
*
47+
* What IS mechanically true here is the CLASS CONTRACT that decides the range.
48+
* This file pins it as an INVARIANT rather than a spelling: it never asserts
49+
* that a row carries `px-2`, only that every row on the axis carries the SAME
50+
* horizontal padding as every other. A future re-spelling of the padding stays
51+
* green; a future DIVERGENCE between the two kinds of row goes red, which is
52+
* the whole defect class.
53+
*
54+
* ## ⚠️ Why this file does NOT re-assert propagation
55+
*
56+
* objectui#8448's pin drives a `fireEvent.scroll` and asserts the rows end up
57+
* with equal `scrollLeft`. That is exactly the assertion that could not see
58+
* this bug: a clamp only happens PAST the header row's own maximum, and
59+
* happy-dom has no maxima, so propagation is satisfied at every value. Pinning
60+
* propagation again here would reproduce the blind spot that let objectui#8797
61+
* through. Propagation stays objectui#8448's; range is this file's.
62+
*/
63+
64+
import React from 'react';
65+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
66+
import { render, waitFor, cleanup, within } from '@testing-library/react';
67+
import { SchemaRenderer, SchemaRendererProvider } from '@object-ui/react';
68+
// Registers `object-kanban`. Module scope, not a hook: the import IS the
69+
// registration (AGENTS.md's test-discipline section).
70+
import '../index';
71+
// Same specifier as `index.tsx`'s lazy factory, so ESM's module cache resolves
72+
// the chunk immediately instead of racing a `waitFor` budget (objectui#3010).
73+
import '../KanbanImpl';
74+
75+
afterEach(cleanup);
76+
77+
/** The viewport the browser numbers in the docblock were read at. */
78+
const VIEWPORT = { width: 1600, height: 1000 };
79+
80+
beforeEach(() => {
81+
Object.defineProperty(window, 'innerWidth', { configurable: true, writable: true, value: VIEWPORT.width });
82+
Object.defineProperty(window, 'innerHeight', { configurable: true, writable: true, value: VIEWPORT.height });
83+
// Collapsed lanes persist per swimlane field; a leaked entry would silently
84+
// change how many rows the next case renders.
85+
try { window.localStorage.clear(); } catch { /* ignore */ }
86+
});
87+
88+
const OBJECT = 'deal';
89+
90+
const DEAL_SCHEMA = {
91+
name: OBJECT,
92+
label: 'Deal',
93+
fields: {
94+
name: { type: 'text', label: 'Name' },
95+
status: { type: 'text', label: 'Status' },
96+
owner: { type: 'text', label: 'Owner' },
97+
},
98+
};
99+
100+
function makeAdapter(): Record<string, any> {
101+
return {
102+
find: vi.fn(async () => ({ data: [] })),
103+
findOne: vi.fn(),
104+
create: vi.fn(),
105+
update: vi.fn(),
106+
delete: vi.fn(),
107+
getObjectSchema: vi.fn(async () => DEAL_SCHEMA),
108+
};
109+
}
110+
111+
const ROWS = [
112+
{ id: 'a', name: 'Alpha deal', status: 'open', owner: 'ann' },
113+
{ id: 'b', name: 'Beta deal', status: 'won', owner: 'bob' },
114+
];
115+
116+
const BOARD = {
117+
type: 'object-kanban',
118+
objectName: OBJECT,
119+
groupBy: 'status',
120+
columns: [
121+
{ id: 'open', title: 'Open' },
122+
{ id: 'qualified', title: 'Qualified' },
123+
{ id: 'proposal', title: 'Proposal' },
124+
{ id: 'won', title: 'Won' },
125+
{ id: 'lost', title: 'Lost' },
126+
],
127+
};
128+
129+
const SWIMLANES = { grouping: { fields: [{ field: 'owner' }] } };
130+
131+
/** Every row that declares itself part of the board's shared horizontal axis. */
132+
const axisRows = (root: ParentNode): HTMLElement[] =>
133+
[...root.querySelectorAll<HTMLElement>('[data-swimlane-scroll-row]')];
134+
135+
/** `sm:pl-44` -> `pl-44`; a bare utility is returned unchanged. */
136+
const utility = (token: string): string => token.slice(token.lastIndexOf(':') + 1);
137+
138+
/**
139+
* The classes that move a box's HORIZONTAL padding, and therefore its
140+
* `scrollWidth`: `p-*`, `px-*`, `pl-*`, `pr-*`, `ps-*`, `pe-*`. Deliberately
141+
* NOT `py-*` / `pt-*` / `pb-*` — the header row's `pt-3 sm:pt-4` and the lane
142+
* rows' `pb-3` are vertical, legitimately differ, and are objectui#8449's.
143+
*/
144+
const isHorizontalPadding = (token: string): boolean => /^p(?:[xlrse])?-/.test(utility(token));
145+
146+
/** Whatever decides the gap between columns, which also moves `scrollWidth`. */
147+
const isGap = (token: string): boolean => /^gap(?:-x)?-/.test(utility(token));
148+
149+
const classesMatching = (el: HTMLElement, pred: (t: string) => boolean): string[] =>
150+
el.className.split(/\s+/).filter(Boolean).filter(pred).sort();
151+
152+
/**
153+
* Render a swimlane board and prove it is a real one before anything is read
154+
* off it: the region, both lanes, and a card INSIDE a lane.
155+
*/
156+
async function renderSwimlaneBoard() {
157+
const { container } = render(
158+
<SchemaRendererProvider dataSource={makeAdapter() as any}>
159+
<SchemaRenderer schema={{ ...BOARD, data: ROWS, ...SWIMLANES } as never} />
160+
</SchemaRendererProvider>,
161+
);
162+
163+
await waitFor(() => expect(container.textContent).toContain('Alpha deal'));
164+
const region = container.querySelector('[role="region"]') as HTMLElement;
165+
expect(region?.getAttribute('aria-label')).toBe('Kanban board with swimlanes');
166+
167+
const laneButtons = [...region.querySelectorAll('button[aria-expanded]')];
168+
expect(laneButtons.map((b) => b.textContent)).toEqual(['▶ann(1)', '▶bob(1)']);
169+
170+
const laneList = region.querySelector('[role="list"][aria-label="Open - ann cards"]');
171+
expect(
172+
within(laneList as HTMLElement).queryByText('Alpha deal'),
173+
'the swimlane cell should hold its card',
174+
).not.toBeNull();
175+
176+
return { container, region };
177+
}
178+
179+
describe('objectui#8797 — every row on the swimlane axis has the same scroll range', () => {
180+
it('RANGE — the header row and every lane row carry the SAME horizontal padding', async () => {
181+
const { region } = await renderSwimlaneBoard();
182+
183+
const rows = axisRows(region);
184+
// CONTROL — one header row + one row per lane, header row first.
185+
expect(rows.length, 'header row + one row per lane').toBe(3);
186+
expect(rows[0]).toBe(region.firstElementChild);
187+
188+
const [headerRow, ...laneRows] = rows;
189+
const headerPadding = classesMatching(headerRow, isHorizontalPadding);
190+
191+
// NON-VACUITY — "the sets agree" is trivially true of two empty sets. The
192+
// rows are indented off the lane labels, so this can never legitimately be
193+
// empty; if it is, the pin below is comparing nothing.
194+
expect(
195+
headerPadding.length,
196+
'the axis rows must carry horizontal padding at all, or this pin compares two empty sets',
197+
).toBeGreaterThan(0);
198+
199+
// THE INVARIANT. Not "the header row carries px-2" — that would pin a
200+
// spelling. Every row on one axis must agree with every other, whatever
201+
// the spelling, because that agreement IS the equal range.
202+
for (const [i, laneRow] of laneRows.entries()) {
203+
expect(
204+
classesMatching(laneRow, isHorizontalPadding),
205+
`lane row ${i} must carry the same horizontal padding as the column-header row, ` +
206+
'or its scrollable range differs and the shared scrollLeft clamps on one of them (objectui#8797)',
207+
).toEqual(headerPadding);
208+
}
209+
});
210+
211+
it('RANGE — the axis rows also agree on the gap, the other class-level input to scrollWidth', async () => {
212+
const { region } = await renderSwimlaneBoard();
213+
214+
const [headerRow, ...laneRows] = axisRows(region);
215+
const headerGap = classesMatching(headerRow, isGap);
216+
217+
expect(headerGap.length, 'the columns are laid out with a gap utility').toBeGreaterThan(0);
218+
219+
// Padding is what objectui#8797 actually caught, but it is not the only
220+
// class that moves `scrollWidth`. A divergent gap would reintroduce the
221+
// same clamp by a different route. (Column WIDTH is objectui#8508's, which
222+
// pins both rows onto one `columnWidthClasses` source.)
223+
for (const [i, laneRow] of laneRows.entries()) {
224+
expect(
225+
classesMatching(laneRow, isGap),
226+
`lane row ${i} must space its columns exactly as the header row does (objectui#8797)`,
227+
).toEqual(headerGap);
228+
}
229+
});
230+
231+
it('NON-VACUITY — the rows are still scroll containers, so they still HAVE a range', async () => {
232+
const { region } = await renderSwimlaneBoard();
233+
234+
// A row that cannot scroll has no range, and two rows that cannot scroll
235+
// agree about their padding for free. objectui#8448 refused "make the
236+
// header row unscrollable" as arm C and objectui#7303's shrink arithmetic
237+
// depends on these rows being scroll containers; this re-reads that so the
238+
// equality above cannot be satisfied by deleting the axis.
239+
for (const row of axisRows(region)) {
240+
expect(
241+
row.className.split(/\s+/).some((t) => /^(?:[a-z]+:)*overflow(?:-x)?-(?:auto|scroll)$/.test(t)),
242+
`a row on the shared axis must still be a scroll container; class was ${JSON.stringify(row.className)}`,
243+
).toBe(true);
244+
}
245+
});
246+
});

0 commit comments

Comments
 (0)