@svgrid/grid 2.2.28 → 2.2.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/GridMenus.svelte +148 -100
- package/dist/SvGrid.controller.svelte.d.ts +14 -1
- package/dist/SvGrid.controller.svelte.js +112 -28
- package/dist/SvGrid.css +15 -34
- package/dist/SvGrid.svelte +49 -21
- package/dist/SvGrid.types.d.ts +20 -5
- package/dist/SvListBox.svelte +42 -3
- package/dist/SvListBox.svelte.d.ts +10 -1
- package/dist/cdn/GridMenus-Da_p7SKS.js +486 -0
- package/dist/cdn/GridMenus-Ds3OpzZT.js +490 -0
- package/dist/cdn/{src-BxNEslEo.js → src-BLJfdyL0.js} +4014 -3869
- package/dist/cdn/{src-C4yKQZ5t.js → src-DYDCiC0D.js} +7036 -6891
- package/dist/cdn/svgrid.js +8 -8
- package/dist/cdn/svgrid.svelte-external.js +8 -8
- package/dist/column-groups.js +8 -10
- package/dist/column-id.d.ts +9 -0
- package/dist/column-id.js +25 -0
- package/dist/core.js +2 -1
- package/dist/createListbox.svelte.d.ts +15 -2
- package/dist/createListbox.svelte.js +27 -6
- package/dist/editing.d.ts +1 -0
- package/dist/editing.js +45 -10
- package/dist/filtering/excel-filters.d.ts +30 -10
- package/dist/filtering/excel-filters.js +96 -15
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/menus.d.ts +2 -0
- package/dist/menus.js +25 -0
- package/dist/row-resize.js +40 -0
- package/dist/selection.js +1 -1
- package/package.json +1 -1
- package/src/GridMenus.svelte +148 -100
- package/src/SvGrid.controller.svelte.ts +123 -27
- package/src/SvGrid.css +15 -34
- package/src/SvGrid.svelte +49 -21
- package/src/SvGrid.types.ts +20 -5
- package/src/SvListBox.svelte +42 -3
- package/src/column-groups.test.ts +48 -0
- package/src/column-groups.ts +8 -10
- package/src/column-id.ts +30 -0
- package/src/core.ts +2 -1
- package/src/createListbox.svelte.ts +39 -7
- package/src/editing.test.ts +90 -0
- package/src/editing.ts +46 -12
- package/src/filtering/excel-filters.test.ts +44 -1
- package/src/filtering/excel-filters.ts +91 -14
- package/src/index.ts +2 -0
- package/src/menus.test.ts +40 -4
- package/src/menus.ts +27 -0
- package/src/row-resize.test.ts +100 -0
- package/src/row-resize.ts +36 -0
- package/src/selection.ts +1 -1
- package/src/svgrid.api-extensions.test.ts +8 -3
- package/src/svgrid.cell-dom-ids.test.ts +96 -0
- package/src/svgrid.conditional-stat-scope.test.ts +111 -0
- package/src/svgrid.filter-menu-listbox.svelte.test.ts +308 -0
- package/src/svgrid.filter-menu-scroll.test.ts +3 -1
- package/src/svgrid.group-header-ids.test.ts +121 -0
- package/dist/cdn/GridMenus-BbzEvTYO.js +0 -421
- package/dist/cdn/GridMenus-E220X2kM.js +0 -417
package/src/row-resize.ts
CHANGED
|
@@ -81,6 +81,37 @@ export function rowResize(node: HTMLElement, opts: RowResizeOptions) {
|
|
|
81
81
|
document.body.style.cursor = ''
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Keyboard resize (#79). The strip is `role="separator"` acting as a
|
|
86
|
+
* splitter, so it has to be reachable by Tab and respond to arrow keys.
|
|
87
|
+
* Up/Down shrink/grow the row, Shift gives a fine 1px step - the same
|
|
88
|
+
* contract the column resize handle uses (Left/Right, Shift = 1px).
|
|
89
|
+
*/
|
|
90
|
+
function onKeyDown(e: KeyboardEvent) {
|
|
91
|
+
if (current.disabled) return
|
|
92
|
+
const t = e.target as HTMLElement | null
|
|
93
|
+
if (!t?.classList.contains(STRIP_CLASS)) return
|
|
94
|
+
const step = e.shiftKey ? 1 : 10
|
|
95
|
+
let delta = 0
|
|
96
|
+
if (e.key === 'ArrowUp') delta = -step
|
|
97
|
+
else if (e.key === 'ArrowDown') delta = step
|
|
98
|
+
else return
|
|
99
|
+
const tr = t.closest<HTMLTableRowElement>('tr.sv-grid-row')
|
|
100
|
+
if (!tr) return
|
|
101
|
+
const rowIndex = rowIndexOf(tr)
|
|
102
|
+
if (!Number.isFinite(rowIndex)) return
|
|
103
|
+
e.preventDefault()
|
|
104
|
+
e.stopPropagation()
|
|
105
|
+
const min = current.min ?? 20
|
|
106
|
+
const max = current.max ?? 320
|
|
107
|
+
const next = Math.round(
|
|
108
|
+
Math.max(min, Math.min(max, tr.getBoundingClientRect().height + delta)),
|
|
109
|
+
)
|
|
110
|
+
tr.style.height = `${next}px`
|
|
111
|
+
current.onResizeMove?.(rowIndex, next)
|
|
112
|
+
current.onResize(rowIndex, next)
|
|
113
|
+
}
|
|
114
|
+
|
|
84
115
|
function onPointerDown(e: PointerEvent) {
|
|
85
116
|
if (current.disabled) return
|
|
86
117
|
const t = e.target as HTMLElement | null
|
|
@@ -134,6 +165,9 @@ export function rowResize(node: HTMLElement, opts: RowResizeOptions) {
|
|
|
134
165
|
strip.setAttribute('role', 'separator')
|
|
135
166
|
strip.setAttribute('aria-orientation', 'horizontal')
|
|
136
167
|
strip.setAttribute('aria-label', 'Resize row')
|
|
168
|
+
// A separator used as an interactive splitter has to be focusable so
|
|
169
|
+
// keyboard-only users can reach it and drive `onKeyDown` (#79).
|
|
170
|
+
strip.tabIndex = 0
|
|
137
171
|
// Inline the geometry + pointer-events so the strip works even
|
|
138
172
|
// before SvGrid.css is parsed; the hover tint still comes from
|
|
139
173
|
// the stylesheet. We keep the strip fully inside the gutter
|
|
@@ -152,6 +186,7 @@ export function rowResize(node: HTMLElement, opts: RowResizeOptions) {
|
|
|
152
186
|
}
|
|
153
187
|
|
|
154
188
|
node.addEventListener('pointerdown', onPointerDown, { capture: true })
|
|
189
|
+
node.addEventListener('keydown', onKeyDown, { capture: true })
|
|
155
190
|
const observer = new MutationObserver(() => decorate())
|
|
156
191
|
observer.observe(node, { childList: true, subtree: true })
|
|
157
192
|
decorate()
|
|
@@ -165,6 +200,7 @@ export function rowResize(node: HTMLElement, opts: RowResizeOptions) {
|
|
|
165
200
|
},
|
|
166
201
|
destroy() {
|
|
167
202
|
node.removeEventListener('pointerdown', onPointerDown, { capture: true })
|
|
203
|
+
node.removeEventListener('keydown', onKeyDown, { capture: true })
|
|
168
204
|
window.removeEventListener('pointermove', onPointerMove)
|
|
169
205
|
window.removeEventListener('pointerup', onPointerUp)
|
|
170
206
|
observer.disconnect()
|
package/src/selection.ts
CHANGED
|
@@ -153,7 +153,7 @@ export function createSelection<
|
|
|
153
153
|
ctx.grid.setActiveCell({
|
|
154
154
|
rowIndex,
|
|
155
155
|
colIndex,
|
|
156
|
-
cellId: getGridCellDomId(
|
|
156
|
+
cellId: getGridCellDomId(ctx.gridDomId, rowIndex, colIndex),
|
|
157
157
|
});
|
|
158
158
|
// Notify consumers (toolbars, ribbons) so they stay synced without
|
|
159
159
|
// having to listen on the DOM. Fired on EVERY active-cell move -
|
|
@@ -309,9 +309,14 @@ describe('SvGridApi - view state (getState / setState)', () => {
|
|
|
309
309
|
})
|
|
310
310
|
|
|
311
311
|
describe('SvGridApi - click / double-click / scroll events', () => {
|
|
312
|
-
function clickCell(
|
|
313
|
-
|
|
314
|
-
|
|
312
|
+
function clickCell(target: HTMLElement, rowIndex: number, colIndex: number, type: 'click' | 'dblclick') {
|
|
313
|
+
// Cell ids are scoped per grid instance (#77), so resolve the base from the
|
|
314
|
+
// grid under test rather than assuming the old global "svgrid" prefix.
|
|
315
|
+
const anyCell = target.querySelector<HTMLElement>('[role="gridcell"][id]')
|
|
316
|
+
const base = anyCell?.id.replace(/_cell_\d+_\d+$/, '')
|
|
317
|
+
if (!base) throw new Error('no gridcell with an id found')
|
|
318
|
+
const id = getGridCellDomId(base, rowIndex, colIndex)
|
|
319
|
+
const el = target.querySelector<HTMLElement>(`[id="${id}"]`)
|
|
315
320
|
if (!el) throw new Error(`cell ${id} not found`)
|
|
316
321
|
el.dispatchEvent(new MouseEvent(type, { bubbles: true }))
|
|
317
322
|
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DOM: cell ids are scoped per grid instance (#77).
|
|
3
|
+
*
|
|
4
|
+
* Every cell used to be minted as `svgrid_cell_<row>_<col>`, so two grids on
|
|
5
|
+
* one page emitted the same ids. Duplicate ids break `getElementById` and made
|
|
6
|
+
* the second grid's `aria-activedescendant` point at the first grid's cell, so
|
|
7
|
+
* a screen reader announced the wrong cell.
|
|
8
|
+
*/
|
|
9
|
+
import { afterEach, describe, expect, it } from 'vitest'
|
|
10
|
+
import { mount, unmount } from 'svelte'
|
|
11
|
+
import SvGrid from './SvGrid.svelte'
|
|
12
|
+
import {
|
|
13
|
+
createCoreRowModel,
|
|
14
|
+
createFilteredRowModel,
|
|
15
|
+
createPaginatedRowModel,
|
|
16
|
+
createSortedRowModel,
|
|
17
|
+
sortFns,
|
|
18
|
+
tableFeatures,
|
|
19
|
+
rowSortingFeature,
|
|
20
|
+
} from './index'
|
|
21
|
+
import type { ColumnDef } from './index'
|
|
22
|
+
|
|
23
|
+
type Row = { id: number; name: string }
|
|
24
|
+
const features = tableFeatures({ rowSortingFeature })
|
|
25
|
+
const cols: ColumnDef<typeof features, Row>[] = [
|
|
26
|
+
{ field: 'name', header: 'Name', width: 160 },
|
|
27
|
+
]
|
|
28
|
+
const data: Row[] = [
|
|
29
|
+
{ id: 1, name: 'one' },
|
|
30
|
+
{ id: 2, name: 'two' },
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
const tick = () => new Promise<void>((r) => queueMicrotask(r))
|
|
34
|
+
|
|
35
|
+
function mountGrid() {
|
|
36
|
+
const target = document.createElement('div')
|
|
37
|
+
document.body.appendChild(target)
|
|
38
|
+
const app = mount(SvGrid, {
|
|
39
|
+
target,
|
|
40
|
+
props: {
|
|
41
|
+
data,
|
|
42
|
+
columns: cols,
|
|
43
|
+
features,
|
|
44
|
+
_rowModels: {
|
|
45
|
+
coreRowModel: createCoreRowModel(),
|
|
46
|
+
filteredRowModel: createFilteredRowModel(),
|
|
47
|
+
sortedRowModel: createSortedRowModel(sortFns),
|
|
48
|
+
paginatedRowModel: createPaginatedRowModel(),
|
|
49
|
+
},
|
|
50
|
+
containerHeight: 240,
|
|
51
|
+
virtualization: false,
|
|
52
|
+
} as never,
|
|
53
|
+
})
|
|
54
|
+
return { target, destroy: () => { unmount(app); target.remove() } }
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const cleanups: Array<() => void> = []
|
|
58
|
+
afterEach(() => {
|
|
59
|
+
while (cleanups.length) cleanups.pop()!()
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
describe('cell DOM ids', () => {
|
|
63
|
+
it('gives two grids on the same page disjoint cell ids (#77)', async () => {
|
|
64
|
+
const a = mountGrid()
|
|
65
|
+
const b = mountGrid()
|
|
66
|
+
cleanups.push(a.destroy, b.destroy)
|
|
67
|
+
await tick()
|
|
68
|
+
|
|
69
|
+
const idsOf = (root: HTMLElement) =>
|
|
70
|
+
[...root.querySelectorAll('[role="gridcell"][id]')].map((el) => el.id)
|
|
71
|
+
const aIds = idsOf(a.target)
|
|
72
|
+
const bIds = idsOf(b.target)
|
|
73
|
+
|
|
74
|
+
expect(aIds.length).toBeGreaterThan(0)
|
|
75
|
+
expect(bIds.length).toBe(aIds.length)
|
|
76
|
+
// No id appears in both grids.
|
|
77
|
+
expect(aIds.filter((id) => bIds.includes(id))).toEqual([])
|
|
78
|
+
// And every id in the document is unique.
|
|
79
|
+
const all = [...aIds, ...bIds]
|
|
80
|
+
expect(new Set(all).size).toBe(all.length)
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it('points aria-activedescendant at a cell inside its own grid (#77)', async () => {
|
|
84
|
+
const a = mountGrid()
|
|
85
|
+
const b = mountGrid()
|
|
86
|
+
cleanups.push(a.destroy, b.destroy)
|
|
87
|
+
await tick()
|
|
88
|
+
|
|
89
|
+
for (const { target } of [a, b]) {
|
|
90
|
+
const grid = target.querySelector('[aria-activedescendant]')
|
|
91
|
+
expect(grid).not.toBeNull()
|
|
92
|
+
const descendantId = grid!.getAttribute('aria-activedescendant')!
|
|
93
|
+
expect(target.querySelector(`[id="${descendantId}"]`)).not.toBeNull()
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
})
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DOM: `conditionalStatScope` decides which rows feed the min/max that
|
|
3
|
+
* `colorScale` / `dataBar` scale against (#61).
|
|
4
|
+
*
|
|
5
|
+
* The old default scanned only the current page, so the same value rendered a
|
|
6
|
+
* different bar on page 1 than on page 2. The default is now `filtered`, which
|
|
7
|
+
* ignores the page slice; `visible` keeps the old per-page behaviour for anyone
|
|
8
|
+
* who wants it.
|
|
9
|
+
*/
|
|
10
|
+
import { afterEach, describe, expect, it } from 'vitest'
|
|
11
|
+
import { mount, unmount } from 'svelte'
|
|
12
|
+
import SvGrid from './SvGrid.svelte'
|
|
13
|
+
import {
|
|
14
|
+
createCoreRowModel,
|
|
15
|
+
createFilteredRowModel,
|
|
16
|
+
createPaginatedRowModel,
|
|
17
|
+
createSortedRowModel,
|
|
18
|
+
sortFns,
|
|
19
|
+
tableFeatures,
|
|
20
|
+
rowSortingFeature,
|
|
21
|
+
} from './index'
|
|
22
|
+
|
|
23
|
+
type Row = { id: number; v: number }
|
|
24
|
+
const features = tableFeatures({ rowSortingFeature })
|
|
25
|
+
const columns = [{ field: 'v', header: 'V', width: 120 }]
|
|
26
|
+
|
|
27
|
+
// Page 1 spans 0..50, page 2 spans 0..100. The value 50 is the page-1 max but
|
|
28
|
+
// only mid-range on page 2, so a per-page scale draws it at two different
|
|
29
|
+
// widths while a filtered-wide scale draws it identically.
|
|
30
|
+
const data: Row[] = [
|
|
31
|
+
{ id: 1, v: 0 },
|
|
32
|
+
{ id: 2, v: 50 },
|
|
33
|
+
{ id: 3, v: 0 },
|
|
34
|
+
{ id: 4, v: 100 },
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
const conditionalFormats = [
|
|
38
|
+
{ type: 'dataBar', columns: ['v'], color: '#2563eb' },
|
|
39
|
+
] as never
|
|
40
|
+
|
|
41
|
+
const tick = () => new Promise<void>((r) => queueMicrotask(r))
|
|
42
|
+
|
|
43
|
+
function mountGrid(props: Record<string, unknown>) {
|
|
44
|
+
const target = document.createElement('div')
|
|
45
|
+
document.body.appendChild(target)
|
|
46
|
+
const app = mount(SvGrid, {
|
|
47
|
+
target,
|
|
48
|
+
props: {
|
|
49
|
+
data,
|
|
50
|
+
columns,
|
|
51
|
+
features,
|
|
52
|
+
conditionalFormats,
|
|
53
|
+
pageable: true,
|
|
54
|
+
pageSize: 2,
|
|
55
|
+
_rowModels: {
|
|
56
|
+
coreRowModel: createCoreRowModel(),
|
|
57
|
+
filteredRowModel: createFilteredRowModel(),
|
|
58
|
+
sortedRowModel: createSortedRowModel(sortFns),
|
|
59
|
+
paginatedRowModel: createPaginatedRowModel(),
|
|
60
|
+
},
|
|
61
|
+
containerHeight: 240,
|
|
62
|
+
virtualization: false,
|
|
63
|
+
...props,
|
|
64
|
+
} as never,
|
|
65
|
+
})
|
|
66
|
+
return { target, destroy: () => { unmount(app); target.remove() } }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
let cleanup: (() => void) | null = null
|
|
70
|
+
afterEach(() => { cleanup?.(); cleanup = null })
|
|
71
|
+
|
|
72
|
+
/** Widths of the rendered data bars, in source order. */
|
|
73
|
+
function barWidths(target: HTMLElement): string[] {
|
|
74
|
+
return [...target.querySelectorAll<HTMLElement>('.sv-grid-cf-bar')].map(
|
|
75
|
+
(el) => el.style.width,
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function nextPage(target: HTMLElement) {
|
|
80
|
+
const next = [...target.querySelectorAll<HTMLButtonElement>('button')].find(
|
|
81
|
+
(b) => /next/i.test(b.getAttribute('aria-label') ?? b.title ?? ''),
|
|
82
|
+
)
|
|
83
|
+
expect(next).toBeDefined()
|
|
84
|
+
next!.click()
|
|
85
|
+
await tick()
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
describe('conditionalStatScope', () => {
|
|
89
|
+
it('keeps the scale steady across pages by default (#61)', async () => {
|
|
90
|
+
const { target, destroy } = mountGrid({})
|
|
91
|
+
cleanup = destroy
|
|
92
|
+
await tick()
|
|
93
|
+
|
|
94
|
+
// Page 1: 0 and 50 against the full 0..100 range.
|
|
95
|
+
expect(barWidths(target)).toEqual(['0%', '50%'])
|
|
96
|
+
await nextPage(target)
|
|
97
|
+
// Page 2: 0 and 100 against the same range.
|
|
98
|
+
expect(barWidths(target)).toEqual(['0%', '100%'])
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
it('rescales per page under scope="visible"', async () => {
|
|
102
|
+
const { target, destroy } = mountGrid({ conditionalStatScope: 'visible' })
|
|
103
|
+
cleanup = destroy
|
|
104
|
+
await tick()
|
|
105
|
+
|
|
106
|
+
// Page 1's own max is 50, so 50 fills the bar.
|
|
107
|
+
expect(barWidths(target)).toEqual(['0%', '100%'])
|
|
108
|
+
await nextPage(target)
|
|
109
|
+
expect(barWidths(target)).toEqual(['0%', '100%'])
|
|
110
|
+
})
|
|
111
|
+
})
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Excel-style filter menu's value checklist is an SvListBox, not a div of
|
|
3
|
+
* checkboxes. Two things that used to bite on a high-cardinality live column
|
|
4
|
+
* (10k distinct symbols on a ticking feed):
|
|
5
|
+
*
|
|
6
|
+
* 1. every distinct value mounted a label + focusable checkbox, so the
|
|
7
|
+
* popover held ~30k nodes and 10k tab stops;
|
|
8
|
+
* 2. the offered values were derived live, so each data tick rebuilt the
|
|
9
|
+
* distinct-value set, re-sorted it and re-keyed the whole list.
|
|
10
|
+
*
|
|
11
|
+
* The list now windows its rows and snapshots its values when the menu opens.
|
|
12
|
+
*/
|
|
13
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
14
|
+
import { mount, unmount } from 'svelte'
|
|
15
|
+
import SvGrid from './SvGrid.svelte'
|
|
16
|
+
import {
|
|
17
|
+
columnFilteringFeature,
|
|
18
|
+
createCoreRowModel,
|
|
19
|
+
createFilteredRowModel,
|
|
20
|
+
createSortedRowModel,
|
|
21
|
+
rowSortingFeature,
|
|
22
|
+
sortFns,
|
|
23
|
+
splitInTokens,
|
|
24
|
+
tableFeatures,
|
|
25
|
+
} from './index'
|
|
26
|
+
import type { ColumnDef, SvGridApi } from './index'
|
|
27
|
+
|
|
28
|
+
type Row = { id: number; symbol: string; team: string }
|
|
29
|
+
const features = tableFeatures({ rowSortingFeature, columnFilteringFeature })
|
|
30
|
+
|
|
31
|
+
const makeRows = (count: number, prefix = 'SYM'): Row[] =>
|
|
32
|
+
Array.from({ length: count }, (_, i) => ({
|
|
33
|
+
id: i + 1,
|
|
34
|
+
symbol: `${prefix}${String(i).padStart(5, '0')}`,
|
|
35
|
+
team: ['A', 'B', 'C'][i % 3]!,
|
|
36
|
+
}))
|
|
37
|
+
|
|
38
|
+
const cols: ColumnDef<typeof features, Row>[] = [
|
|
39
|
+
{ field: 'symbol', header: 'Symbol', width: 200 },
|
|
40
|
+
{ field: 'team', header: 'Team', width: 160 },
|
|
41
|
+
]
|
|
42
|
+
const tick = () => new Promise<void>((r) => setTimeout(r))
|
|
43
|
+
|
|
44
|
+
function mountGrid(data: Row[]) {
|
|
45
|
+
return new Promise<{
|
|
46
|
+
target: HTMLElement
|
|
47
|
+
api: SvGridApi<typeof features, Row>
|
|
48
|
+
setData: (next: Row[]) => void
|
|
49
|
+
destroy: () => void
|
|
50
|
+
}>((res, rej) => {
|
|
51
|
+
const target = document.createElement('div')
|
|
52
|
+
document.body.appendChild(target)
|
|
53
|
+
const props = $state({
|
|
54
|
+
data,
|
|
55
|
+
columns: cols,
|
|
56
|
+
features,
|
|
57
|
+
_rowModels: {
|
|
58
|
+
coreRowModel: createCoreRowModel(),
|
|
59
|
+
filteredRowModel: createFilteredRowModel(),
|
|
60
|
+
sortedRowModel: createSortedRowModel(sortFns),
|
|
61
|
+
},
|
|
62
|
+
rowHeight: 32,
|
|
63
|
+
containerHeight: 400,
|
|
64
|
+
virtualization: true,
|
|
65
|
+
filterMode: 'menu' as const,
|
|
66
|
+
showColumnFilters: true,
|
|
67
|
+
onApiReady(api: SvGridApi<typeof features, Row>) {
|
|
68
|
+
res({
|
|
69
|
+
target,
|
|
70
|
+
api,
|
|
71
|
+
setData: (next: Row[]) => (props.data = next),
|
|
72
|
+
destroy: () => { unmount(app); target.remove() },
|
|
73
|
+
})
|
|
74
|
+
},
|
|
75
|
+
})
|
|
76
|
+
const app = mount(SvGrid, { target, props: props as any })
|
|
77
|
+
queueMicrotask(() => { if (!target.querySelector('[role="grid"]')) rej(new Error('no grid')) })
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Open the funnel popover on the first column and return the menu element. */
|
|
82
|
+
async function openFilterMenu(target: HTMLElement) {
|
|
83
|
+
const btn = target.querySelector('.sv-grid-col-filter-btn') as HTMLButtonElement
|
|
84
|
+
btn.click()
|
|
85
|
+
// GridMenus is a lazy chunk; poll until the popover mounts.
|
|
86
|
+
await vi.waitFor(() => expect(target.querySelector('.sv-grid-filter-menu')).not.toBeNull())
|
|
87
|
+
return target.querySelector('.sv-grid-filter-menu') as HTMLElement
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const optionLabels = (menu: HTMLElement) =>
|
|
91
|
+
Array.from(menu.querySelectorAll('[role="option"]')).map((el) => el.textContent?.trim() ?? '')
|
|
92
|
+
|
|
93
|
+
describe('filter menu value checklist', () => {
|
|
94
|
+
it('windows a high-cardinality column instead of mounting every value', async () => {
|
|
95
|
+
const rows = makeRows(120)
|
|
96
|
+
const { target, destroy } = await mountGrid(rows)
|
|
97
|
+
await tick()
|
|
98
|
+
const menu = await openFilterMenu(target)
|
|
99
|
+
|
|
100
|
+
const list = menu.querySelector('.sv-listbox')
|
|
101
|
+
expect(list).not.toBeNull()
|
|
102
|
+
expect(list!.classList.contains('is-virtual')).toBe(true)
|
|
103
|
+
|
|
104
|
+
const rendered = menu.querySelectorAll('[role="option"]').length
|
|
105
|
+
expect(rendered).toBeGreaterThan(0)
|
|
106
|
+
expect(rendered).toBeLessThan(60)
|
|
107
|
+
|
|
108
|
+
destroy()
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it('is a single tab stop, not one per value', async () => {
|
|
112
|
+
const { target, destroy } = await mountGrid(makeRows(120))
|
|
113
|
+
await tick()
|
|
114
|
+
const menu = await openFilterMenu(target)
|
|
115
|
+
|
|
116
|
+
// Roving tabindex: the listbox root is focusable, its options are not.
|
|
117
|
+
expect(menu.querySelectorAll('.sv-listbox[tabindex="0"]').length).toBe(1)
|
|
118
|
+
expect(menu.querySelectorAll('[role="option"][tabindex]').length).toBe(0)
|
|
119
|
+
// No focusable checkbox per row any more.
|
|
120
|
+
expect(menu.querySelectorAll('.sv-listbox input').length).toBe(0)
|
|
121
|
+
|
|
122
|
+
destroy()
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
it('keeps a short list fully rendered (no fixed-height box)', async () => {
|
|
126
|
+
const { target, destroy } = await mountGrid(makeRows(9))
|
|
127
|
+
await tick()
|
|
128
|
+
const menu = await openFilterMenu(target)
|
|
129
|
+
|
|
130
|
+
const list = menu.querySelector('.sv-listbox')!
|
|
131
|
+
expect(list.classList.contains('is-virtual')).toBe(false)
|
|
132
|
+
expect(menu.querySelectorAll('[role="option"]').length).toBe(9)
|
|
133
|
+
|
|
134
|
+
destroy()
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
it('snapshots the offered values, so a live data tick does not rebuild them', async () => {
|
|
138
|
+
const { target, setData, destroy } = await mountGrid(makeRows(6, 'OLD'))
|
|
139
|
+
await tick()
|
|
140
|
+
const menu = await openFilterMenu(target)
|
|
141
|
+
const before = optionLabels(menu)
|
|
142
|
+
expect(before[0]).toBe('OLD00000')
|
|
143
|
+
|
|
144
|
+
// A streaming grid replaces its row array; the open menu must not re-scan.
|
|
145
|
+
setData(makeRows(6, 'NEW'))
|
|
146
|
+
await tick()
|
|
147
|
+
expect(optionLabels(menu)).toEqual(before)
|
|
148
|
+
|
|
149
|
+
destroy()
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
it('re-reads the values on the next open', async () => {
|
|
153
|
+
const { target, setData, destroy } = await mountGrid(makeRows(6, 'OLD'))
|
|
154
|
+
await tick()
|
|
155
|
+
await openFilterMenu(target)
|
|
156
|
+
setData(makeRows(6, 'NEW'))
|
|
157
|
+
await tick()
|
|
158
|
+
|
|
159
|
+
// Close, then reopen: the snapshot is taken fresh.
|
|
160
|
+
;(target.querySelector('.sv-grid-menu-backdrop') as HTMLElement).click()
|
|
161
|
+
await vi.waitFor(() => expect(target.querySelector('.sv-grid-filter-menu')).toBeNull())
|
|
162
|
+
const reopened = await openFilterMenu(target)
|
|
163
|
+
expect(optionLabels(reopened)[0]).toBe('NEW00000')
|
|
164
|
+
|
|
165
|
+
destroy()
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
it('unchecking a value filters the rows out', async () => {
|
|
169
|
+
const { target, api, destroy } = await mountGrid(makeRows(9))
|
|
170
|
+
await tick()
|
|
171
|
+
const menu = await openFilterMenu(target)
|
|
172
|
+
|
|
173
|
+
const first = menu.querySelector('[role="option"]') as HTMLElement
|
|
174
|
+
expect(first.getAttribute('aria-selected')).toBe('true')
|
|
175
|
+
first.click()
|
|
176
|
+
await tick()
|
|
177
|
+
|
|
178
|
+
expect(first.getAttribute('aria-selected')).toBe('false')
|
|
179
|
+
expect(api.getDisplayedRows().length).toBe(8)
|
|
180
|
+
|
|
181
|
+
destroy()
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
it('an in/notIn box offers a windowed checklist, not a capped datalist', async () => {
|
|
185
|
+
const { target, destroy } = await mountGrid(makeRows(300))
|
|
186
|
+
await tick()
|
|
187
|
+
const menu = await openFilterMenu(target)
|
|
188
|
+
|
|
189
|
+
const op = menu.querySelector('.sv-grid-menu-operator-select') as HTMLSelectElement
|
|
190
|
+
op.value = 'in'
|
|
191
|
+
op.dispatchEvent(new Event('change', { bubbles: true }))
|
|
192
|
+
await tick()
|
|
193
|
+
|
|
194
|
+
expect(menu.querySelector('datalist')).toBeNull()
|
|
195
|
+
const box = menu.querySelector('.sv-grid-menu-condition-value') as HTMLInputElement
|
|
196
|
+
expect(box.getAttribute('list')).toBeNull()
|
|
197
|
+
|
|
198
|
+
box.dispatchEvent(new FocusEvent('focus'))
|
|
199
|
+
await vi.waitFor(() => expect(target.querySelector('.sv-grid-in-suggest')).not.toBeNull())
|
|
200
|
+
const suggest = target.querySelector('.sv-grid-in-suggest') as HTMLElement
|
|
201
|
+
|
|
202
|
+
// Uncapped source list, windowed render.
|
|
203
|
+
expect(suggest.querySelector('.sv-listbox')!.classList.contains('is-virtual')).toBe(true)
|
|
204
|
+
expect(suggest.querySelectorAll('[role="option"]').length).toBeLessThan(60)
|
|
205
|
+
|
|
206
|
+
destroy()
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
it('picking a suggestion replaces the fragment being typed', async () => {
|
|
210
|
+
const { target, destroy } = await mountGrid(makeRows(9))
|
|
211
|
+
await tick()
|
|
212
|
+
const menu = await openFilterMenu(target)
|
|
213
|
+
|
|
214
|
+
const op = menu.querySelector('.sv-grid-menu-operator-select') as HTMLSelectElement
|
|
215
|
+
op.value = 'in'
|
|
216
|
+
op.dispatchEvent(new Event('change', { bubbles: true }))
|
|
217
|
+
await tick()
|
|
218
|
+
|
|
219
|
+
const box = menu.querySelector('.sv-grid-menu-condition-value') as HTMLInputElement
|
|
220
|
+
box.dispatchEvent(new FocusEvent('focus'))
|
|
221
|
+
await vi.waitFor(() => expect(target.querySelector('.sv-grid-in-suggest')).not.toBeNull())
|
|
222
|
+
|
|
223
|
+
// Commit one token, then start typing a second.
|
|
224
|
+
box.value = 'SYM00003, SYM0000'
|
|
225
|
+
box.dispatchEvent(new Event('input', { bubbles: true }))
|
|
226
|
+
await tick()
|
|
227
|
+
|
|
228
|
+
const suggest = target.querySelector('.sv-grid-in-suggest') as HTMLElement
|
|
229
|
+
expect(optionLabels(suggest).length).toBeGreaterThan(1)
|
|
230
|
+
|
|
231
|
+
// Pick another: the fragment is consumed, not left beside it.
|
|
232
|
+
const pick = Array.from(suggest.querySelectorAll('[role="option"]')).find(
|
|
233
|
+
(el) => el.textContent?.trim() === 'SYM00005',
|
|
234
|
+
) as HTMLElement
|
|
235
|
+
pick.click()
|
|
236
|
+
await tick()
|
|
237
|
+
|
|
238
|
+
expect(splitInTokens(box.value).sort()).toEqual(['SYM00003', 'SYM00005'])
|
|
239
|
+
// ...and both read as selected straight away. A value written by the
|
|
240
|
+
// dropdown has no trailing separator, so anything that mistook the last
|
|
241
|
+
// token for a half-typed fragment would show it unchecked.
|
|
242
|
+
const checked = suggest.querySelectorAll('[role="option"][aria-selected="true"]')
|
|
243
|
+
expect(Array.from(checked).map((el) => el.textContent?.trim()).sort()).toEqual([
|
|
244
|
+
'SYM00003',
|
|
245
|
+
'SYM00005',
|
|
246
|
+
])
|
|
247
|
+
|
|
248
|
+
destroy()
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
it('a value whose label contains a comma survives being picked', async () => {
|
|
252
|
+
const rows: Row[] = [
|
|
253
|
+
{ id: 1, symbol: 'Aug 17, 2026', team: 'A' },
|
|
254
|
+
{ id: 2, symbol: '1,234 - 5,678', team: 'B' },
|
|
255
|
+
{ id: 3, symbol: 'plain', team: 'C' },
|
|
256
|
+
]
|
|
257
|
+
const { target, api, destroy } = await mountGrid(rows)
|
|
258
|
+
await tick()
|
|
259
|
+
const menu = await openFilterMenu(target)
|
|
260
|
+
|
|
261
|
+
const op = menu.querySelector('.sv-grid-menu-operator-select') as HTMLSelectElement
|
|
262
|
+
op.value = 'in'
|
|
263
|
+
op.dispatchEvent(new Event('change', { bubbles: true }))
|
|
264
|
+
await tick()
|
|
265
|
+
|
|
266
|
+
const box = menu.querySelector('.sv-grid-menu-condition-value') as HTMLInputElement
|
|
267
|
+
box.dispatchEvent(new FocusEvent('focus'))
|
|
268
|
+
await vi.waitFor(() => expect(target.querySelector('.sv-grid-in-suggest')).not.toBeNull())
|
|
269
|
+
const suggest = target.querySelector('.sv-grid-in-suggest') as HTMLElement
|
|
270
|
+
|
|
271
|
+
const pick = Array.from(suggest.querySelectorAll('[role="option"]')).find(
|
|
272
|
+
(el) => el.textContent?.trim() === 'Aug 17, 2026',
|
|
273
|
+
) as HTMLElement
|
|
274
|
+
pick.click()
|
|
275
|
+
await tick()
|
|
276
|
+
|
|
277
|
+
// The comma inside the value must not split it into two filter tokens.
|
|
278
|
+
expect(splitInTokens(box.value)).toEqual(['Aug 17, 2026'])
|
|
279
|
+
expect(api.getDisplayedRows().length).toBe(1)
|
|
280
|
+
|
|
281
|
+
destroy()
|
|
282
|
+
})
|
|
283
|
+
|
|
284
|
+
it('a search-hidden value stays checked when another is toggled', async () => {
|
|
285
|
+
const { target, api, destroy } = await mountGrid(makeRows(9))
|
|
286
|
+
await tick()
|
|
287
|
+
const menu = await openFilterMenu(target)
|
|
288
|
+
|
|
289
|
+
// Uncheck SYM00000 while everything is visible.
|
|
290
|
+
;(menu.querySelector('[role="option"]') as HTMLElement).click()
|
|
291
|
+
await tick()
|
|
292
|
+
expect(api.getDisplayedRows().length).toBe(8)
|
|
293
|
+
|
|
294
|
+
// Narrow to a single value, uncheck it too. The first exclusion must
|
|
295
|
+
// survive - it is only hidden by the search box, not deselected.
|
|
296
|
+
const search = menu.querySelector('.sv-grid-menu-search') as HTMLInputElement
|
|
297
|
+
search.value = 'SYM00005'
|
|
298
|
+
search.dispatchEvent(new Event('input', { bubbles: true }))
|
|
299
|
+
await tick()
|
|
300
|
+
expect(menu.querySelectorAll('[role="option"]').length).toBe(1)
|
|
301
|
+
;(menu.querySelector('[role="option"]') as HTMLElement).click()
|
|
302
|
+
await tick()
|
|
303
|
+
|
|
304
|
+
expect(api.getDisplayedRows().length).toBe(7)
|
|
305
|
+
|
|
306
|
+
destroy()
|
|
307
|
+
})
|
|
308
|
+
})
|
|
@@ -79,7 +79,9 @@ describe('SvGrid filter menu scrolling', () => {
|
|
|
79
79
|
await tick()
|
|
80
80
|
expect(target.querySelector('.sv-grid-filter-menu')).not.toBeNull()
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
// The value checklist is an SvListBox; under the virtualization threshold
|
|
83
|
+
// it scrolls natively, so it still emits the scroll that must be ignored.
|
|
84
|
+
const facets = menu.querySelector('.sv-listbox')
|
|
83
85
|
expect(facets).not.toBeNull()
|
|
84
86
|
facets!.dispatchEvent(new Event('scroll'))
|
|
85
87
|
await tick()
|