@tangible/ui 0.2.28 → 0.2.30

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.
Files changed (101) hide show
  1. package/components/Accordion/Accordion.js +2 -1
  2. package/components/Avatar/Avatar.js +6 -2
  3. package/components/Button/types.d.ts +5 -5
  4. package/components/Chip/Chip.js +2 -1
  5. package/components/ChipGroup/ChipGroup.js +1 -1
  6. package/components/ChipGroup/types.d.ts +2 -1
  7. package/components/Chips/Chips.d.ts +2 -0
  8. package/components/Chips/Chips.js +2 -16
  9. package/components/ColorPicker/ColorField.d.ts +3 -3
  10. package/components/ColorPicker/ColorField.js +2 -1
  11. package/components/ColorPicker/ColorPicker.js +2 -1
  12. package/components/ColorPicker/usePointerDrag.d.ts +7 -0
  13. package/components/ColorPicker/usePointerDrag.js +15 -1
  14. package/components/Combobox/Combobox.js +3 -2
  15. package/components/ContentIndicator/types.d.ts +3 -3
  16. package/components/DatePicker/Calendar.js +4 -3
  17. package/components/DatePicker/DatePicker.js +3 -2
  18. package/components/DatePicker/PickerTrigger.js +2 -1
  19. package/components/DatePicker/types.d.ts +1 -1
  20. package/components/GradientPicker/GradientBar.js +3 -1
  21. package/components/GradientPicker/GradientPicker.js +4 -3
  22. package/components/Icon/Icon.d.ts +9 -2
  23. package/components/Icon/Icon.js +4 -3
  24. package/components/Icon/index.d.ts +1 -1
  25. package/components/IconButton/IconButton.js +13 -45
  26. package/components/IconButton/IconButtonCore.d.ts +9 -0
  27. package/components/IconButton/IconButtonCore.js +76 -0
  28. package/components/IconButton/types.d.ts +4 -3
  29. package/components/Modal/Modal.d.ts +12 -3
  30. package/components/Modal/Modal.js +38 -15
  31. package/components/MoveHandle/MoveHandle.js +3 -2
  32. package/components/MultiCombobox/MultiCombobox.js +3 -2
  33. package/components/MultiSelect/MultiSelect.js +3 -2
  34. package/components/NavMenu/NavMenu.js +2 -1
  35. package/components/NavMenu/types.d.ts +3 -3
  36. package/components/Notice/Notice.d.ts +7 -0
  37. package/components/Notice/Notice.js +6 -5
  38. package/components/Pager/Pager.js +5 -4
  39. package/components/Rating/Rating.js +2 -1
  40. package/components/SearchInput/SearchInput.js +3 -2
  41. package/components/SearchSelect/SearchSelect.js +3 -2
  42. package/components/SecretInput/SecretInput.js +3 -2
  43. package/components/Select/Select.js +3 -2
  44. package/components/Sidebar/Sidebar.js +2 -1
  45. package/components/StepIndicator/StepIndicator.js +4 -2
  46. package/components/StepIndicator/types.d.ts +2 -2
  47. package/components/StepList/types.d.ts +2 -2
  48. package/components/Tabs/types.d.ts +3 -3
  49. package/components/Toast/Toast.d.ts +5 -1
  50. package/components/Toast/Toast.js +3 -3
  51. package/components/Tooltip/Tooltip.d.ts +1 -1
  52. package/components/Tooltip/Tooltip.js +28 -6
  53. package/components/Tooltip/index.d.ts +1 -1
  54. package/components/Tooltip/types.d.ts +18 -0
  55. package/components/index.d.ts +2 -2
  56. package/figma-tokens.json +6 -4
  57. package/icons/cred/index.js +1 -0
  58. package/icons/icons.svg +7 -3
  59. package/icons/lms/index.d.ts +0 -3
  60. package/icons/lms/index.js +6 -33
  61. package/icons/manifest.json +71 -9
  62. package/icons/membersync/index.js +1 -0
  63. package/icons/player/index.js +1 -0
  64. package/icons/reaction/index.js +1 -0
  65. package/icons/registry.d.ts +14 -0
  66. package/icons/registry.js +7 -0
  67. package/icons/system/index.d.ts +11 -0
  68. package/icons/system/index.js +48 -0
  69. package/package.json +9 -2
  70. package/skills/building-with-tui/SKILL.md +249 -17
  71. package/styles/all.css +1 -1
  72. package/styles/all.expanded.css +127 -13
  73. package/styles/all.expanded.unlayered.css +127 -13
  74. package/styles/all.unlayered.css +1 -1
  75. package/styles/app.css +41 -0
  76. package/styles/components/_bundle.scss +2 -0
  77. package/styles/components/button.scss +6 -1
  78. package/styles/components/card.scss +17 -1
  79. package/styles/components/chip-group.scss +45 -28
  80. package/styles/components/chips.scss +21 -0
  81. package/styles/components/color-picker.scss +15 -1
  82. package/styles/components/gradient-picker.scss +2 -2
  83. package/styles/components/modal.scss +61 -0
  84. package/styles/components/tooltip.scss +8 -1
  85. package/styles/core.css +1 -1
  86. package/styles/core.unlayered.css +1 -1
  87. package/styles/system/_text-styles.scss +4 -0
  88. package/styles/system/_tokens.scss +7 -2
  89. package/styles/utilities/_index.scss +3 -0
  90. package/tui-manifest.json +46 -19
  91. package/utils/focus-trap.d.ts +1 -24
  92. package/utils/focus-trap.js +2 -65
  93. package/utils/scroll-lock.d.ts +4 -0
  94. package/utils/scroll-lock.js +25 -0
  95. package/utils/tabbable.d.ts +29 -0
  96. package/utils/tabbable.js +74 -0
  97. package/vanilla/modal.d.ts +37 -0
  98. package/vanilla/modal.js +453 -0
  99. package/vanilla/modal.min.js +1 -0
  100. package/vanilla/styles.css +1 -0
  101. package/vanilla/styles.unlayered.css +1 -0
