@terpjs/react-core 0.43.0 → 0.44.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/README.md +11 -5
- package/package.json +2 -2
- package/src/layout.tsx +6 -4
- package/src/locale.test.tsx +34 -0
- package/src/locale.tsx +9 -3
- package/src/styles.test.ts +4 -4
- package/src/styles.ts +12 -3
- package/src/typography.tsx +2 -1
- package/src/ui/DatePicker.test.tsx +106 -0
- package/src/ui/DatePicker.tsx +47 -11
- package/src/ui/Input.tsx +5 -4
- package/src/uiText.tsx +6 -0
package/README.md
CHANGED
|
@@ -218,10 +218,10 @@ marker, counted by the escape-hatch budget.
|
|
|
218
218
|
| Export | Use |
|
|
219
219
|
|---|---|
|
|
220
220
|
| `Button` | Token-styled command: `variant` (primary / secondary / danger / ghost), `size` (sm / md / lg, composing with density), `loading` (spinner in the icon slot, `aria-busy`, and disabled so a second click cannot start the request twice), `fullWidth` to fill the container instead of the label, and an optional leading `icon`. Content-sized by default. |
|
|
221
|
-
| `Input`, `Select`, `Textarea` | Token-styled controls with stable framework typography, independent of surrounding display text (raw elements are lint-refused). Numeric inputs suppress unthemeable browser steppers. `Input type="password"` grows a reveal toggle — the type decides, so there is no second export and no prop
|
|
221
|
+
| `Input`, `Select`, `Textarea` | Token-styled controls with stable framework typography, independent of surrounding display text (raw elements are lint-refused). Numeric inputs suppress unthemeable browser steppers. `Input type="password"` grows a reveal toggle — the type decides, so there is no second export and no prop, and no app builds its own: a class from a CSS Module goes on a native element only (ADR 0217), never on `Input`. |
|
|
222
222
|
| `Select` options (`SelectOption<T>`) | Two forms. Pass `options={[{ value, label, disabled? }]}` with `onValueChange` when the choices are data — `T` is inferred from the list, so a closed enum is checked at both ends and the `event.target.value as Status` cast goes away; `placeholder` renders the disabled empty-valued leading row. Or pass `<option>` children as before. The two are mutually exclusive at the type level, so neither can silently ignore the other. |
|
|
223
223
|
| `Combobox` | Accessible autocomplete/typeahead single-select: filterable options, controlled or uncontrolled value, loading state, disabled state, and ARIA combobox/listbox keyboard navigation. |
|
|
224
|
-
| `DatePicker`, `DateRangePicker` | Locale-aware calendar popover controls with keyboard-navigable month grids, min/max bounds, and range selection for ERP date filters. |
|
|
224
|
+
| `DatePicker`, `DateRangePicker` | Locale-aware calendar popover controls with keyboard-navigable month grids, month and year steps (Shift+PageUp/PageDown for a year), min/max bounds, and range selection for ERP date filters. |
|
|
225
225
|
| `DateTimeInput` | A date and time a person picks, sent as the instant it names: it shows an RFC 3339 instant as wall time in a zone (the browser's own, or `zone="Europe/Amsterdam"`) and sends what is picked as an instant with that zone's offset, which the API's timestamp fields require (ADR 0206). A wall time the clocks skip moves past the gap; one they repeat is the earlier. `Input type="datetime-local"` is lint-refused, since its value carries no offset. |
|
|
226
226
|
| `Checkbox` | Labelled checkbox with `checked` / `defaultChecked` and boolean `onChange`. |
|
|
227
227
|
| `Radio`, `RadioGroup` | Labelled radio and accessible grouped radio options with controlled or uncontrolled value. |
|
|
@@ -247,9 +247,15 @@ marker, counted by the escape-hatch budget.
|
|
|
247
247
|
|
|
248
248
|
## Layout
|
|
249
249
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
250
|
+
Choose the layout for the user’s task. Compose existing controls and use the body of
|
|
251
|
+
a plain `Page` when a screen needs its own layout. A component can import a sibling
|
|
252
|
+
`./Board.module.css` with a static default import and use `className={styles.board}`.
|
|
253
|
+
Use local class selectors, a class on a native element only, and the palette's roles for paint:
|
|
254
|
+
`--color-fg-default`, `-muted` or `-subtle` for ink, `--color-bg-canvas`, `-surface` or
|
|
255
|
+
`-subtle` for a surface, a `--color-border-*` token for a border; set ink and type on an element
|
|
256
|
+
that holds only the app's own text. Use the spacing and type scale tokens for lengths and type.
|
|
257
|
+
Responsive rules can use `@media` or `@container`. Keep keyboard focus visible and
|
|
258
|
+
check the layout in narrow viewports and each supported theme. The following primitives implement common layouts.
|
|
253
259
|
|
|
254
260
|
| Export | Use |
|
|
255
261
|
|---|---|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terpjs/react-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.44.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Terp React stack core — typed @terpjs/contract client provider, auth session, capability gates, TanStack Router adapter, app shell, page archetypes, DataView and token-styled UI primitives. First frontend stack; see README.md for the component catalog.",
|
|
6
6
|
"exports": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@tanstack/react-router": "^1.170.46",
|
|
18
|
-
"@terpjs/contract": "^0.
|
|
18
|
+
"@terpjs/contract": "^0.44.0"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"react": "^19.0.0",
|
package/src/layout.tsx
CHANGED
|
@@ -173,8 +173,9 @@ export type GridProps = GridBaseProps & GridTracks;
|
|
|
173
173
|
/**
|
|
174
174
|
* The two-dimensional layout primitive, and the one that lifts a real ceiling: with `Stack`
|
|
175
175
|
* as the entire vocabulary, a two-column form could not be expressed at all, so a fifteen-field
|
|
176
|
-
* form shipped as one long vertical run. App modules
|
|
177
|
-
* (ADR 0059), so that was not
|
|
176
|
+
* form shipped as one long vertical run. App modules could write neither `style` nor `className`
|
|
177
|
+
* then (ADR 0059; ADR 0217 later let a CSS Module class onto a native element), so that was not
|
|
178
|
+
* awkwardness — it was unbuildable.
|
|
178
179
|
*
|
|
179
180
|
* Every prop is a closed set and becomes a `data-*` attribute with a rule each, so `Grid`
|
|
180
181
|
* renders **no inline style** and stays out of the inline-style ledger (ADR 0097). Three
|
|
@@ -351,8 +352,9 @@ export interface DetailListProps extends Omit<HTMLAttributes<HTMLDListElement>,
|
|
|
351
352
|
* internals; a `gap` shorthand from here would reset both.
|
|
352
353
|
*
|
|
353
354
|
* The prop exists because its absence was the reason the value was unreachable: `Stack`,
|
|
354
|
-
* `Grid` and `Card` all take a `gap` on this scale, and app modules may write
|
|
355
|
-
*
|
|
355
|
+
* `Grid` and `Card` all take a `gap` on this scale, and app modules may write no `style` and no
|
|
356
|
+
* class on a framework component (ADR 0059, ADR 0217), so a detail list needing looser rows had
|
|
357
|
+
* nowhere to say so.
|
|
356
358
|
*/
|
|
357
359
|
gap?: SpaceToken;
|
|
358
360
|
}
|
package/src/locale.test.tsx
CHANGED
|
@@ -229,6 +229,20 @@ describe("LocaleProvider + LanguageSwitcher", () => {
|
|
|
229
229
|
</LocaleProvider>,
|
|
230
230
|
),
|
|
231
231
|
).toThrow(/missing .* framework string translation/);
|
|
232
|
+
// A catalog with no framework strings at all: the refusal names the first ten keys and
|
|
233
|
+
// counts the rest, so it stays one line however many keys a release adds.
|
|
234
|
+
const keys = Object.keys(DEFAULT_STRINGS);
|
|
235
|
+
expect(() =>
|
|
236
|
+
render(
|
|
237
|
+
<LocaleProvider locales={{ en: LOCALE_EN, de: { messages: { greeting: "Hallo" } } }}>
|
|
238
|
+
<span />
|
|
239
|
+
</LocaleProvider>,
|
|
240
|
+
),
|
|
241
|
+
).toThrow(
|
|
242
|
+
`Locale "de" is missing ${keys.length} framework string translation(s): ` +
|
|
243
|
+
`${keys.slice(0, 10).join(", ")}, and ${keys.length - 10} more. ` +
|
|
244
|
+
'Add each to the strings of the "de" catalog',
|
|
245
|
+
);
|
|
232
246
|
});
|
|
233
247
|
|
|
234
248
|
it("refuses malformed labels and supplied framework strings", () => {
|
|
@@ -313,6 +327,26 @@ describe("LocaleProvider + LanguageSwitcher", () => {
|
|
|
313
327
|
).toThrow(/missing .* framework string translation.*dataViewSearchPlaceholder/);
|
|
314
328
|
});
|
|
315
329
|
|
|
330
|
+
it("names the calendar's year keys, and where they go, to a catalog written before them", () => {
|
|
331
|
+
// The 0.44.0 upgrade path: a catalog complete against the key set before the calendar's
|
|
332
|
+
// year buttons joined it. Its upgrade note points at this refusal, so the refusal has to
|
|
333
|
+
// say which keys are missing and where they go, not only that some are.
|
|
334
|
+
const beforeYearSteps = completeCatalog(
|
|
335
|
+
"de",
|
|
336
|
+
Object.keys(DEFAULT_STRINGS).filter((key) => key !== "previousYear" && key !== "nextYear"),
|
|
337
|
+
);
|
|
338
|
+
expect(() =>
|
|
339
|
+
render(
|
|
340
|
+
<LocaleProvider locales={{ en: LOCALE_EN, de: { strings: beforeYearSteps } }}>
|
|
341
|
+
<span />
|
|
342
|
+
</LocaleProvider>,
|
|
343
|
+
),
|
|
344
|
+
).toThrow(
|
|
345
|
+
'Locale "de" is missing 2 framework string translation(s): previousYear, nextYear. ' +
|
|
346
|
+
'Add each to the strings of the "de" catalog',
|
|
347
|
+
);
|
|
348
|
+
});
|
|
349
|
+
|
|
316
350
|
it("always renders the descriptor fallback in the source locale", () => {
|
|
317
351
|
render(
|
|
318
352
|
<LocaleProvider
|
package/src/locale.tsx
CHANGED
|
@@ -128,10 +128,14 @@ function assertFrameworkStringsComplete(locales: Record<string, LocaleCatalog>):
|
|
|
128
128
|
(key) => catalog.strings?.[key as keyof TerpStrings] === undefined,
|
|
129
129
|
);
|
|
130
130
|
if (missing.length > 0) {
|
|
131
|
+
// A release that adds a framework string lands here for every app with a catalog of its
|
|
132
|
+
// own, so the refusal names the keys and where they go, not only that some are missing.
|
|
133
|
+
const named = missing.slice(0, 10).join(", ");
|
|
134
|
+
const more = missing.length > 10 ? `, and ${missing.length - 10} more` : "";
|
|
131
135
|
throw new Error(
|
|
132
|
-
`Locale "${code}" is missing ${missing.length} framework string translation(s) ` +
|
|
133
|
-
|
|
134
|
-
"
|
|
136
|
+
`Locale "${code}" is missing ${missing.length} framework string translation(s): ` +
|
|
137
|
+
`${named}${more}. Add each to the strings of the "${code}" catalog, as LOCALE_NL ` +
|
|
138
|
+
"does for every TerpStrings key; app messages alone do not translate the shell.",
|
|
135
139
|
);
|
|
136
140
|
}
|
|
137
141
|
}
|
|
@@ -197,6 +201,8 @@ export const LOCALE_NL: LocaleCatalog = {
|
|
|
197
201
|
selectDate: "Kies een datum",
|
|
198
202
|
selectDateRange: "Kies een periode",
|
|
199
203
|
nextMonth: "Volgende maand",
|
|
204
|
+
previousYear: "Vorig jaar",
|
|
205
|
+
nextYear: "Volgend jaar",
|
|
200
206
|
loading: "Laden...",
|
|
201
207
|
emptyList: "Nog niets te zien.",
|
|
202
208
|
add: "Toevoegen",
|
package/src/styles.test.ts
CHANGED
|
@@ -1865,8 +1865,8 @@ describe("cascade structure", () => {
|
|
|
1865
1865
|
for (const token of [0, 1, 2, 3, 4, 6, 8]) {
|
|
1866
1866
|
// `detail-list` joined the three late, and its absence is why the value it now takes was
|
|
1867
1867
|
// unreachable: every other layout primitive published a gap on this scale, so a detail
|
|
1868
|
-
// list wanting looser rows had nowhere to say so — and app modules may write
|
|
1869
|
-
//
|
|
1868
|
+
// list wanting looser rows had nowhere to say so — and app modules may write no `style`
|
|
1869
|
+
// and no class on a framework component. Its rules set `row-gap` rather than the shorthand, for the
|
|
1870
1870
|
// reason the sheet gives there: the column gap is the layout's, not the caller's.
|
|
1871
1871
|
for (const marker of ["stack", "card", "grid", "detail-list"]) {
|
|
1872
1872
|
expect(
|
|
@@ -1916,10 +1916,10 @@ describe("cascade structure", () => {
|
|
|
1916
1916
|
// first — and the card's tone rules now lose to it on layer instead.
|
|
1917
1917
|
'[data-terp="dataview-card"][data-clickable="true"]:focus-within',
|
|
1918
1918
|
// Re-derived rather than assumed, because the condition is not "has something
|
|
1919
|
-
// migrated" but "can any element this selector matches still beat it". Of the
|
|
1919
|
+
// migrated" but "can any element this selector matches still beat it". Of the NINETEEN
|
|
1920
1920
|
// sites wearing the iconbutton marker, only six can carry the disabled attribute at all:
|
|
1921
1921
|
// the four pagination arrows and the two reorder arrows. The shell's toggles, the toast
|
|
1922
|
-
// dismisser, the combobox's clear button, the calendar's month arrows, the expand toggle,
|
|
1922
|
+
// dismisser, the combobox's clear button, the calendar's month and year arrows, the expand toggle,
|
|
1923
1923
|
// the toolbar's clear-search button and two layout toggles and the password reveal have no
|
|
1924
1924
|
// disabled state —
|
|
1925
1925
|
// and each of the six set cursor inline until it migrated. The day a calendar arrow gains
|
package/src/styles.ts
CHANGED
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
* interaction states, keyed by the `data-terp` / `data-variant` attributes the
|
|
4
4
|
* components stamp on their roots (ADR 0094).
|
|
5
5
|
*
|
|
6
|
-
* Rules are attribute selectors, never class names, so
|
|
7
|
-
* `style
|
|
8
|
-
*
|
|
6
|
+
* Rules are attribute selectors, never class names, so they meet no class an app
|
|
7
|
+
* writes: the boundary lint refuses `style` in app modules and lets a class from a
|
|
8
|
+
* sibling CSS Module onto a native element only, never onto a framework control
|
|
9
|
+
* (ADR 0217). react-core itself is allowed to inject a stylesheet; the rule
|
|
10
|
+
* targets *app modules*.
|
|
9
11
|
*
|
|
10
12
|
* THIS SHEET CARRIES NO `!important`. It carried 35 at 0.7.0, and the count going
|
|
11
13
|
* to zero is what the migration was for: every rule here is now beatable by an
|
|
@@ -4457,7 +4459,14 @@ button[data-terp="input"][data-placeholder="true"] {
|
|
|
4457
4459
|
color: var(--color-neutral-700);
|
|
4458
4460
|
cursor: pointer;
|
|
4459
4461
|
}
|
|
4462
|
+
/* The title takes the space between the two button pairs, so the year and month buttons on
|
|
4463
|
+
each side sit together rather than being spread by space-between. It does not wrap: the
|
|
4464
|
+
four buttons leave the longest month name about its own width at 18rem, and a panel that
|
|
4465
|
+
grows a little reads better than a month name broken over two lines. */
|
|
4460
4466
|
[data-terp="calendar-title"] {
|
|
4467
|
+
flex: 1;
|
|
4468
|
+
text-align: center;
|
|
4469
|
+
white-space: nowrap;
|
|
4461
4470
|
font-weight: var(--font-weight-semibold);
|
|
4462
4471
|
color: var(--color-neutral-900);
|
|
4463
4472
|
}
|
package/src/typography.tsx
CHANGED
|
@@ -9,7 +9,8 @@ injectTerpStyles();
|
|
|
9
9
|
* The prose primitives, and the gap they close is narrower than "we had no typography".
|
|
10
10
|
*
|
|
11
11
|
* A module could always render a `<p>` or a `<code>`. What it could not do is give either any
|
|
12
|
-
* treatment: app modules
|
|
12
|
+
* treatment: app modules could write neither `style` nor `className` (ADR 0059, before ADR 0217
|
|
13
|
+
* let a sibling CSS Module class onto a native element), and a bare element
|
|
13
14
|
* carries no `data-terp`, so no rule in the sheet can reach it. The framework's own generated
|
|
14
15
|
* home page shipped a bare `<p>` and a bare `<code>` for exactly that reason. So these are the
|
|
15
16
|
* marker, and the marker is what makes the ink themeable.
|
|
@@ -98,6 +98,112 @@ describe("DatePicker", () => {
|
|
|
98
98
|
expect(document.activeElement).toBe(next);
|
|
99
99
|
});
|
|
100
100
|
|
|
101
|
+
it("steps a year at a time from the header, keeping the button's focus", () => {
|
|
102
|
+
render(
|
|
103
|
+
<LocaleProvider locales={{ en: LOCALE_EN }}>
|
|
104
|
+
<DatePicker aria-label="Due date" value={new Date(2026, 6, 7)} defaultOpen />
|
|
105
|
+
</LocaleProvider>,
|
|
106
|
+
);
|
|
107
|
+
const next = screen.getByRole("button", { name: "Next year" });
|
|
108
|
+
next.focus();
|
|
109
|
+
fireEvent.click(next);
|
|
110
|
+
expect(screen.getByRole("grid", { name: "July 2027" })).toBeInTheDocument();
|
|
111
|
+
// The cursor keeps its day, so the keyboard picks up where the pointer left it.
|
|
112
|
+
expect(screen.getByRole("grid").querySelector('[tabindex="0"]')?.textContent).toBe("7");
|
|
113
|
+
expect(document.activeElement).toBe(next);
|
|
114
|
+
|
|
115
|
+
const previous = screen.getByRole("button", { name: "Previous year" });
|
|
116
|
+
fireEvent.click(previous);
|
|
117
|
+
fireEvent.click(previous);
|
|
118
|
+
expect(screen.getByRole("grid", { name: "July 2025" })).toBeInTheDocument();
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("pages a year with Shift+PageUp and Shift+PageDown, and a month without Shift", async () => {
|
|
122
|
+
const onChange = vi.fn();
|
|
123
|
+
render(
|
|
124
|
+
<LocaleProvider locales={{ en: LOCALE_EN }}>
|
|
125
|
+
<DatePicker aria-label="Due date" defaultValue={new Date(2028, 1, 29)} onChange={onChange} />
|
|
126
|
+
</LocaleProvider>,
|
|
127
|
+
);
|
|
128
|
+
fireEvent.click(screen.getByRole("button", { name: /^Due date / }));
|
|
129
|
+
const grid = screen.getByRole("grid");
|
|
130
|
+
const cursor = () => grid.querySelector<HTMLElement>('[tabindex="0"]');
|
|
131
|
+
await waitFor(() => expect(document.activeElement).toBe(cursor()));
|
|
132
|
+
|
|
133
|
+
// 29 February has no twin a year on, so the day is the last the target month has.
|
|
134
|
+
fireEvent.keyDown(grid, { key: "PageDown", shiftKey: true });
|
|
135
|
+
expect(screen.getByRole("grid", { name: "February 2029" })).toBeInTheDocument();
|
|
136
|
+
expect(cursor()?.textContent).toBe("28");
|
|
137
|
+
expect(document.activeElement).toBe(cursor());
|
|
138
|
+
|
|
139
|
+
fireEvent.keyDown(grid, { key: "PageUp", shiftKey: true });
|
|
140
|
+
fireEvent.keyDown(grid, { key: "PageUp", shiftKey: true });
|
|
141
|
+
expect(screen.getByRole("grid", { name: "February 2027" })).toBeInTheDocument();
|
|
142
|
+
|
|
143
|
+
// Without Shift, PageUp pages a month: paging a year whatever Shift says would show
|
|
144
|
+
// February 2026 here.
|
|
145
|
+
fireEvent.keyDown(grid, { key: "PageUp" });
|
|
146
|
+
expect(screen.getByRole("grid", { name: "January 2027" })).toBeInTheDocument();
|
|
147
|
+
|
|
148
|
+
fireEvent.keyDown(grid, { key: "Enter" });
|
|
149
|
+
expect(onChange).toHaveBeenCalledWith(new Date(2027, 0, 28));
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("stops a year step at a bound on the bound's month, with the cursor in the grid", () => {
|
|
153
|
+
render(
|
|
154
|
+
<LocaleProvider locales={{ en: LOCALE_EN }}>
|
|
155
|
+
<DatePicker
|
|
156
|
+
aria-label="Due date"
|
|
157
|
+
value={new Date(2026, 6, 7)}
|
|
158
|
+
min={new Date(2026, 2, 25)}
|
|
159
|
+
max={new Date(2027, 1, 10)}
|
|
160
|
+
defaultOpen
|
|
161
|
+
/>
|
|
162
|
+
</LocaleProvider>,
|
|
163
|
+
);
|
|
164
|
+
// A year back from July 2026 is before `min`. Showing July 2025 would leave the cursor,
|
|
165
|
+
// clamped to 25 March 2026, outside every cell on screen, so nothing in the grid could take
|
|
166
|
+
// Tab and a keyboard step would drop focus to <body>.
|
|
167
|
+
fireEvent.click(screen.getByRole("button", { name: "Previous year" }));
|
|
168
|
+
expect(screen.getByRole("grid", { name: "March 2026" })).toBeInTheDocument();
|
|
169
|
+
expect(screen.getByRole("grid").querySelector('[tabindex="0"]')).toHaveAccessibleName(
|
|
170
|
+
"Wednesday, March 25, 2026",
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
fireEvent.click(screen.getByRole("button", { name: "Next year" }));
|
|
174
|
+
expect(screen.getByRole("grid", { name: "February 2027" })).toBeInTheDocument();
|
|
175
|
+
expect(screen.getByRole("grid").querySelector('[tabindex="0"]')).toHaveAccessibleName(
|
|
176
|
+
"Wednesday, February 10, 2027",
|
|
177
|
+
);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("leaves a header button's focus alone after a grid key that could not move the cursor", async () => {
|
|
181
|
+
// With the cursor on `min`, neither key moves it, so neither may leave raised the flag that
|
|
182
|
+
// makes the next cursor move take focus. Each key on its own: the second would overwrite
|
|
183
|
+
// whatever the first left behind.
|
|
184
|
+
for (const key of [{ key: "PageUp", shiftKey: true }, { key: "ArrowLeft" }]) {
|
|
185
|
+
render(
|
|
186
|
+
<LocaleProvider locales={{ en: LOCALE_EN }}>
|
|
187
|
+
<DatePicker aria-label="Due date" defaultValue={new Date(2026, 2, 25)} min={new Date(2026, 2, 25)} />
|
|
188
|
+
</LocaleProvider>,
|
|
189
|
+
);
|
|
190
|
+
fireEvent.click(screen.getByRole("button", { name: /^Due date / }));
|
|
191
|
+
const grid = screen.getByRole("grid");
|
|
192
|
+
const cursor = () => grid.querySelector<HTMLElement>('[tabindex="0"]');
|
|
193
|
+
await waitFor(() => expect(document.activeElement).toBe(cursor()));
|
|
194
|
+
|
|
195
|
+
fireEvent.keyDown(grid, key);
|
|
196
|
+
expect(cursor(), key.key).toHaveAccessibleName("Wednesday, March 25, 2026");
|
|
197
|
+
|
|
198
|
+
const next = screen.getByRole("button", { name: "Next year" });
|
|
199
|
+
next.focus();
|
|
200
|
+
fireEvent.click(next);
|
|
201
|
+
expect(screen.getByRole("grid", { name: "March 2027" })).toBeInTheDocument();
|
|
202
|
+
expect(document.activeElement, key.key).toBe(next);
|
|
203
|
+
cleanup();
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
|
|
101
207
|
it("opens the calendar on mount when asked", () => {
|
|
102
208
|
// Sixteen calendar rules have been in the sheet since stage 2c with no way to render the
|
|
103
209
|
// subtree, so neither visual lane had ever painted one. This is the way in.
|
package/src/ui/DatePicker.tsx
CHANGED
|
@@ -303,16 +303,24 @@ function Calendar({ mode, locale, visibleSeed, selected = null, range, min, max,
|
|
|
303
303
|
activeRef.current?.focus();
|
|
304
304
|
}, [activeKey]);
|
|
305
305
|
|
|
306
|
-
/**
|
|
306
|
+
/**
|
|
307
|
+
* Move the cursor from a key the grid handled, and take focus with it.
|
|
308
|
+
*
|
|
309
|
+
* The flag is raised only when the cursor really moves. A key at a bound leaves it where it
|
|
310
|
+
* is, so no commit re-runs the effect that lowers the flag, and a flag left raised would pull
|
|
311
|
+
* focus off a header button the next time one moved the cursor. Shift+PageUp with the cursor
|
|
312
|
+
* on `min` is now one such key, ArrowLeft there always was.
|
|
313
|
+
*/
|
|
307
314
|
function moveCursor(daysDelta: number) {
|
|
308
|
-
follow.current =
|
|
309
|
-
move(daysDelta);
|
|
315
|
+
follow.current = toKey(move(daysDelta)) !== activeKey;
|
|
310
316
|
}
|
|
311
317
|
|
|
312
|
-
/**
|
|
318
|
+
/**
|
|
319
|
+
* Page the month (or, by twelve, the year) from a key the grid handled. The header buttons
|
|
320
|
+
* deliberately do not.
|
|
321
|
+
*/
|
|
313
322
|
function pageMonth(delta: number) {
|
|
314
|
-
follow.current =
|
|
315
|
-
changeMonth(delta);
|
|
323
|
+
follow.current = toKey(changeMonth(delta)) !== activeKey;
|
|
316
324
|
}
|
|
317
325
|
|
|
318
326
|
function move(daysDelta: number) {
|
|
@@ -321,12 +329,33 @@ function Calendar({ mode, locale, visibleSeed, selected = null, range, min, max,
|
|
|
321
329
|
if (next.getMonth() !== month.getMonth() || next.getFullYear() !== month.getFullYear()) {
|
|
322
330
|
setMonth(startOfMonth(next));
|
|
323
331
|
}
|
|
332
|
+
return next;
|
|
324
333
|
}
|
|
325
334
|
|
|
335
|
+
/**
|
|
336
|
+
* Step the view by `delta` months, keeping the day of the month where the target month has it
|
|
337
|
+
* (31 March back one month is 28 or 29 February, 29 February on a year is the 28th).
|
|
338
|
+
*
|
|
339
|
+
* The view follows the cursor AFTER it is clamped to `min` / `max`, not the unclamped target.
|
|
340
|
+
* Showing the target used to be harmless enough for one month, since the clamped cursor
|
|
341
|
+
* usually still sat in the six weeks on screen; a year step made it the common case to show a
|
|
342
|
+
* month wholly outside the bounds while the cursor stayed in the other one. Then no cell in
|
|
343
|
+
* the grid carried `tabIndex={0}`, so Tab skipped the calendar, and a step from the keyboard
|
|
344
|
+
* unmounted the focused cell and dropped focus to <body> with nothing left to take it back.
|
|
345
|
+
* A step past a bound now lands on the bound itself, in the bound's own month, and once the
|
|
346
|
+
* cursor is on the bound a further step past it changes nothing, as an arrow key there already
|
|
347
|
+
* did: the grid's disabled days beyond the bound are what show where it lies.
|
|
348
|
+
*/
|
|
326
349
|
function changeMonth(delta: number) {
|
|
327
|
-
const
|
|
328
|
-
|
|
329
|
-
|
|
350
|
+
const target = addMonths(month, delta);
|
|
351
|
+
const next = clampDate(
|
|
352
|
+
new Date(target.getFullYear(), target.getMonth(), Math.min(activeDate.getDate(), daysInMonth(target))),
|
|
353
|
+
minDate,
|
|
354
|
+
maxDate,
|
|
355
|
+
);
|
|
356
|
+
setMonth(startOfMonth(next));
|
|
357
|
+
setActiveDate(next);
|
|
358
|
+
return next;
|
|
330
359
|
}
|
|
331
360
|
|
|
332
361
|
function selectDate(day: Date) {
|
|
@@ -375,13 +404,15 @@ function Calendar({ mode, locale, visibleSeed, selected = null, range, min, max,
|
|
|
375
404
|
event.preventDefault();
|
|
376
405
|
moveCursor(6 - activeDate.getDay());
|
|
377
406
|
break;
|
|
407
|
+
// Shift pages a year, as the APG date picker dialog does, so the keyboard reaches what
|
|
408
|
+
// the two year buttons in the header reach.
|
|
378
409
|
case "PageUp":
|
|
379
410
|
event.preventDefault();
|
|
380
|
-
pageMonth(-1);
|
|
411
|
+
pageMonth(event.shiftKey ? -12 : -1);
|
|
381
412
|
break;
|
|
382
413
|
case "PageDown":
|
|
383
414
|
event.preventDefault();
|
|
384
|
-
pageMonth(1);
|
|
415
|
+
pageMonth(event.shiftKey ? 12 : 1);
|
|
385
416
|
break;
|
|
386
417
|
case "Enter":
|
|
387
418
|
case " ":
|
|
@@ -399,10 +430,15 @@ function Calendar({ mode, locale, visibleSeed, selected = null, range, min, max,
|
|
|
399
430
|
// dialog boundary had already been crossed unnamed. axe does not report this at the
|
|
400
431
|
// wcag2a/aa tags the lane runs, so opening the calendar in stage 4 did not surface it.
|
|
401
432
|
<div role="dialog" aria-modal="false" aria-labelledby={titleId} data-terp="calendar">
|
|
433
|
+
{/* The year buttons sit outside the month buttons, the order of the APG date picker
|
|
434
|
+
dialog. Without them a date a few years off (a start date, an end of contract) was
|
|
435
|
+
twelve clicks per year away, and the keyboard's own year step had no pointer twin. */}
|
|
402
436
|
<div data-terp="calendar-header">
|
|
437
|
+
<button type="button" data-terp="iconbutton" aria-label={strings.previousYear} onClick={() => changeMonth(-12)}>«</button>
|
|
403
438
|
<button type="button" data-terp="iconbutton" aria-label={strings.previousMonth} onClick={() => changeMonth(-1)}>‹</button>
|
|
404
439
|
<div id={titleId} data-terp="calendar-title">{formatMonth(month, locale)}</div>
|
|
405
440
|
<button type="button" data-terp="iconbutton" aria-label={strings.nextMonth} onClick={() => changeMonth(1)}>›</button>
|
|
441
|
+
<button type="button" data-terp="iconbutton" aria-label={strings.nextYear} onClick={() => changeMonth(12)}>»</button>
|
|
406
442
|
</div>
|
|
407
443
|
<div data-terp="calendar-week" aria-hidden="true">
|
|
408
444
|
{weekdays.map((day) => <div key={day} data-terp="calendar-weekday">{day}</div>)}
|
package/src/ui/Input.tsx
CHANGED
|
@@ -21,10 +21,11 @@ export type InputProps = InputHTMLAttributes<HTMLInputElement>;
|
|
|
21
21
|
* tag name already makes." A `PasswordInput` export would be the `LoadingButton` mistake, a second
|
|
22
22
|
* name for one `<input>`.
|
|
23
23
|
*
|
|
24
|
-
* An app
|
|
25
|
-
* needs a positioned wrapper, and `BOUNDARY_SPEC`
|
|
26
|
-
* files — exactly the `Button.fullWidth` case: a shape the framework can
|
|
27
|
-
* cannot ask for.
|
|
24
|
+
* An app could not build this itself when it was added, which is why it belongs here rather than in
|
|
25
|
+
* a recipe. The toggle needs a positioned wrapper, and `BOUNDARY_SPEC` refused both `style` and
|
|
26
|
+
* `className` in module files — exactly the `Button.fullWidth` case: a shape the framework can
|
|
27
|
+
* produce and its consumers cannot ask for. A CSS Module class (ADR 0217) now reaches a native
|
|
28
|
+
* wrapper, but never `Input` itself, so the toggle stays the framework's.
|
|
28
29
|
*/
|
|
29
30
|
export function Input({ type, ...rest }: InputProps) {
|
|
30
31
|
const strings = useStrings();
|
package/src/uiText.tsx
CHANGED
|
@@ -436,6 +436,10 @@ export interface TerpStrings {
|
|
|
436
436
|
previousMonth: string;
|
|
437
437
|
/** DatePicker: steps the calendar forward one month. */
|
|
438
438
|
nextMonth: string;
|
|
439
|
+
/** DatePicker: steps the calendar back one year. */
|
|
440
|
+
previousYear: string;
|
|
441
|
+
/** DatePicker: steps the calendar forward one year. */
|
|
442
|
+
nextYear: string;
|
|
439
443
|
/** DatePicker: trigger text before a date is chosen. */
|
|
440
444
|
selectDate: string;
|
|
441
445
|
/** DateRangePicker: trigger text before a range is chosen. */
|
|
@@ -549,6 +553,8 @@ export const DEFAULT_STRINGS: TerpStrings = {
|
|
|
549
553
|
selectDate: "Select date",
|
|
550
554
|
selectDateRange: "Select date range",
|
|
551
555
|
nextMonth: "Next month",
|
|
556
|
+
previousYear: "Previous year",
|
|
557
|
+
nextYear: "Next year",
|
|
552
558
|
loading: "Loading...",
|
|
553
559
|
emptyList: "Nothing here yet.",
|
|
554
560
|
add: "Add",
|