@tangible/ui 0.2.27 → 0.2.29
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/components/Button/Button.js +29 -3
- package/components/Button/types.d.ts +6 -1
- package/components/IconButton/IconButton.js +14 -3
- package/components/IconButton/types.d.ts +6 -1
- package/components/Modal/Modal.d.ts +12 -3
- package/components/Modal/Modal.js +38 -13
- package/figma-tokens.json +1 -1
- package/package.json +8 -2
- package/skills/building-with-tui/SKILL.md +49 -14
- package/styles/all.css +1 -1
- package/styles/all.expanded.css +37 -0
- package/styles/all.expanded.unlayered.css +37 -0
- package/styles/all.unlayered.css +1 -1
- package/styles/components/modal.scss +61 -0
- package/tui-manifest.json +10 -5
- package/utils/focus-trap.d.ts +1 -14
- package/utils/focus-trap.js +3 -43
- package/utils/scroll-lock.d.ts +4 -0
- package/utils/scroll-lock.js +25 -0
- package/utils/tabbable.d.ts +29 -0
- package/utils/tabbable.js +74 -0
- package/vanilla/modal.d.ts +37 -0
- package/vanilla/modal.js +453 -0
- package/vanilla/modal.min.js +1 -0
- package/vanilla/styles.css +1 -0
- package/vanilla/styles.unlayered.css +1 -0
|
@@ -77,6 +77,55 @@
|
|
|
77
77
|
padding-inline-end: calc(var(--_spacing) + var(--_offset-end));
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
// Native <dialog> host, for the vanilla build (src/vanilla/modal.ts). The
|
|
81
|
+
// <dialog> IS the .tui-modal layer above: full-viewport, scrolling, padding
|
|
82
|
+
// the box in from the edges. It paints the backdrop as its own background
|
|
83
|
+
// instead of through ::backdrop, so the colour reads --_backdrop from the
|
|
84
|
+
// element's normal cascade, and a click on the <dialog> itself is a click on
|
|
85
|
+
// the backdrop. The rules below undo the UA dialog box (fit-content size,
|
|
86
|
+
// centring margin, border, Canvas background).
|
|
87
|
+
dialog.#{sys.$prefix}modal {
|
|
88
|
+
inline-size: auto;
|
|
89
|
+
block-size: auto;
|
|
90
|
+
max-inline-size: none;
|
|
91
|
+
max-block-size: none;
|
|
92
|
+
margin: 0;
|
|
93
|
+
border: 0;
|
|
94
|
+
background: var(--_backdrop);
|
|
95
|
+
// The host paints no text of its own; the box sets its fg.
|
|
96
|
+
color: inherit;
|
|
97
|
+
// A tall box scrolls the <dialog>; don't hand the scroll on to the page.
|
|
98
|
+
overscroll-behavior: contain;
|
|
99
|
+
|
|
100
|
+
// .tui-modal's display: flex would otherwise show a closed dialog.
|
|
101
|
+
&:not([open]) {
|
|
102
|
+
display: none;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
&::backdrop {
|
|
106
|
+
background: transparent;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// The <dialog> takes focus only as a fallback; the ring goes on the box.
|
|
110
|
+
&:focus-visible {
|
|
111
|
+
outline: none;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// A video or other embed filling the body at 16:9, the common case for a
|
|
116
|
+
// modal that exists to play something.
|
|
117
|
+
.#{sys.$prefix}modal__embed {
|
|
118
|
+
display: block;
|
|
119
|
+
inline-size: 100%;
|
|
120
|
+
aspect-ratio: 16 / 9;
|
|
121
|
+
border: 0;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
dialog.#{sys.$prefix}modal:focus-visible > .#{sys.$prefix}modal__dialog {
|
|
125
|
+
outline: var(--#{sys.$prefix}focus-ring-width) solid var(--#{sys.$prefix}focus-ring-color);
|
|
126
|
+
outline-offset: var(--#{sys.$prefix}focus-ring-offset);
|
|
127
|
+
}
|
|
128
|
+
|
|
80
129
|
.#{sys.$prefix}modal__backdrop {
|
|
81
130
|
position: fixed; // Fixed so it covers viewport even when container scrolls
|
|
82
131
|
inset: 0;
|
|
@@ -320,6 +369,18 @@
|
|
|
320
369
|
transform: none;
|
|
321
370
|
opacity: 1;
|
|
322
371
|
}
|
|
372
|
+
|
|
373
|
+
// Native host: fade the backdrop it paints. The box above already keys
|
|
374
|
+
// off data-state, which the script sets after showModal() and flips to
|
|
375
|
+
// "closing" for the exit.
|
|
376
|
+
dialog.#{sys.$prefix}modal {
|
|
377
|
+
background-color: transparent;
|
|
378
|
+
transition: background-color var(--#{sys.$prefix}motion-duration) var(--#{sys.$prefix}motion-timing);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
dialog.#{sys.$prefix}modal[data-state="open"] {
|
|
382
|
+
background-color: var(--_backdrop);
|
|
383
|
+
}
|
|
323
384
|
}
|
|
324
385
|
|
|
325
386
|
// Windows High Contrast Mode support
|
package/tui-manifest.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.2.
|
|
3
|
-
"generated": "2026-10-
|
|
2
|
+
"version": "0.2.29",
|
|
3
|
+
"generated": "2026-10-19T00:42:30.786Z",
|
|
4
4
|
"components": {
|
|
5
5
|
"Accordion": {
|
|
6
6
|
"props": {
|
|
@@ -241,7 +241,7 @@
|
|
|
241
241
|
"type": "boolean",
|
|
242
242
|
"required": false,
|
|
243
243
|
"defaultValue": "false",
|
|
244
|
-
"description": "Loading state
|
|
244
|
+
"description": "Loading state: shows a spinner and blocks activation while keeping the\nbutton focusable (`aria-disabled`, not native `disabled`), so a\nkeyboard user who triggered it keeps their place. Only `onClick` is\nguarded: put the action there, not in `onKeyDown`/`onPointerDown`.\nThe start and end of loading aren't announced; confirm completion\nthrough your own status message (a Toast, say)."
|
|
245
245
|
},
|
|
246
246
|
"loadingLabel": {
|
|
247
247
|
"type": "string",
|
|
@@ -1525,7 +1525,7 @@
|
|
|
1525
1525
|
"loading": {
|
|
1526
1526
|
"type": "boolean",
|
|
1527
1527
|
"required": false,
|
|
1528
|
-
"description": "Loading state
|
|
1528
|
+
"description": "Loading state: shows a spinner and blocks activation while keeping the\nbutton focusable (`aria-disabled`, not native `disabled`), so a\nkeyboard user who triggered it keeps their place. Only `onClick` is\nguarded: put the action there, not in `onKeyDown`/`onPointerDown`.\nThe start and end of loading aren't announced; confirm completion\nthrough your own status message (a Toast, say)."
|
|
1529
1529
|
},
|
|
1530
1530
|
"loadingLabel": {
|
|
1531
1531
|
"type": "string",
|
|
@@ -1665,7 +1665,7 @@
|
|
|
1665
1665
|
"role": {
|
|
1666
1666
|
"type": "\"dialog\" | \"alertdialog\"",
|
|
1667
1667
|
"required": false,
|
|
1668
|
-
"description": "ARIA role of the dialog element. Default `'dialog'`.\n\n`'alertdialog'` is for a dialog that interrupts the user's workflow to demand a response —\na destructive-action confirm is the textbook case. Focus trap, `aria-modal`, Escape and\nfocus restore behave identically for both roles; what changes is the contract around them:\nthe APG alert dialog pattern expects BOTH `aria-labelledby` (the heading) and\n`aria-describedby` (the message) — a dev warning fires if either is missing — and the\nbackdrop stops dismissing on click unless `closeOnBackdropClick` says otherwise, since a\nstray click outside is not a response. Escape still closes: it is the keyboard \"cancel\".\n\nInitial focus lands on the first focusable element in DOM order (unless
|
|
1668
|
+
"description": "ARIA role of the dialog element. Default `'dialog'`.\n\n`'alertdialog'` is for a dialog that interrupts the user's workflow to demand a response —\na destructive-action confirm is the textbook case. Focus trap, `aria-modal`, Escape and\nfocus restore behave identically for both roles; what changes is the contract around them:\nthe APG alert dialog pattern expects BOTH `aria-labelledby` (the heading) and\n`aria-describedby` (the message) — a dev warning fires if either is missing — and the\nbackdrop stops dismissing on click unless `closeOnBackdropClick` says otherwise, since a\nstray click outside is not a response. Escape still closes: it is the keyboard \"cancel\".\n\nInitial focus lands on the first focusable element in DOM order, skipping the built-in\nclose button (unless `initialFocusSelector` says otherwise), and the APG wants that to be\nthe safest action —\nso put Cancel before the destructive action in `Modal.Foot`. If the visual order must\ndiffer (`Modal.Foot justify=\"between\"` with a destructive action first), point\n`initialFocusSelector` at the safe one.\nhttps://www.w3.org/WAI/ARIA/apg/patterns/alertdialog/"
|
|
1669
1669
|
},
|
|
1670
1670
|
"closeOnBackdropClick": {
|
|
1671
1671
|
"type": "boolean",
|
|
@@ -1676,6 +1676,11 @@
|
|
|
1676
1676
|
"type": "boolean",
|
|
1677
1677
|
"required": false,
|
|
1678
1678
|
"description": "When true, prevents the browser from scrolling to the trigger element\nwhen focus is restored on close. Useful when the trigger may be off-screen\ninside a scrollable container. Default: false."
|
|
1679
|
+
},
|
|
1680
|
+
"restoreFocusTo": {
|
|
1681
|
+
"type": "RefObject<HTMLElement> | (() => HTMLElement)",
|
|
1682
|
+
"required": false,
|
|
1683
|
+
"description": "Where focus goes on close, read at close time. Defaults to whatever had\nfocus when the modal opened. Set it when that element can be gone by then:\na \"Delete\" in a list row whose confirm removes the row. Point it at the\nnext row, the list heading or the \"Add\" button. A function suits a target\nthat only exists by close time (the row after the deleted one). If neither\nthis nor the captured element can take focus, focus falls to <body> and a\ndev warning names this prop (WCAG 2.4.3)."
|
|
1679
1684
|
}
|
|
1680
1685
|
},
|
|
1681
1686
|
"cssTokens": [
|
package/utils/focus-trap.d.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* CSS selector for focusable elements.
|
|
3
|
-
* Used by focus trap and initial focus logic.
|
|
4
|
-
*/
|
|
5
|
-
export declare const FOCUSABLE_SELECTOR: string;
|
|
1
|
+
export { FOCUSABLE_SELECTOR, isTabbable, getTabbable, getInitialFocus } from './tabbable';
|
|
6
2
|
/**
|
|
7
3
|
* Options for the focus trap hook.
|
|
8
4
|
*/
|
|
@@ -29,12 +25,3 @@ export type UseFocusTrapOptions = {
|
|
|
29
25
|
* ```
|
|
30
26
|
*/
|
|
31
27
|
export declare function useFocusTrap(containerRef: React.RefObject<HTMLElement | null>, options: UseFocusTrapOptions): void;
|
|
32
|
-
/**
|
|
33
|
-
* Finds the first focusable element within a container.
|
|
34
|
-
* Optionally accepts a custom selector to try first.
|
|
35
|
-
*
|
|
36
|
-
* @param container - The container element to search within
|
|
37
|
-
* @param preferredSelector - Optional selector to try before fallback
|
|
38
|
-
* @returns The found element, or the container if nothing found
|
|
39
|
-
*/
|
|
40
|
-
export declare function getInitialFocus(container: HTMLElement, preferredSelector?: string): HTMLElement;
|
package/utils/focus-trap.js
CHANGED
|
@@ -1,22 +1,6 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Used by focus trap and initial focus logic.
|
|
5
|
-
*/
|
|
6
|
-
export const FOCUSABLE_SELECTOR = [
|
|
7
|
-
'[data-autofocus]',
|
|
8
|
-
'a[href]',
|
|
9
|
-
'area[href]',
|
|
10
|
-
'button:not([disabled])',
|
|
11
|
-
'input:not([disabled]):not([type="hidden"])',
|
|
12
|
-
'select:not([disabled])',
|
|
13
|
-
'textarea:not([disabled])',
|
|
14
|
-
'iframe',
|
|
15
|
-
'audio[controls]',
|
|
16
|
-
'video[controls]',
|
|
17
|
-
'[contenteditable]:not([contenteditable="false"])',
|
|
18
|
-
'[tabindex]:not([tabindex="-1"])',
|
|
19
|
-
].join(',');
|
|
2
|
+
import { getTabbable } from './tabbable.js';
|
|
3
|
+
export { FOCUSABLE_SELECTOR, isTabbable, getTabbable, getInitialFocus } from './tabbable.js';
|
|
20
4
|
/**
|
|
21
5
|
* Traps focus within a container element.
|
|
22
6
|
* Tab and Shift+Tab cycle through focusable elements inside the container.
|
|
@@ -48,14 +32,7 @@ export function useFocusTrap(containerRef, options) {
|
|
|
48
32
|
// Tab trap
|
|
49
33
|
if (e.key !== 'Tab')
|
|
50
34
|
return;
|
|
51
|
-
const nodes =
|
|
52
|
-
if (n === document.activeElement)
|
|
53
|
-
return true;
|
|
54
|
-
// offsetParent is null for position:fixed elements — use computed style
|
|
55
|
-
// as a more reliable visibility check
|
|
56
|
-
const style = getComputedStyle(n);
|
|
57
|
-
return style.display !== 'none' && style.visibility !== 'hidden';
|
|
58
|
-
});
|
|
35
|
+
const nodes = getTabbable(container);
|
|
59
36
|
if (nodes.length === 0) {
|
|
60
37
|
e.preventDefault();
|
|
61
38
|
container.focus();
|
|
@@ -81,20 +58,3 @@ export function useFocusTrap(containerRef, options) {
|
|
|
81
58
|
return () => document.removeEventListener('keydown', handleKeyDown);
|
|
82
59
|
}, [isActive, containerRef, onEscape, escapeDeactivates]);
|
|
83
60
|
}
|
|
84
|
-
/**
|
|
85
|
-
* Finds the first focusable element within a container.
|
|
86
|
-
* Optionally accepts a custom selector to try first.
|
|
87
|
-
*
|
|
88
|
-
* @param container - The container element to search within
|
|
89
|
-
* @param preferredSelector - Optional selector to try before fallback
|
|
90
|
-
* @returns The found element, or the container if nothing found
|
|
91
|
-
*/
|
|
92
|
-
export function getInitialFocus(container, preferredSelector) {
|
|
93
|
-
if (preferredSelector) {
|
|
94
|
-
const preferred = container.querySelector(preferredSelector);
|
|
95
|
-
if (preferred)
|
|
96
|
-
return preferred;
|
|
97
|
-
}
|
|
98
|
-
const firstFocusable = container.querySelector(FOCUSABLE_SELECTOR);
|
|
99
|
-
return firstFocusable ?? container;
|
|
100
|
-
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Body scroll lock shared by every modal on the page: the React Modal and the
|
|
2
|
+
// vanilla one, which can be open at the same time when Fields (React) and
|
|
3
|
+
// Blocks or L&L markup (vanilla) share a page. The count lives on <body>, not
|
|
4
|
+
// in module scope, because each vanilla script is its own bundle with its own
|
|
5
|
+
// copy of this module. The lock lifts only when the last holder releases it.
|
|
6
|
+
const CLASS = 'tui-modal-open';
|
|
7
|
+
const COUNT = 'tuiScrollLock'; // data-tui-scroll-lock
|
|
8
|
+
function count() {
|
|
9
|
+
return Number(document.body.dataset[COUNT] ?? 0) || 0;
|
|
10
|
+
}
|
|
11
|
+
/** Locks body scroll. Pair every call with one `unlockScroll()`. */
|
|
12
|
+
export function lockScroll() {
|
|
13
|
+
document.body.dataset[COUNT] = String(count() + 1);
|
|
14
|
+
document.body.classList.add(CLASS);
|
|
15
|
+
}
|
|
16
|
+
/** Releases one lock; scroll returns when none are left. */
|
|
17
|
+
export function unlockScroll() {
|
|
18
|
+
const next = count() - 1;
|
|
19
|
+
if (next > 0) {
|
|
20
|
+
document.body.dataset[COUNT] = String(next);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
delete document.body.dataset[COUNT];
|
|
24
|
+
document.body.classList.remove(CLASS);
|
|
25
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS selector for focusable elements.
|
|
3
|
+
* Used by focus trap and initial focus logic.
|
|
4
|
+
*/
|
|
5
|
+
export declare const FOCUSABLE_SELECTOR: string;
|
|
6
|
+
/**
|
|
7
|
+
* Whether an element matched by FOCUSABLE_SELECTOR can actually take focus.
|
|
8
|
+
* The selector alone over-matches: a button inside a disabled fieldset, an
|
|
9
|
+
* inert subtree or a display:none ancestor (a closed accordion panel, a hidden
|
|
10
|
+
* tab panel) still matches it. Picking one of those as the trap's first/last
|
|
11
|
+
* edge lets Tab walk straight out of the dialog, so filter them here.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isTabbable(el: HTMLElement, container?: HTMLElement): boolean;
|
|
14
|
+
/** The focusable elements in `container` that can actually take focus, in DOM order. */
|
|
15
|
+
export declare function getTabbable(container: HTMLElement): HTMLElement[];
|
|
16
|
+
/**
|
|
17
|
+
* Finds the first focusable element within a container.
|
|
18
|
+
* Optionally accepts a custom selector to try first.
|
|
19
|
+
*
|
|
20
|
+
* @param container - The container element to search within
|
|
21
|
+
* @param preferredSelector - Optional selector to try before fallback
|
|
22
|
+
* @param options.lastResort - Selector for controls that shouldn't take initial
|
|
23
|
+
* focus while anything else can (a dialog's close button: opening a form on
|
|
24
|
+
* the control that discards it). Still chosen when it's all there is.
|
|
25
|
+
* @returns The found element, or the container if nothing found
|
|
26
|
+
*/
|
|
27
|
+
export declare function getInitialFocus(container: HTMLElement, preferredSelector?: string, { lastResort }?: {
|
|
28
|
+
lastResort?: string;
|
|
29
|
+
}): HTMLElement;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// React-free focus helpers. Shared by the React focus trap and the vanilla
|
|
2
|
+
// builds (src/vanilla), which must not pull React into a drop-in script.
|
|
3
|
+
/**
|
|
4
|
+
* CSS selector for focusable elements.
|
|
5
|
+
* Used by focus trap and initial focus logic.
|
|
6
|
+
*/
|
|
7
|
+
export const FOCUSABLE_SELECTOR = [
|
|
8
|
+
'[data-autofocus]',
|
|
9
|
+
'a[href]',
|
|
10
|
+
'area[href]',
|
|
11
|
+
'button:not([disabled])',
|
|
12
|
+
'input:not([disabled]):not([type="hidden"])',
|
|
13
|
+
'select:not([disabled])',
|
|
14
|
+
'textarea:not([disabled])',
|
|
15
|
+
'iframe',
|
|
16
|
+
'audio[controls]',
|
|
17
|
+
'video[controls]',
|
|
18
|
+
'[contenteditable]:not([contenteditable="false"])',
|
|
19
|
+
'[tabindex]:not([tabindex="-1"])',
|
|
20
|
+
].join(',');
|
|
21
|
+
/**
|
|
22
|
+
* Whether an element matched by FOCUSABLE_SELECTOR can actually take focus.
|
|
23
|
+
* The selector alone over-matches: a button inside a disabled fieldset, an
|
|
24
|
+
* inert subtree or a display:none ancestor (a closed accordion panel, a hidden
|
|
25
|
+
* tab panel) still matches it. Picking one of those as the trap's first/last
|
|
26
|
+
* edge lets Tab walk straight out of the dialog, so filter them here.
|
|
27
|
+
*/
|
|
28
|
+
export function isTabbable(el, container) {
|
|
29
|
+
if (el.matches(':disabled') || el.closest('[inert]'))
|
|
30
|
+
return false;
|
|
31
|
+
if (typeof el.checkVisibility === 'function') {
|
|
32
|
+
return el.checkVisibility({ visibilityProperty: true });
|
|
33
|
+
}
|
|
34
|
+
// No checkVisibility (jsdom, older engines): walk up to the container.
|
|
35
|
+
for (let node = el; node && node !== container; node = node.parentElement) {
|
|
36
|
+
if (node.hidden)
|
|
37
|
+
return false;
|
|
38
|
+
const style = getComputedStyle(node);
|
|
39
|
+
if (style.display === 'none')
|
|
40
|
+
return false;
|
|
41
|
+
if (node === el && style.visibility === 'hidden')
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
/** The focusable elements in `container` that can actually take focus, in DOM order. */
|
|
47
|
+
export function getTabbable(container) {
|
|
48
|
+
return Array.from(container.querySelectorAll(FOCUSABLE_SELECTOR)).filter((n) => isTabbable(n, container));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Finds the first focusable element within a container.
|
|
52
|
+
* Optionally accepts a custom selector to try first.
|
|
53
|
+
*
|
|
54
|
+
* @param container - The container element to search within
|
|
55
|
+
* @param preferredSelector - Optional selector to try before fallback
|
|
56
|
+
* @param options.lastResort - Selector for controls that shouldn't take initial
|
|
57
|
+
* focus while anything else can (a dialog's close button: opening a form on
|
|
58
|
+
* the control that discards it). Still chosen when it's all there is.
|
|
59
|
+
* @returns The found element, or the container if nothing found
|
|
60
|
+
*/
|
|
61
|
+
export function getInitialFocus(container, preferredSelector, { lastResort } = {}) {
|
|
62
|
+
if (preferredSelector) {
|
|
63
|
+
const preferred = container.querySelector(preferredSelector);
|
|
64
|
+
if (preferred)
|
|
65
|
+
return preferred;
|
|
66
|
+
}
|
|
67
|
+
// [data-autofocus] first, then DOM order, skipping anything that can't take focus.
|
|
68
|
+
const tabbable = getTabbable(container);
|
|
69
|
+
const autofocus = tabbable.find((n) => n.matches('[data-autofocus]'));
|
|
70
|
+
if (autofocus)
|
|
71
|
+
return autofocus;
|
|
72
|
+
const first = lastResort ? tabbable.find((n) => !n.matches(lastResort)) : tabbable[0];
|
|
73
|
+
return first ?? tabbable[0] ?? container;
|
|
74
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** Fired on the <dialog> after it opens. Bubbles, so one document listener covers every modal. */
|
|
2
|
+
export declare const MODAL_OPEN_EVENT = "tui-modal-open";
|
|
3
|
+
/** Fired on the <dialog> after it closes, however it closed. Bubbles. */
|
|
4
|
+
export declare const MODAL_CLOSE_EVENT = "tui-modal-close";
|
|
5
|
+
/** A dialog's id, or the element itself. */
|
|
6
|
+
export type ModalTarget = string | HTMLDialogElement;
|
|
7
|
+
export type ModalEventDetail = {
|
|
8
|
+
/** The element focus returns to on close: the trigger, or whatever had focus at open. */
|
|
9
|
+
opener: HTMLElement | null;
|
|
10
|
+
};
|
|
11
|
+
export type ModalCloseEventDetail = ModalEventDetail & {
|
|
12
|
+
/** The dialog's `returnValue`: the value of the button that submitted a `<form method="dialog">`. */
|
|
13
|
+
returnValue: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Opens a modal. Returns false when the target can't be found or opened.
|
|
17
|
+
*
|
|
18
|
+
* `opener` is where focus returns on close. Delegated triggers pass themselves;
|
|
19
|
+
* from script, pass the control that asked, because Safari doesn't focus a
|
|
20
|
+
* button on click and `document.activeElement` can be stale.
|
|
21
|
+
*/
|
|
22
|
+
export declare function open(target: ModalTarget, opener?: HTMLElement | null): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Closes a modal after its exit transition. The promise resolves when the
|
|
25
|
+
* exit ends: with the dialog closed, or still open if `open()` was called
|
|
26
|
+
* during the exit. A close already in progress returns the same promise.
|
|
27
|
+
*/
|
|
28
|
+
export declare function close(target: ModalTarget): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Wires up `data-tui-modal-open` / `data-tui-modal-close`, the backdrop and
|
|
31
|
+
* Escape for the whole document. Listeners are delegated, so markup added
|
|
32
|
+
* later needs no second call. Calls are counted: the listeners come off when
|
|
33
|
+
* every caller has run its teardown.
|
|
34
|
+
*
|
|
35
|
+
* The standalone script (`vanilla/modal.min.js`) calls this itself.
|
|
36
|
+
*/
|
|
37
|
+
export declare function init(): () => void;
|