package/tui-manifest.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
- "version": "0.2.28",
3
- "generated": "2026-10-02T21:31:01.904Z",
2
+ "version": "0.2.30",
3
+ "generated": "2026-10-24T23:31:09.605Z",
4
4
  "components": {
5
5
  "Accordion": {
6
6
  "props": {
@@ -270,14 +270,14 @@
270
270
  "description": "Click handler. Works for both button and anchor variants."
271
271
  },
272
272
  "leftIconName": {
273
- "type": "IconName",
273
+ "type": "IconSource",
274
274
  "required": false,
275
- "description": "Icon to display before the label.\nUse icon registry paths like \"system/check\".\n@example leftIconName=\"system/check\""
275
+ "description": "Icon to display before the label.\nA registry path like \"system/check\", or an icon component.\n@example leftIconName=\"system/check\""
276
276
  },
277
277
  "rightIconName": {
278
- "type": "IconName",
278
+ "type": "IconSource",
279
279
  "required": false,
280
- "description": "Icon to display after the label.\nUse icon registry paths like \"system/chevron-right\".\n@example rightIconName=\"system/chevron-right\""
280
+ "description": "Icon to display after the label.\nA registry path like \"system/chevron-right\", or an icon component.\n@example rightIconName=\"system/chevron-right\""
281
281
  },
282
282
  "leftIcon": {
283
283
  "type": "ReactNode",
@@ -765,7 +765,7 @@
765
765
  "alignment": {
766
766
  "type": "\"start\" | \"center\" | \"end\"",
767
767
  "required": false,
768
- "description": "Alignment along main axis."
768
+ "description": "Inline: distribution along the row (justify-content). Stack: cross-axis\nalignment (align-items). Published as `data-align`."
769
769
  },
770
770
  "multipleLabel": {
771
771
  "type": "string",
@@ -808,6 +808,11 @@
808
808
  "defaultValue": "sm",
809
809
  "description": "Gap between chips"
810
810
  },
811
+ "alignment": {
812
+ "type": "\"start\" | \"center\" | \"end\"",
813
+ "required": false,
814
+ "description": "Inline: distribution along the row. Stack: cross-axis alignment.\nPublished as `data-align`."
815
+ },
811
816
  "className": {
812
817
  "type": "string",
813
818
  "required": false
@@ -1039,9 +1044,9 @@
1039
1044
  "ContentIndicator": {
1040
1045
  "props": {
1041
1046
  "icon": {
1042
- "type": "IconName",
1047
+ "type": "IconSource",
1043
1048
  "required": true,
1044
- "description": "Icon to display in the center.\nUses the icon registry path format: \"category/name\"\n@example \"lms/question-mark\""
1049
+ "description": "Icon to display in the center.\nA registry path (\"category/name\") or an icon component.\n@example \"lms/question-mark\""
1045
1050
  },
1046
1051
  "size": {
1047
1052
  "type": "\"xs\" | \"sm\" | \"md\" | \"lg\"",
@@ -1440,9 +1445,9 @@
1440
1445
  "Icon": {
1441
1446
  "props": {
1442
1447
  "name": {
1443
- "type": "IconName",
1448
+ "type": "IconSource",
1444
1449
  "required": false,
1445
- "description": "Icon name from registry (e.g., \"system/check\")"
1450
+ "description": "Icon name from the registry (\"system/check\"), or an icon component."
1446
1451
  },
1447
1452
  "emoji": {
1448
1453
  "type": "string",
@@ -1490,9 +1495,9 @@
1490
1495
  "IconButton": {
1491
1496
  "props": {
1492
1497
  "icon": {
1493
- "type": "IconName",
1498
+ "type": "IconSource",
1494
1499
  "required": true,
1495
- "description": "Icon to display. Required — this is the button's visual content.\n@example icon=\"system/close\""
1500
+ "description": "Icon to display: a registry path or an icon component. Required — this is\nthe button's visual content.\n@example icon=\"system/close\""
1496
1501
  },
1497
1502
  "label": {
1498
1503
  "type": "string",
@@ -1665,7 +1670,7 @@
1665
1670
  "role": {
1666
1671
  "type": "\"dialog\" | \"alertdialog\"",
1667
1672
  "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\n`initialFocusSelector` says otherwise), and the APG wants that to be the 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/"
1673
+ "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
1674
  },
1670
1675
  "closeOnBackdropClick": {
1671
1676
  "type": "boolean",
@@ -1676,6 +1681,11 @@
1676
1681
  "type": "boolean",
1677
1682
  "required": false,
1678
1683
  "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."
1684
+ },
1685
+ "restoreFocusTo": {
1686
+ "type": "RefObject<HTMLElement> | (() => HTMLElement)",
1687
+ "required": false,
1688
+ "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
1689
  }
1680
1690
  },
1681
1691
  "cssTokens": [
@@ -2252,6 +2262,11 @@
2252
2262
  "type": "() => void",
2253
2263
  "required": false
2254
2264
  },
2265
+ "dismissedMessage": {
2266
+ "type": "string",
2267
+ "required": false,
2268
+ "description": "Announced to screen readers after the dismiss button removes the notice\n(not on a programmatic `exit()`). Default 'Notification dismissed'.\nOverride it to translate. If Notice gains more built-in strings, move\nthis and `dismissLabel` into a `labels` object together."
2269
+ },
2255
2270
  "exitAnimation": {
2256
2271
  "type": "\"none\" | \"collapse\" | \"fade\"",
2257
2272
  "required": false,
@@ -3514,7 +3529,7 @@
3514
3529
  "description": "Override the inferred status.\n\nBy default, status is derived from `value`. Set this explicitly for:\n- `'locked'` — Shows lock icon regardless of value\n- Force a specific state when value doesn't reflect actual status"
3515
3530
  },
3516
3531
  "icon": {
3517
- "type": "IconName",
3532
+ "type": "IconSource",
3518
3533
  "required": false,
3519
3534
  "description": "Custom icon to display instead of the default status icons.\n\n- Shows for `not-started` and `in-progress` states\n- `complete` always shows checkmark (completion is universal)\n- `locked` always shows lock (access restriction is universal)\n\nUse for content-type indicators like quizzes, readings, videos.\n@example icon=\"lms/question-mark\""
3520
3535
  },
@@ -4014,6 +4029,11 @@
4014
4029
  "required": false,
4015
4030
  "description": "Accessible label for the dismiss button. Default 'Dismiss'."
4016
4031
  },
4032
+ "dismissedMessage": {
4033
+ "type": "string",
4034
+ "required": false,
4035
+ "description": "Announced after the × button removes the toast (not on programmatic `dismiss(id)`). Default 'Notification dismissed'."
4036
+ },
4017
4037
  "actions": {
4018
4038
  "type": "ReactNode",
4019
4039
  "required": false,
@@ -4105,13 +4125,20 @@
4105
4125
  "type": "number",
4106
4126
  "required": false,
4107
4127
  "description": "Override provider's delay for this tooltip."
4128
+ },
4129
+ "type": {
4130
+ "type": "\"description\" | \"label\"",
4131
+ "required": false,
4132
+ "defaultValue": "'description'",
4133
+ "description": "`label` when the tooltip repeats the trigger's accessible name, as on an\nicon-only button; see `TooltipType`."
4108
4134
  }
4109
4135
  },
4110
4136
  "cssTokens": [
4111
4137
  "--tui-tooltip-bg",
4112
4138
  "--tui-tooltip-fg",
4113
4139
  "--tui-tooltip-radius",
4114
- "--tui-tooltip-z"
4140
+ "--tui-tooltip-z",
4141
+ "--tui-tooltip-max-width"
4115
4142
  ],
4116
4143
  "story": {
4117
4144
  "title": "Overlays/Tooltip",
@@ -4230,7 +4257,7 @@
4230
4257
  ],
4231
4258
  "textStyles": [
4232
4259
  "tui-text-style-display-{01|02|03|04}",
4233
- "tui-text-style-headline-{01|02|03|04|05|06}",
4260
+ "tui-text-style-headline-{01|02|03|04|05|06|07}",
4234
4261
  "tui-text-style-body",
4235
4262
  "tui-text-style-body-sm",
4236
4263
  "tui-text-style-label",
@@ -4334,9 +4361,9 @@
4334
4361
  "membersync": 22,
4335
4362
  "player": 24,
4336
4363
  "reaction": 36,
4337
- "system": 116
4364
+ "system": 123
4338
4365
  },
4339
- "total": 255,
4366
+ "total": 262,
4340
4367
  "manifest": "./icons/manifest.json"
4341
4368
  }
4342
4369
  }
@@ -1,18 +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;
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[];
1
+ export { FOCUSABLE_SELECTOR, isTabbable, getTabbable, getInitialFocus } from './tabbable';
16
2
  /**
17
3
  * Options for the focus trap hook.
18
4
  */
@@ -39,12 +25,3 @@ export type UseFocusTrapOptions = {
39
25
  * ```
40
26
  */
41
27
  export declare function useFocusTrap(containerRef: React.RefObject<HTMLElement | null>, options: UseFocusTrapOptions): void;
42
- /**
43
- * Finds the first focusable element within a container.
44
- * Optionally accepts a custom selector to try first.
45
- *
46
- * @param container - The container element to search within
47
- * @param preferredSelector - Optional selector to try before fallback
48
- * @returns The found element, or the container if nothing found
49
- */
50
- export declare function getInitialFocus(container: HTMLElement, preferredSelector?: string): HTMLElement;
@@ -1,51 +1,6 @@
1
1
  import { useEffect } from 'react';
2
- /**
3
- * CSS selector for focusable elements.
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(',');
20
- /**
21
- * Whether an element matched by FOCUSABLE_SELECTOR can actually take focus.
22
- * The selector alone over-matches: a button inside a disabled fieldset, an
23
- * inert subtree or a display:none ancestor (a closed accordion panel, a hidden
24
- * tab panel) still matches it. Picking one of those as the trap's first/last
25
- * edge lets Tab walk straight out of the dialog, so filter them here.
26
- */
27
- export function isTabbable(el, container) {
28
- if (el.matches(':disabled') || el.closest('[inert]'))
29
- return false;
30
- if (typeof el.checkVisibility === 'function') {
31
- return el.checkVisibility({ visibilityProperty: true });
32
- }
33
- // No checkVisibility (jsdom, older engines): walk up to the container.
34
- for (let node = el; node && node !== container; node = node.parentElement) {
35
- if (node.hidden)
36
- return false;
37
- const style = getComputedStyle(node);
38
- if (style.display === 'none')
39
- return false;
40
- if (node === el && style.visibility === 'hidden')
41
- return false;
42
- }
43
- return true;
44
- }
45
- /** The focusable elements in `container` that can actually take focus, in DOM order. */
46
- export function getTabbable(container) {
47
- return Array.from(container.querySelectorAll(FOCUSABLE_SELECTOR)).filter((n) => isTabbable(n, container));
48
- }
2
+ import { getTabbable } from './tabbable.js';
3
+ export { FOCUSABLE_SELECTOR, isTabbable, getTabbable, getInitialFocus } from './tabbable.js';
49
4
  /**
50
5
  * Traps focus within a container element.
51
6
  * Tab and Shift+Tab cycle through focusable elements inside the container.
@@ -103,21 +58,3 @@ export function useFocusTrap(containerRef, options) {
103
58
  return () => document.removeEventListener('keydown', handleKeyDown);
104
59
  }, [isActive, containerRef, onEscape, escapeDeactivates]);
105
60
  }
106
- /**
107
- * Finds the first focusable element within a container.
108
- * Optionally accepts a custom selector to try first.
109
- *
110
- * @param container - The container element to search within
111
- * @param preferredSelector - Optional selector to try before fallback
112
- * @returns The found element, or the container if nothing found
113
- */
114
- export function getInitialFocus(container, preferredSelector) {
115
- if (preferredSelector) {
116
- const preferred = container.querySelector(preferredSelector);
117
- if (preferred)
118
- return preferred;
119
- }
120
- // [data-autofocus] first, then DOM order, skipping anything that can't take focus.
121
- const tabbable = getTabbable(container);
122
- return tabbable.find((n) => n.matches('[data-autofocus]')) ?? tabbable[0] ?? container;
123
- }
@@ -0,0 +1,4 @@
1
+ /** Locks body scroll. Pair every call with one `unlockScroll()`. */
2
+ export declare function lockScroll(): void;
3
+ /** Releases one lock; scroll returns when none are left. */
4
+ export declare function unlockScroll(): void;
@@ -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;