Skip to content

Commit 7dcbb2e

Browse files
committed
fix(components): every list header opens the column menu; a Firefox-draggable sort handle
Under GridHeaderMenu a header that does not sort now opens the column menu with Hide column alone, and its click still changes no sort. Hide column moves focus to the header beside the hidden one. The sort builder's handle is a span with role button and a tab stop, since Firefox starts no HTML5 drag from a button. The condition-row e2e spec drags a handle in a chip's panel. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 046c89d commit 7dcbb2e

7 files changed

Lines changed: 71 additions & 29 deletions

File tree

‎.changeset/35876-list-header-menu-multi-sort.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fix(plugin-list): a list's column header opens a menu and keeps a multi-level so
1010
Clause-②: yes (widening)
1111
Metadata-protocol: none
1212

13-
On a list page (the grid `ListView` draws), a click on a sortable column header no longer sorts at once. It opens the column menu: sort ascending, sort descending, hide the column. Enter, Space or ArrowDown on the focused header opens the same menu, the arrows move through it, Enter chooses, and Esc shuts it without touching the sort. With no sort or a single level, the column picked in the menu replaces the sort; with two levels or more it becomes the first level, the other levels keep their order after it, and a column already in the sort moves up with the picked direction. No level is dropped. The ↑1 / ↓2 marks on the headers are unchanged.
13+
On a list page (the grid `ListView` draws), a click on a column header no longer sorts at once. It opens the column menu: sort ascending, sort descending, hide the column (a column that does not sort offers hide alone). Enter, Space or ArrowDown on the focused header opens the same menu, the arrows move through it, Enter chooses, and Esc shuts it without touching the sort. With no sort or a single level, the column picked in the menu replaces the sort; with two levels or more it becomes the first level, the other levels keep their order after it, and a column already in the sort moves up with the picked direction. No level is dropped. The ↑1 / ↓2 marks on the headers are unchanged.
1414

1515
A sort chip under the view bar no longer reverses its direction on a click: it opens every sort level in one panel. Each level row in the sort builder now has a handle; dragging it, or ArrowUp / ArrowDown on the focused handle, reorders the levels.
1616

‎content/docs/frontend/plugins/plugin-grid.mdx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ changes the direction.
117117
**On an object's list page** the header opens a menu instead
118118
(objectstack#35876), which its host turns on (the `headerMenu` component
119119
prop, not a schema key): **Sort ascending**, **Sort descending** and **Hide
120-
column**. The header itself never changes the sort. Enter, Space or ArrowDown
120+
column**. A column that does not sort offers **Hide column** alone. The
121+
header itself never changes the sort. Enter, Space or ArrowDown
121122
on the focused header opens the same menu; the arrows move through it, Enter
122123
chooses and Escape closes it without touching the sort.
123124

‎ui/e2e/list-condition-row-35549.spec.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ test.describe('list condition row under the view bar (objectstack#35549, objects
318318
expect(await slotHeight(page)).toBe(0);
319319
});
320320

