From fc35f47381650ced591b29f0fdcfc2c113d3b1bd Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 16:55:56 +0000 Subject: [PATCH 1/7] fix(plugin-list): list header opens a menu and keeps a multi-level sort; sort chip opens the sort panel Co-Authored-By: Claude --- .../35876-list-header-menu-multi-sort.md | 17 ++ .../DataPillar.recordsTab-34794.test.tsx | 2 +- .../components/src/context/gridHeaderMenu.tsx | 42 +++++ .../components/src/custom/sort-builder.tsx | 73 +++++++- ui/packages/components/src/index.ts | 7 + ...ta-table-header-column-menu-34794.test.tsx | 2 +- .../data-table-header-menu-35876.test.tsx | 139 ++++++++++++++ .../src/renderers/complex/data-table.tsx | 171 ++++++++++++------ ui/packages/i18n/src/locales/ar.ts | 1 + ui/packages/i18n/src/locales/de.ts | 1 + ui/packages/i18n/src/locales/en.ts | 1 + ui/packages/i18n/src/locales/es.ts | 1 + ui/packages/i18n/src/locales/fr.ts | 1 + ui/packages/i18n/src/locales/ja.ts | 1 + ui/packages/i18n/src/locales/ko.ts | 1 + ui/packages/i18n/src/locales/pt-BR.ts | 1 + ui/packages/i18n/src/locales/ru.ts | 1 + ui/packages/i18n/src/locales/zh-Hans.ts | 1 + ui/packages/i18n/src/locales/zh-Hant.ts | 1 + ui/packages/plugin-grid/src/ObjectGrid.tsx | 16 +- ui/packages/plugin-list/src/ListView.tsx | 22 ++- .../ListView.headerMenuSort-35876.test.tsx | 170 +++++++++++++++++ .../src/conditions/ListConditionControls.tsx | 67 ++++--- .../src/conditions/conditionModel.ts | 4 - 24 files changed, 649 insertions(+), 94 deletions(-) create mode 100644 .changeset/35876-list-header-menu-multi-sort.md create mode 100644 ui/packages/components/src/context/gridHeaderMenu.tsx create mode 100644 ui/packages/components/src/renderers/complex/__tests__/data-table-header-menu-35876.test.tsx create mode 100644 ui/packages/plugin-list/src/__tests__/ListView.headerMenuSort-35876.test.tsx diff --git a/.changeset/35876-list-header-menu-multi-sort.md b/.changeset/35876-list-header-menu-multi-sort.md new file mode 100644 index 00000000000..b2028ce17f3 --- /dev/null +++ b/.changeset/35876-list-header-menu-multi-sort.md @@ -0,0 +1,17 @@ +--- +'@object-ui/components': patch +'@object-ui/plugin-grid': patch +'@object-ui/plugin-list': patch +'@object-ui/i18n': patch +--- + +fix(plugin-list): a list's column header opens a menu and keeps a multi-level sort; a sort chip opens the sort panel + +Clause-②: yes (widening) +Metadata-protocol: none + +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. + +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. + +New public surface, all additive: `GridHeaderMenuProvider` and `useGridHeaderMenu` from `@object-ui/components` (a host opts a data-table into the header menu; without it a header click sorts as before, so related lists, dashboard tables and every other host keep click-to-sort); the `headerMenu` runtime prop on `ObjectGrid`; and the `sortBuilder.reorder` key in every `@object-ui/i18n` locale. The column menu itself is now a menu (`role="menu"` entries, keyboard reachable) wherever it opens, including a right-click on a header and the design host's caret. diff --git a/ui/packages/app-shell/src/views/studio-design/DataPillar.recordsTab-34794.test.tsx b/ui/packages/app-shell/src/views/studio-design/DataPillar.recordsTab-34794.test.tsx index b266f1961a3..f0621a76c42 100644 --- a/ui/packages/app-shell/src/views/studio-design/DataPillar.recordsTab-34794.test.tsx +++ b/ui/packages/app-shell/src/views/studio-design/DataPillar.recordsTab-34794.test.tsx @@ -181,7 +181,7 @@ describe('Data pillar Records tab (objectstack#34794)', () => { const caret = within(header('title')).getByRole('button', { name: COLUMN_MENU }); await userEvent.click(caret); const menu = screen.getByTestId('column-context-menu'); - expect(within(menu).getAllByRole('button')).toHaveLength(3); + expect(within(menu).getAllByRole('menuitem')).toHaveLength(3); // The caret's click selected nothing else and did not sort either. expect(firstTitles()).toEqual(before); }); diff --git a/ui/packages/components/src/context/gridHeaderMenu.tsx b/ui/packages/components/src/context/gridHeaderMenu.tsx new file mode 100644 index 00000000000..c4a3209076e --- /dev/null +++ b/ui/packages/components/src/context/gridHeaderMenu.tsx @@ -0,0 +1,42 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/** + * GridHeaderMenu — a data-table whose column header opens the column menu + * instead of sorting, opted into by a HOST, never by metadata + * (objectstack#35876). + * + * Inside a provider whose value is `true`, a click on a sortable column's + * header (or Enter, Space or ArrowDown while the header has focus) opens the + * column menu: sort ascending, sort descending, hide the column. The header + * itself never changes the sort. Outside a provider (`false`, the default) + * the header keeps its click-to-sort behaviour, so every host that does not + * mount this keeps what it had. + * + * `ObjectGrid` mounts it around the table it draws when its host asks for it + * (`ListView`, the list page, does). + */ + +import React from 'react'; + +const GridHeaderMenuContext = React.createContext(false); + +export function GridHeaderMenuProvider({ + value, + children, +}: { + value: boolean; + children: React.ReactNode; +}): React.ReactElement { + return {children}; +} + +/** Whether a host asked this table's column headers to open the column menu. */ +export function useGridHeaderMenu(): boolean { + return React.useContext(GridHeaderMenuContext); +} diff --git a/ui/packages/components/src/custom/sort-builder.tsx b/ui/packages/components/src/custom/sort-builder.tsx index ee6afdc0ea4..38a0b36d907 100644 --- a/ui/packages/components/src/custom/sort-builder.tsx +++ b/ui/packages/components/src/custom/sort-builder.tsx @@ -7,7 +7,7 @@ */ import * as React from "react" -import { X, Plus } from "lucide-react" +import { X, Plus, GripVertical } from "lucide-react" import { createSafeTranslation } from "@object-ui/i18n" import type { SortItem as SpecSortItem } from "@objectstack/spec/shared" @@ -26,6 +26,7 @@ const useSafeSortTranslation = createSafeTranslation( 'sortBuilder.newestFirst': 'Newest → Oldest', 'sortBuilder.addSort': 'Add sort', 'sortBuilder.removeSort': 'Remove sort', + 'sortBuilder.reorder': 'Drag to reorder', }, 'sortBuilder.sortBy', ) @@ -147,6 +148,20 @@ export function SortBuilder({ handleChange(items.filter(item => item.id !== id)); }; + // objectstack#35876 — the levels' order is the sort's priority: a row's + // handle drags it to another place, and ArrowUp / ArrowDown on the focused + // handle move it one place. + const dragFrom = React.useRef(null); + const handleRefs = React.useRef(new Map()); + const moveItem = (from: number, to: number) => { + if (from === to || from < 0 || to < 0 || from >= items.length || to >= items.length) return; + const next = items.slice(); + const [moved] = next.splice(from, 1); + next.splice(to, 0, moved); + handleChange(next); + return moved.id; + }; + return (
@@ -157,13 +172,59 @@ export function SortBuilder({ // the words, then the field beside Remove, then the direction.
{ + if (dragFrom.current === null) return; + event.preventDefault(); + event.stopPropagation(); + }} + onDrop={(event) => { + if (dragFrom.current === null) return; + event.preventDefault(); + event.stopPropagation(); + moveItem(dragFrom.current, index); + dragFrom.current = null; + }} > - + + {index === 0 ? t('sortBuilder.sortBy') : t('sortBuilder.thenBy')} -
+
-
+
s in the row are - * `role="combobox"`, which leaves exactly one button inside it. + * toolbar happens to render first; named, since the row also holds its + * drag handle (objectstack#35876). */ function removeSortRow(label: 'Sort by' | 'Then by') { const row = screen.getByText(label).parentElement as HTMLElement; - fireEvent.click(within(row).getByRole('button')); + fireEvent.click(within(row).getByRole('button', { name: /remove sort/i })); } /** "Add sort" — an edit to a DIFFERENT part of the sort than the refused row. */ diff --git a/ui/packages/plugin-list/src/__tests__/ListView.sortRemovableOnly-11943.test.tsx b/ui/packages/plugin-list/src/__tests__/ListView.sortRemovableOnly-11943.test.tsx index 4137c96aeb0..38e36153f26 100644 --- a/ui/packages/plugin-list/src/__tests__/ListView.sortRemovableOnly-11943.test.tsx +++ b/ui/packages/plugin-list/src/__tests__/ListView.sortRemovableOnly-11943.test.tsx @@ -214,7 +214,7 @@ describe('a field the Sort picker keeps only for the current sort is removable o // Removing its row ends the exception: the field leaves the list. const firstRow = within(sortPanel()).getByText('Sort by').parentElement as HTMLElement; - fireEvent.click(within(firstRow).getByRole('button')); + fireEvent.click(within(firstRow).getByRole('button', { name: /remove sort/i })); await waitFor(() => expect(sortRowTriggers()).toHaveLength(1)); expect(sortRowTriggers()[0]).toHaveTextContent('Title'); expect((await optionsOf(sortRowTriggers()[0])).map((o) => o.label)).toEqual(['Title', 'Priority']); diff --git a/ui/packages/plugin-list/src/__tests__/ListView.withheldFields-34901.test.tsx b/ui/packages/plugin-list/src/__tests__/ListView.withheldFields-34901.test.tsx index ad5d11519bc..9349007a237 100644 --- a/ui/packages/plugin-list/src/__tests__/ListView.withheldFields-34901.test.tsx +++ b/ui/packages/plugin-list/src/__tests__/ListView.withheldFields-34901.test.tsx @@ -165,7 +165,7 @@ describe('ListView over a field a disabled package withholds (objectstack#34901) fireEvent.click(await screen.findByTestId('sort-panel-open-advanced')); const rows = await screen.findAllByTestId('sort-builder-row'); expect(rows).toHaveLength(2); - fireEvent.click(within(rows[1]).getByRole('button')); + fireEvent.click(within(rows[1]).getByRole('button', { name: /remove sort/i })); await waitFor(() => expect(onSortChange).toHaveBeenCalled()); expect(onSortChange.mock.calls.at(-1)![0].map((s: any) => [s.field, s.order])).toEqual([[WITHHELD, 'asc']]); From c3e4d7765d4143583bee89f90716d9ecefd365f7 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 17:10:47 +0000 Subject: [PATCH 4/7] docs(plugin-grid): the list page's header menu and multi-level sort Co-Authored-By: Claude --- content/docs/frontend/plugins/plugin-grid.mdx | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/content/docs/frontend/plugins/plugin-grid.mdx b/content/docs/frontend/plugins/plugin-grid.mdx index 31d1c45621c..614a5117a49 100644 --- a/content/docs/frontend/plugins/plugin-grid.mdx +++ b/content/docs/frontend/plugins/plugin-grid.mdx @@ -111,6 +111,26 @@ is no top-level `sortable` switch. } ``` +A click on a sortable column header sorts by that column; another click on it +changes the direction. + +**On an object's list page** the header opens a menu instead +(objectstack#35876), which its host turns on (the `headerMenu` component +prop, not a schema key): **Sort ascending**, **Sort descending** and **Hide +column**. The header itself never changes the sort. Enter, Space or ArrowDown +on the focused header opens the same menu; the arrows move through it, Enter +chooses and Escape closes 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 and every other level + keeps its place after it; a column already in the sort moves up with the + picked direction. No level is dropped. +- The ↑1 / ↓2 marks on the headers show each level's place. +- A sort chip under the view bar opens every level in one panel (it does not + reverse the direction). Each level's handle reorders it: drag it to another + row, or press ArrowUp / ArrowDown on the focused handle. + ### Filtering and search There is no per-column filter key and no top-level `filterable` switch. A grid From 663cd467bffc3c23bbd625378557a81939720744 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 18:09:39 +0000 Subject: [PATCH 5/7] fix(components): type-clean column menu focus; migrate the condition-row e2e spec DropdownMenuContent does not type onOpenAutoFocus, so the declaration build failed. A keyboard-opened column menu now focuses its first entry from an effect once the content mounts. The condition-row e2e spec read the old sort chip testid and a header click that sorted; the header now opens the column menu and the entry chosen there sorts. Review nits: a sort chip's panel is a required prop of ConditionChipRow, the unread toggleSort fallback is dropped, and a header that opens the menu shows a focus ring. Co-Authored-By: Claude --- ui/e2e/list-condition-row-35549.spec.ts | 16 +++++++++++----- .../src/renderers/complex/data-table.tsx | 18 +++++++++++++----- .../src/conditions/ListConditionControls.tsx | 3 +-- .../src/conditions/conditionTranslations.ts | 1 - 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/ui/e2e/list-condition-row-35549.spec.ts b/ui/e2e/list-condition-row-35549.spec.ts index d11f59615db..f71304ae73c 100644 --- a/ui/e2e/list-condition-row-35549.spec.ts +++ b/ui/e2e/list-condition-row-35549.spec.ts @@ -318,7 +318,7 @@ test.describe('list condition row under the view bar (objectstack#35549, objects expect(await slotHeight(page)).toBe(0); }); - test('sort: Sort → Descending → Amount is three clicks; chips come before filter chips; a drag reorders; a header click shows as a chip; Reset restores', async ({ page }) => { + 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 }) => { test.setTimeout(120_000); await mount(page); await expect.poll(() => count(page)).toBe('12'); @@ -326,8 +326,8 @@ test.describe('list condition row under the view bar (objectstack#35549, objects await click(page, 'sort-panel-order-desc'); await click(page, 'sort-panel-fields-item-amount'); expect(await sortNow(page)).toEqual(['amount:desc']); - await expect(page.getByTestId('sort-chip-toggle-amount')).toHaveText('Amount'); - await expect(page.getByTestId('sort-chip-toggle-amount')).toHaveAttribute('title', 'High → Low'); + await expect(page.getByTestId('sort-chip-open-amount')).toHaveText('Amount'); + await expect(page.getByTestId('sort-chip-open-amount')).toHaveAttribute('title', 'High → Low'); // a second level await click(page, 'toolbar-sort-trigger'); await click(page, 'sort-panel-fields-item-stage'); @@ -359,10 +359,16 @@ test.describe('list condition row under the view bar (objectstack#35549, objects expect(await sortNow(page)).toEqual([]); await expect.poll(() => count(page)).toBe('12'); expect(await slotHeight(page)).toBe(0); - // a click on a column header sorts, and the row shows it as a chip + // a click on a column header opens its menu and sorts nothing + // (objectstack#35876); the entry chosen there sorts, and the row shows it + // as a chip await page.getByRole('columnheader', { name: /Amount/ }).click(); + const columnMenu = page.getByTestId('column-context-menu'); + await expect(columnMenu).toBeVisible(); + expect(await sortNow(page)).toEqual([]); + await columnMenu.getByRole('menuitem', { name: 'Sort descending' }).click(); await style(page); await expect(page.getByTestId('sort-chip-amount')).toBeVisible(); - expect((await sortNow(page))[0]).toMatch(/^amount:/); + expect(await sortNow(page)).toEqual(['amount:desc']); }); }); diff --git a/ui/packages/components/src/renderers/complex/data-table.tsx b/ui/packages/components/src/renderers/complex/data-table.tsx index 49f4eac5368..266c4ec5de1 100644 --- a/ui/packages/components/src/renderers/complex/data-table.tsx +++ b/ui/packages/components/src/renderers/complex/data-table.tsx @@ -2495,6 +2495,17 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => { !byKeyboard && open?.columnKey === columnKey ? null : { x: r.left, y: r.bottom, columnKey }, ); }; + // A menu opened from the keyboard starts on its first entry. Radix moves + // focus into a keyboard-opened menu only when it saw the key itself, and + // this one mounts after the header's keydown; so the first entry is focused + // once the content is in the document, after Radix's own mount focus. + useEffect(() => { + if (!contextMenu || !columnMenuByKeyboardRef.current) return; + const frame = requestAnimationFrame(() => { + columnMenuContentRef.current?.querySelector('[role="menuitem"]')?.focus(); + }); + return () => cancelAnimationFrame(frame); + }, [contextMenu]); // The column the open context menu belongs to (objectui#10727). The menu // holds only a key, so it is resolved from `columns`, the list the header @@ -4216,6 +4227,8 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => { className={cn( col.className, isColumnSortable(col) && 'cursor-pointer select-none', + // A header that opens the column menu is a tab stop (objectstack#35876). + headerMenuOn(col) && 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring', isDragging && 'opacity-50', isDragOver && 'border-l-2 border-primary', col.align === 'right' && 'text-right', @@ -5445,11 +5458,6 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => { className="min-w-[160px]" data-testid="column-context-menu" onClick={(e) => e.stopPropagation()} - onOpenAutoFocus={(e) => { - if (!columnMenuByKeyboardRef.current) return; - e.preventDefault(); - columnMenuContentRef.current?.querySelector('[role="menuitem"]')?.focus(); - }} onInteractOutside={(e) => { // A press on the control the menu was opened from is that // control's own toggle: its click shuts the menu. diff --git a/ui/packages/plugin-list/src/conditions/ListConditionControls.tsx b/ui/packages/plugin-list/src/conditions/ListConditionControls.tsx index 6327afa969c..27b84e1e6f8 100644 --- a/ui/packages/plugin-list/src/conditions/ListConditionControls.tsx +++ b/ui/packages/plugin-list/src/conditions/ListConditionControls.tsx @@ -477,7 +477,7 @@ export interface ConditionChipRowProps { * 「all sort levels」 step): a sort chip opens it (objectstack#35876). The * chip itself never changes the sort. */ - renderSortLevels?: () => React.ReactNode; + renderSortLevels: () => React.ReactNode; /** * Back to the view as saved. Drawn only when passed: the host passes it * only while the reader has something of their own to reset. @@ -610,7 +610,6 @@ export function ConditionChipRow({ {label} ); - if (!renderSortLevels) return chipButton; // objectstack#35876 — the chip opens every sort level in one // panel; it does not flip the direction. return ( diff --git a/ui/packages/plugin-list/src/conditions/conditionTranslations.ts b/ui/packages/plugin-list/src/conditions/conditionTranslations.ts index 0105091693c..f272bab9d89 100644 --- a/ui/packages/plugin-list/src/conditions/conditionTranslations.ts +++ b/ui/packages/plugin-list/src/conditions/conditionTranslations.ts @@ -68,7 +68,6 @@ export const LIST_CONDITION_DEFAULT_TRANSLATIONS: Record = { 'listConditions.chips.reset': 'Reset', 'listConditions.chips.resetHint': 'Back to the view as saved', 'listConditions.chips.remove': 'Remove {{label}}', - 'listConditions.chips.toggleSort': 'Reverse {{label}}', 'listConditions.chips.dragSort': 'Drag to change the sort priority', 'listConditions.chips.viewOwn': 'Part of this view; it cannot be removed here', 'listConditions.chips.viewFilter': 'View filter', From 046c89d32ac447621e3e3728a1591f712280a7c3 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 18:30:15 +0000 Subject: [PATCH 6/7] fix(i18n): regenerate zh-Hant from zh-Hans for the sort builder's reorder key Co-Authored-By: Claude --- ui/packages/i18n/src/locales/zh-Hant.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/packages/i18n/src/locales/zh-Hant.ts b/ui/packages/i18n/src/locales/zh-Hant.ts index f6ceb71787f..7bd66114f3f 100644 --- a/ui/packages/i18n/src/locales/zh-Hant.ts +++ b/ui/packages/i18n/src/locales/zh-Hant.ts @@ -5048,7 +5048,7 @@ const zhHant = { newestFirst: '最新 → 最早', addSort: '新增排序', removeSort: '刪除排序', - reorder: '拖曳以調整先後', + reorder: '拖動以調整先後', }, collaboration: { commentCount: '{{count}} 條評論', From 7dcbb2e8947c4fd8366cb623198658e6b2f87399 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 19:24:06 +0000 Subject: [PATCH 7/7] 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 --- .../35876-list-header-menu-multi-sort.md | 2 +- content/docs/frontend/plugins/plugin-grid.mdx | 3 +- ui/e2e/list-condition-row-35549.spec.ts | 11 ++++++- .../sort-builder-reorder-35876.test.tsx | 11 +++++-- .../components/src/custom/sort-builder.tsx | 16 ++++++---- .../data-table-header-menu-35876.test.tsx | 29 ++++++++++++++----- .../src/renderers/complex/data-table.tsx | 28 ++++++++++++------ 7 files changed, 71 insertions(+), 29 deletions(-) diff --git a/.changeset/35876-list-header-menu-multi-sort.md b/.changeset/35876-list-header-menu-multi-sort.md index b2028ce17f3..ec11c9be232 100644 --- a/.changeset/35876-list-header-menu-multi-sort.md +++ b/.changeset/35876-list-header-menu-multi-sort.md @@ -10,7 +10,7 @@ fix(plugin-list): a list's column header opens a menu and keeps a multi-level so Clause-②: yes (widening) Metadata-protocol: none -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. +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. 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. diff --git a/content/docs/frontend/plugins/plugin-grid.mdx b/content/docs/frontend/plugins/plugin-grid.mdx index 614a5117a49..788cd62026b 100644 --- a/content/docs/frontend/plugins/plugin-grid.mdx +++ b/content/docs/frontend/plugins/plugin-grid.mdx @@ -117,7 +117,8 @@ changes the direction. **On an object's list page** the header opens a menu instead (objectstack#35876), which its host turns on (the `headerMenu` component prop, not a schema key): **Sort ascending**, **Sort descending** and **Hide -column**. The header itself never changes the sort. Enter, Space or ArrowDown +column**. A column that does not sort offers **Hide column** alone. The +header itself never changes the sort. Enter, Space or ArrowDown on the focused header opens the same menu; the arrows move through it, Enter chooses and Escape closes it without touching the sort. diff --git a/ui/e2e/list-condition-row-35549.spec.ts b/ui/e2e/list-condition-row-35549.spec.ts index f71304ae73c..79ca8e8900c 100644 --- a/ui/e2e/list-condition-row-35549.spec.ts +++ b/ui/e2e/list-condition-row-35549.spec.ts @@ -318,7 +318,7 @@ test.describe('list condition row under the view bar (objectstack#35549, objects expect(await slotHeight(page)).toBe(0); }); - 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 }) => { + 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 }) => { test.setTimeout(120_000); await mount(page); await expect.poll(() => count(page)).toBe('12'); @@ -354,6 +354,15 @@ test.describe('list condition row under the view bar (objectstack#35549, objects // a real drag: the second sort chip onto the first await page.getByTestId('sort-chip-stage').dragTo(page.getByTestId('sort-chip-amount')); expect(await sortNow(page)).toEqual(['stage:asc', 'amount:desc']); + // a chip opens every level in one panel (objectstack#35876); a real drag of + // the second level's handle onto the first row puts it first + await click(page, 'sort-chip-open-stage'); + const panel = page.getByTestId('sort-chip-panel'); + await expect(panel.getByTestId('sort-builder-handle')).toHaveCount(2); + expect(await sortNow(page)).toEqual(['stage:asc', 'amount:desc']); + await panel.getByTestId('sort-builder-handle').nth(1).dragTo(panel.getByTestId('sort-builder-row').first()); + await expect.poll(() => sortNow(page)).toEqual(['amount:desc', 'stage:asc']); + await page.keyboard.press('Escape'); // Reset puts the list back as saved: no sort, no filter await click(page, 'condition-reset'); expect(await sortNow(page)).toEqual([]); diff --git a/ui/packages/components/src/__tests__/sort-builder-reorder-35876.test.tsx b/ui/packages/components/src/__tests__/sort-builder-reorder-35876.test.tsx index a974a9448e5..ce1aba0010d 100644 --- a/ui/packages/components/src/__tests__/sort-builder-reorder-35876.test.tsx +++ b/ui/packages/components/src/__tests__/sort-builder-reorder-35876.test.tsx @@ -52,11 +52,15 @@ function mount(initial: SortItem[]) { const fieldsOf = (items: SortItem[]) => items.map((i) => `${i.field}:${i.order}`); describe('SortBuilder — reordering the levels (objectstack#35876)', () => { - it('every level has a named handle', () => { + it('every level has a named handle: a keyboard control that is not a + {index === 0 ? t('sortBuilder.sortBy') : t('sortBuilder.thenBy')} diff --git a/ui/packages/components/src/renderers/complex/__tests__/data-table-header-menu-35876.test.tsx b/ui/packages/components/src/renderers/complex/__tests__/data-table-header-menu-35876.test.tsx index 74d4aa74bf0..52ab6ed3da5 100644 --- a/ui/packages/components/src/renderers/complex/__tests__/data-table-header-menu-35876.test.tsx +++ b/ui/packages/components/src/renderers/complex/__tests__/data-table-header-menu-35876.test.tsx @@ -7,10 +7,11 @@ */ /** - * objectstack#35876 — under `GridHeaderMenu` a sortable column header opens - * the column menu (sort ascending, sort descending, hide) and never sorts by - * itself; the keyboard reaches the same menu from the focused header. Without - * the provider the header still sorts on a click. + * objectstack#35876 — under `GridHeaderMenu` every column header opens the + * column menu (sort ascending, sort descending, hide; a header that does not + * sort offers hide alone) and never sorts by itself; the keyboard reaches the + * same menu from the focused header. Without the provider the header still + * sorts on a click. */ import { describe, it, expect, afterEach, vi } from 'vitest'; 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)', await waitFor(() => expect(th).toHaveFocus()); }); - it('a header that does not sort opens no menu on a click and takes no focus', () => { + it('a header that does not sort opens a menu with Hide column alone, and changes no sort', () => { const { onSortChange } = renderManual({ headerMenu: true, statusSortable: false }); + expect(header('status')).toHaveAttribute('tabindex', '0'); + expect(header('status')).toHaveAttribute('aria-haspopup', 'menu'); fireEvent.click(header('status')); - expect(menu()).toBeNull(); - expect(header('status')).not.toHaveAttribute('tabindex'); - expect(header('status')).not.toHaveAttribute('aria-haspopup'); + expect(within(menu()!).getAllByRole('menuitem').map((b) => b.textContent)).toEqual(['Hide column']); + expect(onSortChange).not.toHaveBeenCalled(); + }); + + it('Hide column from the keyboard gives focus to the header beside the hidden one', async () => { + const { onSortChange } = renderManual({ headerMenu: true }); + act(() => header('name').focus()); + await userEvent.keyboard('{Enter}'); + const items = within(menu()!).getAllByRole('menuitem'); + await waitFor(() => expect(items[0]).toHaveFocus()); + await userEvent.keyboard('{ArrowDown}{ArrowDown}{Enter}'); + expect(header('name')).toBeNull(); + await waitFor(() => expect(header('status')).toHaveFocus()); expect(onSortChange).not.toHaveBeenCalled(); }); diff --git a/ui/packages/components/src/renderers/complex/data-table.tsx b/ui/packages/components/src/renderers/complex/data-table.tsx index 266c4ec5de1..700c0ef1b7c 100644 --- a/ui/packages/components/src/renderers/complex/data-table.tsx +++ b/ui/packages/components/src/renderers/complex/data-table.tsx @@ -2482,11 +2482,12 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => { setContextMenu({ x: e.clientX, y: e.clientY, columnKey }); }; - // objectstack#35876 — under `GridHeaderMenu` a sortable header opens the - // column menu below itself (a click, or Enter / Space / ArrowDown while it - // has focus) and never sorts; the sort is the entry chosen in the menu. A - // click on the header whose menu is open shuts it. - const headerMenuOn = (col: TableColumn) => headerOpensMenu && isColumnSortable(col); + // objectstack#35876 — under `GridHeaderMenu` every header opens the column + // menu below itself (a click, or Enter / Space / ArrowDown while it has + // focus) and never sorts; the sort is the entry chosen in the menu, which + // offers sort entries only where `isColumnSortable` does. A click on the + // header whose menu is open shuts it. + const headerMenuOn = (_col: TableColumn) => headerOpensMenu; const openHeaderMenu = (header: HTMLElement, columnKey: string, byKeyboard: boolean) => { columnMenuReturnFocusRef.current = header; columnMenuByKeyboardRef.current = byKeyboard; @@ -2520,6 +2521,16 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => { : undefined; const hideColumn = (columnKey: string) => { + // The header the menu came from is about to go: focus returns to the + // header beside it (the next one, else the previous), when that one is a + // tab stop. + const from = columnMenuReturnFocusRef.current?.closest('th'); + if (from && from.getAttribute('data-column-key') === columnKey) { + const beside = [from.nextElementSibling, from.previousElementSibling].find( + (el): el is HTMLElement => el instanceof HTMLElement && el.hasAttribute('data-column-key') && el.tabIndex >= 0, + ); + columnMenuReturnFocusRef.current = beside ?? null; + } setColumns(prev => prev.filter(c => c.accessorKey !== columnKey)); setContextMenu(null); }; @@ -4226,7 +4237,7 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => { data-column-key={col.accessorKey} className={cn( col.className, - isColumnSortable(col) && 'cursor-pointer select-none', + (isColumnSortable(col) || headerMenuOn(col)) && 'cursor-pointer select-none', // A header that opens the column menu is a tab stop (objectstack#35876). headerMenuOn(col) && 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring', isDragging && 'opacity-50', @@ -4270,9 +4281,8 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => { } : {})} onClick={(e) => { - if (!isColumnSortable(col)) return; - if (headerOpensMenu) openHeaderMenu(e.currentTarget, col.accessorKey, false); - else handleSort(col.accessorKey); + if (headerMenuOn(col)) openHeaderMenu(e.currentTarget, col.accessorKey, false); + else if (isColumnSortable(col)) handleSort(col.accessorKey); }} onContextMenu={(e) => handleColumnContextMenu(e, col.accessorKey)} >