@olenbetong/appframe-ds 1.5.0 → 1.6.0
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/CHANGELOG.md +16 -0
- package/package.json +17 -16
- package/src/AfLookup/Lookup.css +20 -3
- package/src/AfLookup/LookupCombobox.css +23 -26
- package/src/AfLookup/LookupCombobox.tsx +62 -26
- package/src/AfLookup/LookupGrid.css +96 -3
- package/src/AfLookup/LookupGrid.test.tsx +142 -0
- package/src/AfLookup/LookupGrid.tsx +214 -14
- package/src/autocomplete/Autocomplete.css +2 -5
- package/src/binding/BoundNumberInput.tsx +42 -0
- package/src/binding/index.ts +1 -0
- package/src/input/InputAdornments.css +1 -5
- package/src/input/NumberInput.css +9 -0
- package/src/input/NumberInput.test.tsx +212 -0
- package/src/input/NumberInput.tsx +268 -0
- package/src/input/index.ts +2 -0
- package/src/input/numberFormat.test.ts +79 -0
- package/src/input/numberFormat.ts +94 -0
- package/src/progress/LinearProgress.css +39 -11
- package/src/progress/LinearProgress.tsx +3 -1
- package/src/test/setup.ts +15 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @olenbetong/appframe-ds
|
|
2
2
|
|
|
3
|
+
## 1.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 3cd79b7: New `NumberInput` and `BoundNumberInput`: a number edited as text and shown in the user's culture (`culture` prop, defaulting to `af.userSession.culture` and to `nb-NO` outside a session), with stepper buttons and arrow keys that round to `decimalDigits`, `min`/`max` clamping, and the whole value selected on focus. Typed text is parsed the same way whatever the culture: both `,` and `.` are the decimal separator and whitespace the only thousands separator, so a Norwegian user typing `1.5` gets 1,5. It is built on `InputAdornments` inside a Designsystemet `Field`, so `label`, `description` and `error` work as on `Textfield`. `BoundNumberInput` binds it to a number field through `useField`. The `formatNumber`, `parseNumber` and `getDefaultCulture` helpers behind it are exported too.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- dc1945b: `LinearProgress` indeterminate animation is Material Design's again: two bars chase each other across the track in a 2.1 s cycle, the first growing from 35% to 90% of the track, the second starting 1.15 s later with a sharper easing and shrinking to a sliver, both holding off-screen from 60% of the cycle. The previous single bar never paused and barely changed width, so it read as a bar moving at varying speed. The bars are still moved with transforms, so the animation stays on the compositor. The lookup popup's loading bar now uses this component as an overlay instead of a bar of its own.
|
|
12
|
+
- 96f6bb3: The lookup popup (`AfLookup`, `AfLookupEdit`) is laid out the conventional way: the search field on top, where the focus is, the list filling the middle, and Clear and Close as a footer. On desktop the popup renders at `data-size="sm"`, so the search field, the rows and the buttons are compact next to the field; the mobile bottom sheet keeps `md` for touch. List rows now get a subtle divider plus the hover and active states from the component, so a `renderItem` only lays out its content. The dialog padding is tightened, and on mobile the bottom sheet really sits on the bottom edge of the viewport: the user agent's modal max-height and auto margins had left a gap under it, and the height now follows the browser chrome (`dvh`).
|
|
13
|
+
|
|
14
|
+
The grid variant's header now follows the rows when the columns are wider than the popup and the list scrolls sideways; before, only the rows moved. Columns can be resized by dragging the handle at the end of a header cell (double click restores the configured width), and the header row is given the list's inner width so `1fr` columns line up with the rows whether or not there is a vertical scrollbar. Clicking a header sorts by that column (again to flip the direction) through the data object's sort order, so the server sorts and every page follows; a column sets `sortable: false` to opt out. Truncated cell text now ends in an ellipsis; the cell is a flex container, which never applied one to its own text. The loading bar is laid over the top edge of the list instead of being inserted above it, so the rows no longer jump by its height while a search runs.
|
|
15
|
+
|
|
16
|
+
- 3cd79b7: `InputAdornments` and `Autocomplete` drop their `data-size="xs"` rules. Designsystemet components come in `sm`, `md` and `lg` only (`xs` and `xl` are typography sizes), so the rules never matched a working size and `xs` rendered as `md`.
|
|
17
|
+
- 56fb84d: The lookup dialog flips above or to the left of its input when there is no room below or to the right, instead of opening outside the viewport.
|
|
18
|
+
|
|
3
19
|
## 1.5.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@olenbetong/appframe-ds",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Components that bind Designsystemet components to Appframe data objects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./es/index.d.ts",
|
|
@@ -62,37 +62,38 @@
|
|
|
62
62
|
"dependencies": {
|
|
63
63
|
"@atlaskit/pragmatic-drag-and-drop": "4.0.0",
|
|
64
64
|
"@atlaskit/pragmatic-drag-and-drop-hitbox": "3.0.0",
|
|
65
|
-
"@base-ui/react": "1.
|
|
65
|
+
"@base-ui/react": "1.9.0",
|
|
66
66
|
"@olenbetong/appframe-core": "^2.15.2",
|
|
67
|
-
"@olenbetong/appframe-data": "^1.8.
|
|
68
|
-
"@olenbetong/appframe-react": "^2.2.
|
|
67
|
+
"@olenbetong/appframe-data": "^1.8.3",
|
|
68
|
+
"@olenbetong/appframe-react": "^2.2.8",
|
|
69
69
|
"clsx": "^2.1.1",
|
|
70
|
-
"dockview-react": "8.
|
|
70
|
+
"dockview-react": "8.6.1",
|
|
71
71
|
"localforage": "^1.10.0",
|
|
72
72
|
"mitt": "^3.0.1",
|
|
73
|
-
"react": "19.3.
|
|
74
|
-
"react-dom": "19.3.
|
|
75
|
-
"react-window": "2.
|
|
76
|
-
"temporal-polyfill": "1.0.
|
|
73
|
+
"react": "19.3.1",
|
|
74
|
+
"react-dom": "19.3.1",
|
|
75
|
+
"react-window": "2.5.0",
|
|
76
|
+
"temporal-polyfill": "1.0.6"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@digdir/designsystemet-react": "1.23.0",
|
|
80
80
|
"@emotion/react": "^11.14.0",
|
|
81
81
|
"@emotion/styled": "^11.14.1",
|
|
82
|
-
"@mui/material": "9.
|
|
83
|
-
"@mui/x-data-grid-premium": "8.29.
|
|
82
|
+
"@mui/material": "9.5.0",
|
|
83
|
+
"@mui/x-data-grid-premium": "8.29.5",
|
|
84
84
|
"@mui/x-license": "8.29.3",
|
|
85
|
-
"@navikt/aksel-icons": "8.
|
|
85
|
+
"@navikt/aksel-icons": "8.19.2",
|
|
86
86
|
"@testing-library/dom": "^10.4.2",
|
|
87
87
|
"@testing-library/jest-dom": "^7.0.1",
|
|
88
88
|
"@testing-library/react": "16.3.3",
|
|
89
|
-
"@testing-library/user-event": "^14.6.
|
|
89
|
+
"@testing-library/user-event": "^14.6.8",
|
|
90
90
|
"@types/react": "19.3.0",
|
|
91
91
|
"@types/react-dom": "19.3.0",
|
|
92
|
-
"happy-dom": "
|
|
92
|
+
"happy-dom": "21.0.4",
|
|
93
93
|
"react-error-boundary": "6.1.6",
|
|
94
|
-
"react-router": "8.
|
|
95
|
-
"typescript": "7.0.2"
|
|
94
|
+
"react-router": "8.5.0",
|
|
95
|
+
"typescript": "7.0.2",
|
|
96
|
+
"vitest": "5.0.5"
|
|
96
97
|
},
|
|
97
98
|
"scripts": {
|
|
98
99
|
"build": "pnpm run build:tsc && pnpm test && pnpm run build:css",
|
package/src/AfLookup/Lookup.css
CHANGED
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
.ObLookup-dialog {
|
|
26
26
|
border: 0;
|
|
27
27
|
margin-block-start: 0;
|
|
28
|
-
|
|
28
|
+
/* Tight: the search field sits at the top edge and the footer buttons carry their own padding */
|
|
29
|
+
padding: var(--ds-size-3, 0.75rem) var(--ds-size-2, 0.5rem) var(--ds-size-1, 0.25rem);
|
|
29
30
|
overflow: hidden;
|
|
30
31
|
|
|
31
32
|
background-color: var(--ds-color-neutral-background-tinted);
|
|
@@ -54,11 +55,19 @@
|
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
@media (width < 768px) {
|
|
57
|
-
|
|
58
|
+
/*
|
|
59
|
+
* A bottom sheet. The UA stylesheet caps a modal dialog at calc(100% - 6px - 2em) and
|
|
60
|
+
* centres it with auto margins, which left a gap under the sheet; drop both so the box
|
|
61
|
+
* really sits on the bottom edge. dvh follows the mobile browser chrome.
|
|
62
|
+
*/
|
|
63
|
+
inset: auto 0.5rem 0;
|
|
64
|
+
margin: 0;
|
|
65
|
+
max-height: none;
|
|
58
66
|
|
|
59
67
|
border-radius: 1rem 1rem 0 0;
|
|
60
68
|
height: 90vh;
|
|
61
|
-
|
|
69
|
+
height: 90dvh;
|
|
70
|
+
width: auto;
|
|
62
71
|
max-width: 100vw;
|
|
63
72
|
transform: translateY(100%);
|
|
64
73
|
z-index: 1500;
|
|
@@ -112,6 +121,14 @@
|
|
|
112
121
|
inset-inline-start: anchor(left);
|
|
113
122
|
inset-inline-end: unset;
|
|
114
123
|
|
|
124
|
+
/* Below and to the right of the input when there is room; otherwise above it, or
|
|
125
|
+
aligned to its right edge, so an input near the bottom or the right edge of the
|
|
126
|
+
viewport still gets a visible dialog. */
|
|
127
|
+
position-try-fallbacks:
|
|
128
|
+
flip-block,
|
|
129
|
+
flip-inline,
|
|
130
|
+
flip-block flip-inline;
|
|
131
|
+
|
|
115
132
|
translate: unset;
|
|
116
133
|
transform-origin: top left;
|
|
117
134
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
/* Search on top (it has the focus), the list filling the middle, Clear and Close as a footer */
|
|
1
2
|
.ObCombobox-root {
|
|
2
3
|
height: 100%;
|
|
3
4
|
display: grid;
|
|
4
|
-
grid-template-rows: min-content
|
|
5
|
-
gap: 0.5rem;
|
|
5
|
+
grid-template-rows: auto 1fr min-content;
|
|
6
|
+
gap: var(--ds-size-2, 0.5rem);
|
|
6
7
|
|
|
7
8
|
overscroll-behavior: contain;
|
|
8
9
|
}
|
|
@@ -12,7 +13,13 @@
|
|
|
12
13
|
justify-content: space-between;
|
|
13
14
|
}
|
|
14
15
|
|
|
16
|
+
/* Close stays at the end when there is no Clear */
|
|
17
|
+
.ObCombobox-close {
|
|
18
|
+
margin-inline-start: auto;
|
|
19
|
+
}
|
|
20
|
+
|
|
15
21
|
.ObCombobox-listWrap {
|
|
22
|
+
position: relative;
|
|
16
23
|
overflow: hidden;
|
|
17
24
|
min-height: 0;
|
|
18
25
|
border: 1px solid var(--ds-color-neutral-border-subtle);
|
|
@@ -33,8 +40,15 @@
|
|
|
33
40
|
background-color: var(--ds-color-neutral-background-default);
|
|
34
41
|
}
|
|
35
42
|
|
|
43
|
+
/*
|
|
44
|
+
* The rows are rendered by the consumer; the divider and the hover and active
|
|
45
|
+
* states come from here, so a row only has to lay out its content.
|
|
46
|
+
*/
|
|
36
47
|
.ObCombobox-listItem {
|
|
37
48
|
cursor: pointer;
|
|
49
|
+
box-sizing: border-box;
|
|
50
|
+
list-style: none;
|
|
51
|
+
border-bottom: 1px solid var(--ds-color-neutral-border-subtle);
|
|
38
52
|
|
|
39
53
|
&.active {
|
|
40
54
|
background-color: var(--ds-color-neutral-surface-active);
|
|
@@ -45,28 +59,11 @@
|
|
|
45
59
|
}
|
|
46
60
|
}
|
|
47
61
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
.ObCombobox-progress-bar {
|
|
56
|
-
position: absolute;
|
|
57
|
-
top: 0;
|
|
58
|
-
left: -100%;
|
|
59
|
-
height: 100%;
|
|
60
|
-
width: 50%;
|
|
61
|
-
background-color: var(--ds-color-brand-base-default);
|
|
62
|
-
animation: ObCombobox-progress-anim 1.5s ease-in-out infinite;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
@keyframes ObCombobox-progress-anim {
|
|
66
|
-
0% {
|
|
67
|
-
left: -100%;
|
|
68
|
-
}
|
|
69
|
-
100% {
|
|
70
|
-
left: 200%;
|
|
71
|
-
}
|
|
62
|
+
/*
|
|
63
|
+
* The loading bar is a `LinearProgress overlay`: a zero-height wrapper at the
|
|
64
|
+
* top of the list wrap, with the bar laid over the first rows, so nothing moves
|
|
65
|
+
* when it appears. The track is square here so it hugs the list border.
|
|
66
|
+
*/
|
|
67
|
+
.ObCombobox-progress .ObLinearProgress-root {
|
|
68
|
+
border-radius: 0;
|
|
72
69
|
}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import "./LookupCombobox.css";
|
|
2
2
|
|
|
3
3
|
import { Button, Textfield } from "@digdir/designsystemet-react";
|
|
4
|
-
import type
|
|
4
|
+
import { type DataObject, SortOrder } from "@olenbetong/appframe-data";
|
|
5
5
|
import { type LookupColumn, useComboboxData } from "@olenbetong/appframe-react";
|
|
6
6
|
|
|
7
7
|
import clsx from "clsx";
|
|
8
|
-
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
8
|
+
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
9
9
|
import { List, type RowComponentProps, useDynamicRowHeight, useListRef } from "react-window";
|
|
10
10
|
|
|
11
|
-
import { LookupGrid } from "./LookupGrid.js";
|
|
11
|
+
import { LookupGrid, type LookupGridSort } from "./LookupGrid.js";
|
|
12
12
|
import { getLocalizedString } from "../i18n.js";
|
|
13
|
+
import { LinearProgress } from "../progress/LinearProgress.js";
|
|
13
14
|
|
|
14
15
|
export interface LookupComboboxBaseProps<T extends Record<string, unknown>> {
|
|
15
16
|
nullable?: boolean;
|
|
@@ -126,6 +127,27 @@ export function LookupCombobox<T extends Record<string, unknown>>(props: LookupC
|
|
|
126
127
|
onChange,
|
|
127
128
|
});
|
|
128
129
|
|
|
130
|
+
// Sorting goes through the data object, so it is done by the server and covers every page.
|
|
131
|
+
// Like the search filter, it stays on the data object after the popup closes.
|
|
132
|
+
let [sortOrder, setSortOrder] = useState<Record<string, SortOrder>[]>(
|
|
133
|
+
() => (dataObject.getParameter("sortOrder") as Record<string, SortOrder>[] | undefined) ?? [],
|
|
134
|
+
);
|
|
135
|
+
let sort = useMemo<LookupGridSort | undefined>(() => {
|
|
136
|
+
let [first] = sortOrder;
|
|
137
|
+
let entry = first && Object.entries(first)[0];
|
|
138
|
+
if (!entry) return undefined;
|
|
139
|
+
let [field, direction] = entry;
|
|
140
|
+
return { field, direction: String(direction).startsWith("desc") ? "desc" : "asc" };
|
|
141
|
+
}, [sortOrder]);
|
|
142
|
+
|
|
143
|
+
function handleSort(field: string) {
|
|
144
|
+
let direction = sort?.field === field && sort.direction === "asc" ? SortOrder.Desc : SortOrder.Asc;
|
|
145
|
+
let next = [{ [field]: direction }];
|
|
146
|
+
setSortOrder(next);
|
|
147
|
+
dataObject.setParameter("sortOrder", next as never);
|
|
148
|
+
dataObject.refreshDataSource();
|
|
149
|
+
}
|
|
150
|
+
|
|
129
151
|
let wrapperRef = useRef<HTMLDivElement>(null);
|
|
130
152
|
let [height, setHeight] = useState<number>(0);
|
|
131
153
|
|
|
@@ -161,26 +183,15 @@ export function LookupCombobox<T extends Record<string, unknown>>(props: LookupC
|
|
|
161
183
|
return (
|
|
162
184
|
// oxlint-disable-next-line jsx-a11y/click-events-have-key-events -- element is not interactive, click is used to prevent dialog close
|
|
163
185
|
// oxlint-disable-next-line jsx-a11y/no-static-element-interactions -- element is not interactive, click is used to prevent dialog close
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}}
|
|
174
|
-
>
|
|
175
|
-
{getLocalizedString("Clear")}
|
|
176
|
-
</Button>
|
|
177
|
-
)}
|
|
178
|
-
{onClose && (
|
|
179
|
-
<Button data-size={isDesktop ? "sm" : "md"} variant="tertiary" className="ObCombobox-close" onClick={onClose}>
|
|
180
|
-
{getLocalizedString("Close")}
|
|
181
|
-
</Button>
|
|
182
|
-
)}
|
|
183
|
-
</div>
|
|
186
|
+
// Compact on desktop, where the popup is a small dialog next to the field; the mobile
|
|
187
|
+
// bottom sheet keeps the default size for touch. The size cascades to the search field,
|
|
188
|
+
// the rows and the buttons.
|
|
189
|
+
<div
|
|
190
|
+
className="ObCombobox-root"
|
|
191
|
+
id={id}
|
|
192
|
+
data-size={isDesktop ? "sm" : "md"}
|
|
193
|
+
onClick={(evt) => evt.stopPropagation()}
|
|
194
|
+
>
|
|
184
195
|
<Textfield
|
|
185
196
|
type="search"
|
|
186
197
|
className="ObCombobox-input"
|
|
@@ -193,9 +204,12 @@ export function LookupCombobox<T extends Record<string, unknown>>(props: LookupC
|
|
|
193
204
|
/>
|
|
194
205
|
<div className="ObCombobox-listWrap" ref={wrapperRef}>
|
|
195
206
|
{loading && (
|
|
196
|
-
<
|
|
197
|
-
|
|
198
|
-
|
|
207
|
+
<LinearProgress
|
|
208
|
+
overlay
|
|
209
|
+
className="ObCombobox-progress"
|
|
210
|
+
data-size="xs"
|
|
211
|
+
aria-label={getLocalizedString("Loading")}
|
|
212
|
+
/>
|
|
199
213
|
)}
|
|
200
214
|
{height > 0 &&
|
|
201
215
|
(columns ? (
|
|
@@ -208,6 +222,8 @@ export function LookupCombobox<T extends Record<string, unknown>>(props: LookupC
|
|
|
208
222
|
getItemId={getItemId}
|
|
209
223
|
isItemSelected={isItemSelected}
|
|
210
224
|
onSelectItem={handleSelectItem}
|
|
225
|
+
sort={sort}
|
|
226
|
+
onSort={handleSort}
|
|
211
227
|
/>
|
|
212
228
|
) : (
|
|
213
229
|
<div className="ObCombobox-list" role="listbox">
|
|
@@ -232,6 +248,26 @@ export function LookupCombobox<T extends Record<string, unknown>>(props: LookupC
|
|
|
232
248
|
</div>
|
|
233
249
|
))}
|
|
234
250
|
</div>
|
|
251
|
+
{(nullable || onClose) && (
|
|
252
|
+
<div className="ObCombobox-actions">
|
|
253
|
+
{nullable && (
|
|
254
|
+
<Button
|
|
255
|
+
className="ObCombobox-clear"
|
|
256
|
+
variant="tertiary"
|
|
257
|
+
onClick={() => {
|
|
258
|
+
onChange?.(null);
|
|
259
|
+
}}
|
|
260
|
+
>
|
|
261
|
+
{getLocalizedString("Clear")}
|
|
262
|
+
</Button>
|
|
263
|
+
)}
|
|
264
|
+
{onClose && (
|
|
265
|
+
<Button variant="tertiary" className="ObCombobox-close" onClick={onClose}>
|
|
266
|
+
{getLocalizedString("Close")}
|
|
267
|
+
</Button>
|
|
268
|
+
)}
|
|
269
|
+
</div>
|
|
270
|
+
)}
|
|
235
271
|
</div>
|
|
236
272
|
);
|
|
237
273
|
}
|
|
@@ -5,25 +5,111 @@
|
|
|
5
5
|
border: 1px solid var(--ds-color-neutral-border-subtle);
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
/* No text selection while a column is being dragged */
|
|
9
|
+
.ObLookupGrid-root[data-resizing] {
|
|
10
|
+
user-select: none;
|
|
11
|
+
cursor: col-resize;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
* The header does not scroll itself: the list is the only scroll container, and the header
|
|
16
|
+
* row inside is moved sideways with a transform to follow it.
|
|
17
|
+
*/
|
|
8
18
|
.ObLookupGrid-header {
|
|
9
|
-
display: grid;
|
|
10
19
|
height: 40px;
|
|
11
|
-
|
|
20
|
+
overflow: hidden;
|
|
12
21
|
border-bottom: 1px solid var(--ds-color-neutral-border-default);
|
|
13
22
|
background-color: var(--ds-color-neutral-background-tinted);
|
|
14
23
|
font-weight: 600;
|
|
15
24
|
}
|
|
16
25
|
|
|
26
|
+
.ObLookupGrid-headerRow {
|
|
27
|
+
display: grid;
|
|
28
|
+
align-items: center;
|
|
29
|
+
height: 100%;
|
|
30
|
+
box-sizing: border-box;
|
|
31
|
+
}
|
|
32
|
+
|
|
17
33
|
.ObLookupGrid-headerCell {
|
|
34
|
+
position: relative;
|
|
35
|
+
display: flex;
|
|
36
|
+
align-items: center;
|
|
37
|
+
height: 100%;
|
|
18
38
|
padding: 0 8px;
|
|
19
39
|
overflow: hidden;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.ObLookupGrid-headerText {
|
|
43
|
+
overflow: hidden;
|
|
20
44
|
text-overflow: ellipsis;
|
|
21
45
|
white-space: nowrap;
|
|
22
46
|
}
|
|
23
47
|
|
|
48
|
+
/* A sortable header: the whole cell text is the button, the arrow shows on hover and when sorted */
|
|
49
|
+
.ObLookupGrid-sortButton {
|
|
50
|
+
display: flex;
|
|
51
|
+
align-items: center;
|
|
52
|
+
gap: var(--ds-size-1, 0.25rem);
|
|
53
|
+
min-width: 0;
|
|
54
|
+
max-width: 100%;
|
|
55
|
+
padding: 0;
|
|
56
|
+
border: 0;
|
|
57
|
+
background: none;
|
|
58
|
+
color: inherit;
|
|
59
|
+
font: inherit;
|
|
60
|
+
cursor: pointer;
|
|
61
|
+
text-align: start;
|
|
62
|
+
|
|
63
|
+
.ObLookupGrid-sortIcon {
|
|
64
|
+
flex-shrink: 0;
|
|
65
|
+
font-size: 1.125em;
|
|
66
|
+
opacity: 0;
|
|
67
|
+
transition: opacity 0.15s ease-out;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
&:hover .ObLookupGrid-sortIcon {
|
|
71
|
+
opacity: 0.5;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
&.sorted .ObLookupGrid-sortIcon {
|
|
75
|
+
opacity: 1;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* The drag handle: a wide hit area at the end of the cell with a thin line drawn in it */
|
|
80
|
+
.ObLookupGrid-resizer {
|
|
81
|
+
position: absolute;
|
|
82
|
+
inset-block: 0;
|
|
83
|
+
inset-inline-end: 0;
|
|
84
|
+
width: 9px;
|
|
85
|
+
cursor: col-resize;
|
|
86
|
+
touch-action: none;
|
|
87
|
+
|
|
88
|
+
&::after {
|
|
89
|
+
content: "";
|
|
90
|
+
position: absolute;
|
|
91
|
+
inset-block: 25%;
|
|
92
|
+
inset-inline-end: 4px;
|
|
93
|
+
width: 1px;
|
|
94
|
+
background-color: var(--ds-color-neutral-border-default);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
&:hover::after {
|
|
98
|
+
inset-block: 15%;
|
|
99
|
+
width: 2px;
|
|
100
|
+
background-color: var(--ds-color-neutral-border-strong);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/* Keeps the client width stable whether or not there are enough rows for a scrollbar */
|
|
105
|
+
.ObLookupGrid-list {
|
|
106
|
+
scrollbar-gutter: stable;
|
|
107
|
+
}
|
|
108
|
+
|
|
24
109
|
.ObLookupGrid-row {
|
|
25
110
|
display: grid;
|
|
26
111
|
align-items: center;
|
|
112
|
+
box-sizing: border-box;
|
|
27
113
|
cursor: pointer;
|
|
28
114
|
border-bottom: 1px solid var(--ds-color-neutral-border-subtle);
|
|
29
115
|
|
|
@@ -42,7 +128,6 @@
|
|
|
42
128
|
display: flex;
|
|
43
129
|
align-items: center;
|
|
44
130
|
overflow: hidden;
|
|
45
|
-
text-overflow: ellipsis;
|
|
46
131
|
white-space: nowrap;
|
|
47
132
|
|
|
48
133
|
&.active {
|
|
@@ -50,3 +135,11 @@
|
|
|
50
135
|
outline-offset: -2px;
|
|
51
136
|
}
|
|
52
137
|
}
|
|
138
|
+
|
|
139
|
+
/* text-overflow does not apply to text directly inside a flex container, so it sits on this span */
|
|
140
|
+
.ObLookupGrid-cellText {
|
|
141
|
+
min-width: 0;
|
|
142
|
+
overflow: hidden;
|
|
143
|
+
text-overflow: ellipsis;
|
|
144
|
+
white-space: nowrap;
|
|
145
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import type { LookupColumn } from "@olenbetong/appframe-react";
|
|
2
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
3
|
+
import { beforeAll, describe, expect, it, vi } from "vitest";
|
|
4
|
+
|
|
5
|
+
import { LookupGrid } from "./LookupGrid.js";
|
|
6
|
+
|
|
7
|
+
type Row = { PrimKey: string; Name: string; Code: string };
|
|
8
|
+
|
|
9
|
+
const COLUMNS: LookupColumn<Row>[] = [
|
|
10
|
+
{ field: "Code", headerName: "Code", width: 100 },
|
|
11
|
+
{ field: "Name", headerName: "Name" },
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
const DATA: Row[] = [
|
|
15
|
+
{ PrimKey: "1", Code: "A", Name: "Alpha" },
|
|
16
|
+
{ PrimKey: "2", Code: "B", Name: "Beta" },
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
function renderGrid(props: Partial<React.ComponentProps<typeof LookupGrid<Row>>> = {}) {
|
|
20
|
+
return render(
|
|
21
|
+
<LookupGrid<Row>
|
|
22
|
+
columns={COLUMNS}
|
|
23
|
+
data={DATA}
|
|
24
|
+
height={300}
|
|
25
|
+
currentIndex={0}
|
|
26
|
+
currentColumn={0}
|
|
27
|
+
getItemId={(item) => item?.PrimKey}
|
|
28
|
+
onSelectItem={() => undefined}
|
|
29
|
+
{...props}
|
|
30
|
+
/>,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function headerRow() {
|
|
35
|
+
return screen.getByRole("grid").querySelector(".ObLookupGrid-headerRow") as HTMLElement;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
beforeAll(() => {
|
|
39
|
+
// happy-dom has no pointer capture; the handle only checks that it holds it during a drag
|
|
40
|
+
let captured = new WeakMap<Element, number>();
|
|
41
|
+
Element.prototype.setPointerCapture = function (id: number) {
|
|
42
|
+
captured.set(this, id);
|
|
43
|
+
};
|
|
44
|
+
Element.prototype.hasPointerCapture = function (id: number) {
|
|
45
|
+
return captured.get(this) === id;
|
|
46
|
+
};
|
|
47
|
+
Element.prototype.releasePointerCapture = function () {
|
|
48
|
+
captured.delete(this);
|
|
49
|
+
};
|
|
50
|
+
if (typeof ResizeObserver === "undefined") {
|
|
51
|
+
globalThis.ResizeObserver = class {
|
|
52
|
+
observe() {}
|
|
53
|
+
unobserve() {}
|
|
54
|
+
disconnect() {}
|
|
55
|
+
} as never;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe("LookupGrid", () => {
|
|
60
|
+
it("lays the header out with the configured column tracks", () => {
|
|
61
|
+
renderGrid();
|
|
62
|
+
|
|
63
|
+
expect(headerRow().style.gridTemplateColumns).toBe("100px minmax(80px, 1fr)");
|
|
64
|
+
expect(headerRow().style.minWidth).toBe("180px");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("moves the header sideways with the list", () => {
|
|
68
|
+
renderGrid();
|
|
69
|
+
|
|
70
|
+
let list = screen.getByRole("rowgroup");
|
|
71
|
+
list.scrollLeft = 37;
|
|
72
|
+
fireEvent.scroll(list);
|
|
73
|
+
|
|
74
|
+
expect(headerRow().style.transform).toBe("translateX(-37px)");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("resizes a column by dragging its handle, and resets it on double click", () => {
|
|
78
|
+
renderGrid();
|
|
79
|
+
|
|
80
|
+
let [handle] = screen.getAllByRole("separator", { name: "Resize column" });
|
|
81
|
+
let cell = handle.parentElement as HTMLElement;
|
|
82
|
+
vi.spyOn(cell, "getBoundingClientRect").mockReturnValue({ width: 100 } as DOMRect);
|
|
83
|
+
|
|
84
|
+
fireEvent.pointerDown(handle, { button: 0, pointerId: 1, clientX: 200 });
|
|
85
|
+
fireEvent.pointerMove(handle, { pointerId: 1, clientX: 250 });
|
|
86
|
+
expect(headerRow().style.gridTemplateColumns).toBe("150px minmax(80px, 1fr)");
|
|
87
|
+
expect(headerRow().style.minWidth).toBe("230px");
|
|
88
|
+
|
|
89
|
+
fireEvent.pointerMove(handle, { pointerId: 1, clientX: 0 });
|
|
90
|
+
expect(headerRow().style.gridTemplateColumns).toBe("80px minmax(80px, 1fr)");
|
|
91
|
+
|
|
92
|
+
fireEvent.pointerUp(handle, { pointerId: 1, clientX: 0 });
|
|
93
|
+
expect(screen.getByRole("grid")).not.toHaveAttribute("data-resizing");
|
|
94
|
+
|
|
95
|
+
fireEvent.doubleClick(handle);
|
|
96
|
+
expect(headerRow().style.gridTemplateColumns).toBe("100px minmax(80px, 1fr)");
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("renders plain headers when there is no sort handler", () => {
|
|
100
|
+
renderGrid();
|
|
101
|
+
|
|
102
|
+
expect(screen.queryByRole("button", { name: "Code" })).toBeNull();
|
|
103
|
+
expect(screen.getByRole("columnheader", { name: /^Code/ })).not.toHaveAttribute("aria-sort");
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("sorts on a header click, marks the sorted column and keeps the focus where it is", () => {
|
|
107
|
+
let onSort = vi.fn();
|
|
108
|
+
renderGrid({ onSort, sort: { field: "Name", direction: "desc" } });
|
|
109
|
+
|
|
110
|
+
expect(screen.getByRole("columnheader", { name: /^Name/ })).toHaveAttribute("aria-sort", "descending");
|
|
111
|
+
expect(screen.getByRole("columnheader", { name: /^Code/ })).not.toHaveAttribute("aria-sort");
|
|
112
|
+
|
|
113
|
+
let button = screen.getByRole("button", { name: "Code" });
|
|
114
|
+
let mouseDown = fireEvent.mouseDown(button);
|
|
115
|
+
expect(mouseDown).toBe(false);
|
|
116
|
+
|
|
117
|
+
fireEvent.click(button);
|
|
118
|
+
expect(onSort).toHaveBeenCalledWith("Code");
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("leaves a column marked sortable: false as plain text", () => {
|
|
122
|
+
renderGrid({
|
|
123
|
+
onSort: vi.fn(),
|
|
124
|
+
columns: [
|
|
125
|
+
{ field: "Code", headerName: "Code", sortable: false },
|
|
126
|
+
{ field: "Name", headerName: "Name" },
|
|
127
|
+
],
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
expect(screen.queryByRole("button", { name: "Code" })).toBeNull();
|
|
131
|
+
expect(screen.getByRole("button", { name: "Name" })).toBeInTheDocument();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("ignores moves that are not part of a drag", () => {
|
|
135
|
+
renderGrid();
|
|
136
|
+
|
|
137
|
+
let [handle] = screen.getAllByRole("separator", { name: "Resize column" });
|
|
138
|
+
fireEvent.pointerMove(handle, { pointerId: 1, clientX: 250 });
|
|
139
|
+
|
|
140
|
+
expect(headerRow().style.gridTemplateColumns).toBe("100px minmax(80px, 1fr)");
|
|
141
|
+
});
|
|
142
|
+
});
|