321-
test('sort: Sort → Descending → Amount is three clicks; chips come before filter chips; a drag reorders; a header menu pick shows as a chip; Reset restores', async ({ page }) => {
321+
test('sort: Sort → Descending → Amount is three clicks; chips come before filter chips; a drag reorders; a handle in a chip panel reorders; a header menu pick shows as a chip; Reset restores', async ({ page }) => {
322322
test.setTimeout(120_000);
323323
await mount(page);
324324
await expect.poll(() => count(page)).toBe('12');
@@ -354,6 +354,15 @@ test.describe('list condition row under the view bar (objectstack#35549, objects
354354
// a real drag: the second sort chip onto the first
355355
await page.getByTestId('sort-chip-stage').dragTo(page.getByTestId('sort-chip-amount'));
356356
expect(await sortNow(page)).toEqual(['stage:asc', 'amount:desc']);
357+
// a chip opens every level in one panel (objectstack#35876); a real drag of
358+
// the second level's handle onto the first row puts it first
359+
await click(page, 'sort-chip-open-stage');
360+
const panel = page.getByTestId('sort-chip-panel');
361+
await expect(panel.getByTestId('sort-builder-handle')).toHaveCount(2);
362+
expect(await sortNow(page)).toEqual(['stage:asc', 'amount:desc']);
363+
await panel.getByTestId('sort-builder-handle').nth(1).dragTo(panel.getByTestId('sort-builder-row').first());
364+
await expect.poll(() => sortNow(page)).toEqual(['amount:desc', 'stage:asc']);
365+
await page.keyboard.press('Escape');
357366
// Reset puts the list back as saved: no sort, no filter
358367
await click(page, 'condition-reset');
359368
expect(await sortNow(page)).toEqual([]);

‎ui/packages/components/src/__tests__/sort-builder-reorder-35876.test.tsx‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,15 @@ function mount(initial: SortItem[]) {
5252
const fieldsOf = (items: SortItem[]) => items.map((i) => `${i.field}:${i.order}`);
5353

5454
describe('SortBuilder — reordering the levels (objectstack#35876)', () => {
55-
it('every level has a named handle', () => {
55+
it('every level has a named handle: a keyboard control that is not a <button>, so Firefox can drag it', () => {
5656
mount(THREE);
5757
const handles = screen.getAllByRole('button', { name: 'Drag to reorder' });
5858
expect(handles).toHaveLength(3);
59-
for (const h of handles) expect(h).toHaveAttribute('draggable', 'true');
59+
for (const h of handles) {
60+
expect(h).toHaveAttribute('draggable', 'true');
61+
expect(h).toHaveAttribute('tabindex', '0');
62+
expect(h.tagName).not.toBe('BUTTON');
63+
}
6064
});
6165

6266
it('ArrowUp on the second handle makes it the first level; ArrowDown on the first moves it down', () => {
@@ -98,7 +102,8 @@ describe('SortBuilder — reordering the levels (objectstack#35876)', () => {
98102
it('a single level: the handle is drawn but disabled, and drags nothing', () => {
99103
mount([THREE[0]]);
100104
const handle = screen.getByTestId('sort-builder-handle');
101-
expect(handle).toBeDisabled();
105+
expect(handle).toHaveAttribute('aria-disabled', 'true');
106+
expect(handle).toHaveAttribute('tabindex', '-1');
102107
expect(handle).toHaveAttribute('draggable', 'false');
103108
});
104109
});

‎ui/packages/components/src/custom/sort-builder.tsx‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export function SortBuilder({
152152
// handle drags it to another place, and ArrowUp / ArrowDown on the focused
153153
// handle move it one place.
154154
const dragFrom = React.useRef<number | null>(null);
155-
const handleRefs = React.useRef(new Map<string, HTMLButtonElement>());
155+
const handleRefs = React.useRef(new Map<string, HTMLElement>());
156156
const moveItem = (from: number, to: number) => {
157157
if (from === to || from < 0 || to < 0 || from >= items.length || to >= items.length) return;
158158
const next = items.slice();
@@ -189,14 +189,18 @@ export function SortBuilder({
189189
dragFrom.current = null;
190190
}}
191191
>
192-
<button
193-
type="button"
192+
{/* A `span`, not a `<button>`: Firefox starts no HTML5 drag from a
193+
button. It is a keyboard control all the same (role, tab stop,
194+
arrows). */}
195+
<span
196+
role="button"
197+
tabIndex={items.length > 1 ? 0 : -1}
198+
aria-disabled={items.length < 2 || undefined}
194199
ref={(node) => {
195200
if (node) handleRefs.current.set(item.id, node);
196201
else handleRefs.current.delete(item.id);
197202
}}
198203
draggable={items.length > 1}
199-
disabled={items.length < 2}
200204
onDragStart={(event) => {
201205
event.stopPropagation();
202206
dragFrom.current = index;
@@ -216,11 +220,11 @@ export function SortBuilder({
216220
}}
217221
aria-label={t('sortBuilder.reorder')}
218222
title={t('sortBuilder.reorder')}
219-
className="inline-flex h-9 w-5 shrink-0 cursor-grab items-center justify-center rounded text-muted-foreground hover:text-foreground disabled:cursor-default disabled:opacity-40 max-sm:col-start-1 max-sm:row-start-1 max-sm:row-span-3 max-sm:h-auto"
223+
className="inline-flex h-9 w-5 shrink-0 cursor-grab items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring aria-disabled:cursor-default aria-disabled:opacity-40 max-sm:col-start-1 max-sm:row-start-1 max-sm:row-span-3 max-sm:h-auto"
220224
data-testid="sort-builder-handle"
221225
>
222226
<GripVertical className="h-4 w-4" aria-hidden="true" />
223-
</button>
227+
</span>
224228
<span className="text-sm font-medium w-16 text-muted-foreground max-sm:col-start-2 max-sm:col-span-2 max-sm:w-auto">
225229
{index === 0 ? t('sortBuilder.sortBy') : t('sortBuilder.thenBy')}
226230
</span>

‎ui/packages/components/src/renderers/complex/__tests__/data-table-header-menu-35876.test.tsx‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
*/
88

99
/**
10-
* objectstack#35876 — under `GridHeaderMenu` a sortable column header opens
11-
* the column menu (sort ascending, sort descending, hide) and never sorts by
12-
* itself; the keyboard reaches the same menu from the focused header. Without
13-
* the provider the header still sorts on a click.
10+
* objectstack#35876 — under `GridHeaderMenu` every column header opens the
11+
* column menu (sort ascending, sort descending, hide; a header that does not
12+
* sort offers hide alone) and never sorts by itself; the keyboard reaches the
13+
* same menu from the focused header. Without the provider the header still
14+
* sorts on a click.
1415
*/
1516
import { describe, it, expect, afterEach, vi } from 'vitest';
1617
import { render, screen, cleanup, fireEvent, within, act, waitFor } from '@testing-library/react';
@@ -119,12 +120,24 @@ describe('data-table — the header opens the column menu (objectstack#35876)',
119120
await waitFor(() => expect(th).toHaveFocus());
120121
});
121122

122-
it('a header that does not sort opens no menu on a click and takes no focus', () => {
123+
it('a header that does not sort opens a menu with Hide column alone, and changes no sort', () => {
123124
const { onSortChange } = renderManual({ headerMenu: true, statusSortable: false });
125+
expect(header('status')).toHaveAttribute('tabindex', '0');
126+
expect(header('status')).toHaveAttribute('aria-haspopup', 'menu');
124127
fireEvent.click(header('status'));
125-
expect(menu()).toBeNull();
126-
expect(header('status')).not.toHaveAttribute('tabindex');
127-
expect(header('status')).not.toHaveAttribute('aria-haspopup');
128+
expect(within(menu()!).getAllByRole('menuitem').map((b) => b.textContent)).toEqual(['Hide column']);
129+
expect(onSortChange).not.toHaveBeenCalled();
130+
});
131+
132+
it('Hide column from the keyboard gives focus to the header beside the hidden one', async () => {
133+
const { onSortChange } = renderManual({ headerMenu: true });
134+
act(() => header('name').focus());
135+
await userEvent.keyboard('{Enter}');
136+
const items = within(menu()!).getAllByRole('menuitem');
137+
await waitFor(() => expect(items[0]).toHaveFocus());
138+
await userEvent.keyboard('{ArrowDown}{ArrowDown}{Enter}');
139+
expect(header('name')).toBeNull();
140+
await waitFor(() => expect(header('status')).toHaveFocus());
128141
expect(onSortChange).not.toHaveBeenCalled();
129142
});
130143

‎ui/packages/components/src/renderers/complex/data-table.tsx‎

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2482,11 +2482,12 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
24822482
setContextMenu({ x: e.clientX, y: e.clientY, columnKey });
24832483
};
24842484

2485-
// objectstack#35876 — under `GridHeaderMenu` a sortable header opens the
2486-
// column menu below itself (a click, or Enter / Space / ArrowDown while it
2487-
// has focus) and never sorts; the sort is the entry chosen in the menu. A
2488-
// click on the header whose menu is open shuts it.
2489-
const headerMenuOn = (col: TableColumn) => headerOpensMenu && isColumnSortable(col);
2485+
// objectstack#35876 — under `GridHeaderMenu` every header opens the column
2486+
// menu below itself (a click, or Enter / Space / ArrowDown while it has
2487+
// focus) and never sorts; the sort is the entry chosen in the menu, which
2488+
// offers sort entries only where `isColumnSortable` does. A click on the
2489+
// header whose menu is open shuts it.
2490+
const headerMenuOn = (_col: TableColumn) => headerOpensMenu;
24902491
const openHeaderMenu = (header: HTMLElement, columnKey: string, byKeyboard: boolean) => {
24912492
columnMenuReturnFocusRef.current = header;
24922493
columnMenuByKeyboardRef.current = byKeyboard;
@@ -2520,6 +2521,16 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
25202521
: undefined;
25212522

25222523
const hideColumn = (columnKey: string) => {
2524+
// The header the menu came from is about to go: focus returns to the
2525+
// header beside it (the next one, else the previous), when that one is a
2526+
// tab stop.
2527+
const from = columnMenuReturnFocusRef.current?.closest('th');
2528+
if (from && from.getAttribute('data-column-key') === columnKey) {
2529+
const beside = [from.nextElementSibling, from.previousElementSibling].find(
2530+
(el): el is HTMLElement => el instanceof HTMLElement && el.hasAttribute('data-column-key') && el.tabIndex >= 0,
2531+
);
2532+
columnMenuReturnFocusRef.current = beside ?? null;
2533+
}
25232534
setColumns(prev => prev.filter(c => c.accessorKey !== columnKey));
25242535
setContextMenu(null);
25252536
};
@@ -4226,7 +4237,7 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
42264237
data-column-key={col.accessorKey}
42274238
className={cn(
42284239
col.className,
4229-
isColumnSortable(col) && 'cursor-pointer select-none',
4240+
(isColumnSortable(col) || headerMenuOn(col)) && 'cursor-pointer select-none',
42304241
// A header that opens the column menu is a tab stop (objectstack#35876).
42314242
headerMenuOn(col) && 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring',
42324243
isDragging && 'opacity-50',
@@ -4270,9 +4281,8 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
42704281
}
42714282
: {})}
42724283
onClick={(e) => {
4273-
if (!isColumnSortable(col)) return;
4274-
if (headerOpensMenu) openHeaderMenu(e.currentTarget, col.accessorKey, false);
4275-
else handleSort(col.accessorKey);
4284+
if (headerMenuOn(col)) openHeaderMenu(e.currentTarget, col.accessorKey, false);
4285+
else if (isColumnSortable(col)) handleSort(col.accessorKey);
42764286
}}
42774287
onContextMenu={(e) => handleColumnContextMenu(e, col.accessorKey)}
42784288
>

0 commit comments

Comments
 (0)