@jini-ai/ui-kit 0.1.2 → 0.1.3
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.
|
@@ -48,9 +48,22 @@ export function useNativeDialog(required, optional = {}) {
|
|
|
48
48
|
'aria-busy': required.pending,
|
|
49
49
|
onCancel: (event) => { event.preventDefault(); if (!required.pending)
|
|
50
50
|
required.onClose({}); },
|
|
51
|
-
|
|
51
|
+
// A click whose target is the <dialog> itself is not always the backdrop: the dialog's own
|
|
52
|
+
// padding and gaps hit it too, and so does the click that dismisses a native date/select
|
|
53
|
+
// popup inside it (seen live: closing a datetime picker closed the whole modal). Only a point
|
|
54
|
+
// outside the dialog's box is a backdrop click.
|
|
55
|
+
onClick: (event) => { if (event.target === event.currentTarget && !required.pending && isOutsideBox(event))
|
|
52
56
|
required.onClose({}); } } };
|
|
53
57
|
}
|
|
58
|
+
/** True when the pointer is outside the dialog's own rectangle, i.e. on the ::backdrop. A click with no
|
|
59
|
+
* coordinates (keyboard activation, synthetic test clicks) keeps the old target-only behaviour. */
|
|
60
|
+
function isOutsideBox(event) {
|
|
61
|
+
const { clientX: x, clientY: y } = event;
|
|
62
|
+
if (x === 0 && y === 0)
|
|
63
|
+
return true;
|
|
64
|
+
const r = event.currentTarget.getBoundingClientRect();
|
|
65
|
+
return x < r.left || x > r.right || y < r.top || y > r.bottom;
|
|
66
|
+
}
|
|
54
67
|
export function useNativeConfirm(required, _optional = {}) {
|
|
55
68
|
const c = required.controller;
|
|
56
69
|
const vm = useNativeDialog({ open: c.open, title: c.title, pending: c.pending, onClose: () => c.requestDismiss({ reason: 'close' }) }, { initialFocus: () => c.focusInitial({}) });
|