@cosmicdrift/kumiko-renderer-web 0.244.0 → 0.245.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cosmicdrift/kumiko-renderer-web",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.245.0",
|
|
4
4
|
"description": "Web-platform bindings for @cosmicdrift/kumiko-renderer. HTML default-primitives, browser history-based navigation, EventSource-backed live events, and a one-call createKumikoApp that mounts the whole stack via react-dom.",
|
|
5
5
|
"license": "BUSL-1.1",
|
|
6
6
|
"author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"./styles.css": "./src/styles.css"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@cosmicdrift/kumiko-dispatcher-live": "0.
|
|
20
|
-
"@cosmicdrift/kumiko-headless": "0.
|
|
21
|
-
"@cosmicdrift/kumiko-renderer": "0.
|
|
19
|
+
"@cosmicdrift/kumiko-dispatcher-live": "0.245.0",
|
|
20
|
+
"@cosmicdrift/kumiko-headless": "0.245.0",
|
|
21
|
+
"@cosmicdrift/kumiko-renderer": "0.245.0",
|
|
22
22
|
"@radix-ui/react-dialog": "^1.1.15",
|
|
23
23
|
"@radix-ui/react-dropdown-menu": "^2.1.16",
|
|
24
24
|
"@radix-ui/react-label": "^2.1.8",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"@types/react-dom": "^19.2.3",
|
|
65
65
|
"jsdom": "^29.1.1",
|
|
66
66
|
"tailwindcss": "^4.3.0",
|
|
67
|
-
"@cosmicdrift/kumiko-locale-de": "0.
|
|
67
|
+
"@cosmicdrift/kumiko-locale-de": "0.245.0"
|
|
68
68
|
},
|
|
69
69
|
"repository": {
|
|
70
70
|
"type": "git",
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// `kind: "select"` with an explicit `display` (#2711). The short-option-set
|
|
2
|
+
// heuristic covered by select-segmented.test.tsx stays the default; these
|
|
3
|
+
// tests only cover the case where the caller states a presentation and the
|
|
4
|
+
// heuristic would have decided the other way.
|
|
5
|
+
|
|
6
|
+
import { describe, expect, test } from "bun:test";
|
|
7
|
+
import { fireEvent } from "@testing-library/react";
|
|
8
|
+
import { render, screen } from "../../__tests__/test-utils";
|
|
9
|
+
import { defaultPrimitives } from "../index";
|
|
10
|
+
|
|
11
|
+
const { Field, Input } = defaultPrimitives;
|
|
12
|
+
|
|
13
|
+
// Six options, every label past the 14-char threshold — the heuristic would
|
|
14
|
+
// render a dropdown for these.
|
|
15
|
+
const HEURISTIC_REJECTS = [
|
|
16
|
+
"Background Jobs Queue",
|
|
17
|
+
"Inbound Mail Processing",
|
|
18
|
+
"Realtime Event Stream",
|
|
19
|
+
"Scheduled Reporting",
|
|
20
|
+
"Tenant Provisioning",
|
|
21
|
+
"Search Index Rebuild",
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
// Three short labels — the heuristic would render the radio group for these.
|
|
25
|
+
const HEURISTIC_ACCEPTS = ["Draft", "Review", "Done"];
|
|
26
|
+
|
|
27
|
+
function renderSelect(
|
|
28
|
+
options: readonly string[],
|
|
29
|
+
overrides: {
|
|
30
|
+
readonly display?: "radio" | "dropdown";
|
|
31
|
+
readonly value?: string;
|
|
32
|
+
} = {},
|
|
33
|
+
): string[] {
|
|
34
|
+
const changes: string[] = [];
|
|
35
|
+
render(
|
|
36
|
+
<Field id="area" label="Area" testId="field-area">
|
|
37
|
+
<Input
|
|
38
|
+
kind="select"
|
|
39
|
+
id="area"
|
|
40
|
+
name="area"
|
|
41
|
+
value={overrides.value ?? options[0] ?? ""}
|
|
42
|
+
onChange={(v) => changes.push(v)}
|
|
43
|
+
options={options}
|
|
44
|
+
{...(overrides.display !== undefined && { display: overrides.display })}
|
|
45
|
+
/>
|
|
46
|
+
</Field>,
|
|
47
|
+
);
|
|
48
|
+
return changes;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
describe("DefaultInput select — explicit display request", () => {
|
|
52
|
+
test('display: "radio" renders the radio group even where the heuristic says dropdown', () => {
|
|
53
|
+
renderSelect(HEURISTIC_REJECTS, { display: "radio" });
|
|
54
|
+
expect(screen.queryByTestId("combobox-area")).toBeNull();
|
|
55
|
+
expect(screen.getAllByRole("radio")).toHaveLength(6);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test("the forced radio group keeps the accessible group name and checked state", () => {
|
|
59
|
+
renderSelect(HEURISTIC_REJECTS, {
|
|
60
|
+
display: "radio",
|
|
61
|
+
value: "Realtime Event Stream",
|
|
62
|
+
});
|
|
63
|
+
expect(screen.getByRole("radiogroup", { name: "Area" })).toBeTruthy();
|
|
64
|
+
expect(
|
|
65
|
+
screen.getByRole("radio", { name: "Realtime Event Stream" }).getAttribute("aria-checked"),
|
|
66
|
+
).toBe("true");
|
|
67
|
+
expect(
|
|
68
|
+
screen.getByRole("radio", { name: "Background Jobs Queue" }).getAttribute("aria-checked"),
|
|
69
|
+
).toBe("false");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("the forced radio group reports the raw option value on click", () => {
|
|
73
|
+
const changes = renderSelect(HEURISTIC_REJECTS, {
|
|
74
|
+
display: "radio",
|
|
75
|
+
value: "Background Jobs Queue",
|
|
76
|
+
});
|
|
77
|
+
fireEvent.click(screen.getByRole("radio", { name: "Search Index Rebuild" }));
|
|
78
|
+
expect(changes).toEqual(["Search Index Rebuild"]);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('display: "dropdown" keeps the dropdown where the heuristic says radio group', () => {
|
|
82
|
+
renderSelect(HEURISTIC_ACCEPTS, { display: "dropdown" });
|
|
83
|
+
expect(screen.queryByRole("radiogroup")).toBeNull();
|
|
84
|
+
expect(screen.getByTestId("combobox-area")).toBeTruthy();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("no display stated: the heuristic still decides", () => {
|
|
88
|
+
renderSelect(HEURISTIC_REJECTS);
|
|
89
|
+
expect(screen.getByTestId("combobox-area")).toBeTruthy();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('display: "radio" without options falls back to the dropdown, not an empty group', () => {
|
|
93
|
+
renderSelect([], { display: "radio" });
|
|
94
|
+
expect(screen.queryByRole("radiogroup")).toBeNull();
|
|
95
|
+
expect(screen.getByTestId("combobox-area")).toBeTruthy();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("labelled options render their label and report their value", () => {
|
|
99
|
+
const changes: string[] = [];
|
|
100
|
+
render(
|
|
101
|
+
<Field id="area" label="Area" testId="field-area">
|
|
102
|
+
<Input
|
|
103
|
+
kind="select"
|
|
104
|
+
id="area"
|
|
105
|
+
name="area"
|
|
106
|
+
value="jobs"
|
|
107
|
+
onChange={(v) => changes.push(v)}
|
|
108
|
+
display="radio"
|
|
109
|
+
options={[
|
|
110
|
+
{ value: "jobs", label: "Background Jobs Queue" },
|
|
111
|
+
{ value: "mail", label: "Inbound Mail Processing" },
|
|
112
|
+
{ value: "search", label: "Search Index Rebuild" },
|
|
113
|
+
{ value: "events", label: "Realtime Event Stream" },
|
|
114
|
+
{ value: "tenants", label: "Tenant Provisioning" },
|
|
115
|
+
]}
|
|
116
|
+
/>
|
|
117
|
+
</Field>,
|
|
118
|
+
);
|
|
119
|
+
fireEvent.click(screen.getByRole("radio", { name: "Inbound Mail Processing" }));
|
|
120
|
+
expect(changes).toEqual(["mail"]);
|
|
121
|
+
});
|
|
122
|
+
});
|
package/src/primitives/index.tsx
CHANGED
|
@@ -422,11 +422,10 @@ function withUnitSuffix(unit: string | undefined, input: ReactNode): ReactNode {
|
|
|
422
422
|
);
|
|
423
423
|
}
|
|
424
424
|
|
|
425
|
-
//
|
|
425
|
+
// Default presentation for `kind: "select"` with a small closed option set —
|
|
426
426
|
// a 4-value Status field looked wrong stretched into a full-width dropdown
|
|
427
|
-
// (edit-existing screenshot feedback).
|
|
428
|
-
//
|
|
429
|
-
// `options` + string value/onChange).
|
|
427
|
+
// (edit-existing screenshot feedback). Only consulted when the caller states
|
|
428
|
+
// no `display` of its own; an explicit `display` wins (#2711).
|
|
430
429
|
const SEGMENTED_SELECT_MAX_OPTIONS = 4;
|
|
431
430
|
const SEGMENTED_SELECT_MAX_LABEL_LENGTH = 14;
|
|
432
431
|
|
|
@@ -699,7 +698,13 @@ function DefaultInput(props: InputProps): ReactNode {
|
|
|
699
698
|
const comboOptions = props.options.map((o) =>
|
|
700
699
|
typeof o === "string" ? { value: o, label: o } : o,
|
|
701
700
|
);
|
|
702
|
-
|
|
701
|
+
// An explicit `display` is an author decision and outranks the
|
|
702
|
+
// heuristic in both directions — a requested radio group renders as
|
|
703
|
+
// one even when the labels are long or numerous (#2711).
|
|
704
|
+
const wantsRadioGroup =
|
|
705
|
+
props.display === "radio" ||
|
|
706
|
+
(props.display === undefined && isSegmentedSelectEligible(comboOptions));
|
|
707
|
+
if (wantsRadioGroup && comboOptions.length > 0) {
|
|
703
708
|
return (
|
|
704
709
|
<SegmentedSelect
|
|
705
710
|
id={props.id}
|