@kahitsan/ksui 0.46.0 → 0.46.1
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": "@kahitsan/ksui",
|
|
3
|
-
"version": "0.46.
|
|
3
|
+
"version": "0.46.1",
|
|
4
4
|
"description": "ksui is a standalone set of SolidJS UI components for KahitSan/Hilinga and any SolidJS app. Published to the public npm registry and consumed as a normal dependency. Ships source under a `solid` export condition so the consumer's vite-plugin-solid compiles it with only solid-js externalized; it depends on nothing but solid-js + lucide-solid and injects its own CSS.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from "vitest";
|
|
2
|
-
import { render } from "@solidjs/testing-library";
|
|
3
|
-
import { Show, createSignal } from "solid-js";
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { cleanup, render } from "@solidjs/testing-library";
|
|
4
3
|
import Modal from "./Modal";
|
|
5
4
|
|
|
6
5
|
// Modal is the most critical shared widget — it wraps a native <dialog> with
|
|
@@ -68,4 +67,71 @@ describe("Modal", () => {
|
|
|
68
67
|
const card = container.querySelector(".ksui-modal-card")!;
|
|
69
68
|
expect(card.className).toContain("danger");
|
|
70
69
|
});
|
|
70
|
+
|
|
71
|
+
describe("sheet variant", () => {
|
|
72
|
+
// jsdom has no showModal()/close(); stand them in so a stacked dialog is open.
|
|
73
|
+
const proto = HTMLDialogElement.prototype;
|
|
74
|
+
const original = { showModal: proto.showModal, close: proto.close };
|
|
75
|
+
beforeEach(() => {
|
|
76
|
+
proto.showModal = function (this: HTMLDialogElement) {
|
|
77
|
+
this.setAttribute("open", "");
|
|
78
|
+
};
|
|
79
|
+
proto.close = function (this: HTMLDialogElement) {
|
|
80
|
+
this.removeAttribute("open");
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
afterEach(() => {
|
|
84
|
+
cleanup(); // unmount while the stubs still exist
|
|
85
|
+
proto.showModal = original.showModal;
|
|
86
|
+
proto.close = original.close;
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("calls onClose on Escape", () => {
|
|
90
|
+
const onClose = vi.fn();
|
|
91
|
+
render(() => (
|
|
92
|
+
<Modal variant="sheet" onClose={onClose}>
|
|
93
|
+
<p>sheet</p>
|
|
94
|
+
</Modal>
|
|
95
|
+
));
|
|
96
|
+
window.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true }));
|
|
97
|
+
expect(onClose).toHaveBeenCalledOnce();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("leaves Escape to a dialog opened on top of it", () => {
|
|
101
|
+
const onSheetClose = vi.fn();
|
|
102
|
+
const onDialogClose = vi.fn();
|
|
103
|
+
const { container } = render(() => (
|
|
104
|
+
<Modal variant="sheet" onClose={onSheetClose}>
|
|
105
|
+
<Modal onClose={onDialogClose}>
|
|
106
|
+
<button type="button">inside</button>
|
|
107
|
+
</Modal>
|
|
108
|
+
</Modal>
|
|
109
|
+
));
|
|
110
|
+
const dialog = container.querySelector("dialog")!;
|
|
111
|
+
expect(dialog.open).toBe(true);
|
|
112
|
+
|
|
113
|
+
// A browser delivers Escape as keydown (bubbling to window) and then
|
|
114
|
+
// fires cancel on the topmost modal dialog.
|
|
115
|
+
dialog
|
|
116
|
+
.querySelector("button")!
|
|
117
|
+
.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true }));
|
|
118
|
+
dialog.dispatchEvent(new Event("cancel", { cancelable: true }));
|
|
119
|
+
|
|
120
|
+
expect(onSheetClose).not.toHaveBeenCalled();
|
|
121
|
+
expect(onDialogClose).toHaveBeenCalledOnce();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("ignores an Escape keydown another handler already consumed", () => {
|
|
125
|
+
const onClose = vi.fn();
|
|
126
|
+
render(() => (
|
|
127
|
+
<Modal variant="sheet" onClose={onClose}>
|
|
128
|
+
<p>sheet</p>
|
|
129
|
+
</Modal>
|
|
130
|
+
));
|
|
131
|
+
const e = new KeyboardEvent("keydown", { key: "Escape", bubbles: true, cancelable: true });
|
|
132
|
+
e.preventDefault();
|
|
133
|
+
window.dispatchEvent(e);
|
|
134
|
+
expect(onClose).not.toHaveBeenCalled();
|
|
135
|
+
});
|
|
136
|
+
});
|
|
71
137
|
});
|
|
@@ -155,13 +155,28 @@ function DialogModal(local: LocalProps): JSX.Element {
|
|
|
155
155
|
);
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
+
function openModalDialogs(): HTMLDialogElement[] {
|
|
159
|
+
const open = [...document.querySelectorAll<HTMLDialogElement>("dialog[open]")];
|
|
160
|
+
try {
|
|
161
|
+
return open.filter((d) => d.matches(":modal"));
|
|
162
|
+
} catch {
|
|
163
|
+
// Engines without :modal support; treat every open dialog as modal.
|
|
164
|
+
return open;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
158
168
|
function SheetModal(local: LocalProps, size?: ModalSize): JSX.Element {
|
|
169
|
+
let overlayEl: HTMLDivElement | undefined;
|
|
170
|
+
|
|
159
171
|
lockPullToRefresh();
|
|
160
172
|
onCleanup(unlockPullToRefresh);
|
|
161
173
|
|
|
162
174
|
const handleKey = (e: KeyboardEvent) => {
|
|
163
|
-
if (e.key !== "Escape") return;
|
|
175
|
+
if (e.key !== "Escape" || e.defaultPrevented) return;
|
|
164
176
|
if (local.dismissable === false) return;
|
|
177
|
+
// A modal <dialog> stacked above this sheet owns Escape (it gets `cancel`);
|
|
178
|
+
// closing here too would discard the sheet underneath.
|
|
179
|
+
if (openModalDialogs().some((d) => !d.contains(overlayEl ?? null))) return;
|
|
165
180
|
local.onClose();
|
|
166
181
|
};
|
|
167
182
|
if (typeof window !== "undefined") {
|
|
@@ -179,7 +194,7 @@ function SheetModal(local: LocalProps, size?: ModalSize): JSX.Element {
|
|
|
179
194
|
// ModalLayerContext value is already ambient (an outer DialogModal's
|
|
180
195
|
// dialogEl if nested inside one, otherwise the default null/document.body).
|
|
181
196
|
return (
|
|
182
|
-
<div class="ksui-modal-sheet-overlay">
|
|
197
|
+
<div ref={overlayEl} class="ksui-modal-sheet-overlay">
|
|
183
198
|
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */}
|
|
184
199
|
<div class="ksui-modal-sheet-backdrop" onClick={handleBackdropClick} />
|
|
185
200
|
<div
|