@tangible/ui 0.2.28 → 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.
@@ -25,8 +25,9 @@ export type ModalProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'role' | 'ar
25
25
  * backdrop stops dismissing on click unless `closeOnBackdropClick` says otherwise, since a
26
26
  * stray click outside is not a response. Escape still closes: it is the keyboard "cancel".
27
27
  *
28
- * Initial focus lands on the first focusable element in DOM order (unless
29
- * `initialFocusSelector` says otherwise), and the APG wants that to be the safest action —
28
+ * Initial focus lands on the first focusable element in DOM order, skipping the built-in
29
+ * close button (unless `initialFocusSelector` says otherwise), and the APG wants that to be
30
+ * the safest action —
30
31
  * so put Cancel before the destructive action in `Modal.Foot`. If the visual order must
31
32
  * differ (`Modal.Foot justify="between"` with a destructive action first), point
32
33
  * `initialFocusSelector` at the safe one.
@@ -44,12 +45,20 @@ export type ModalProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'role' | 'ar
44
45
  * when focus is restored on close. Useful when the trigger may be off-screen
45
46
  * inside a scrollable container. Default: false. */
46
47
  preventScrollOnRestore?: boolean;
48
+ /** Where focus goes on close, read at close time. Defaults to whatever had
49
+ * focus when the modal opened. Set it when that element can be gone by then:
50
+ * a "Delete" in a list row whose confirm removes the row. Point it at the
51
+ * next row, the list heading or the "Add" button. A function suits a target
52
+ * that only exists by close time (the row after the deleted one). If neither
53
+ * this nor the captured element can take focus, focus falls to <body> and a
54
+ * dev warning names this prop (WCAG 2.4.3). */
55
+ restoreFocusTo?: React.RefObject<HTMLElement | null> | (() => HTMLElement | null);
47
56
  /** Additional class names applied to the dialog element (`.tui-modal__dialog`).
48
57
  * Use for layout tweaks, custom widths, or context-specific theming. */
49
58
  className?: string;
50
59
  children?: React.ReactNode;
51
60
  };
52
- declare function ModalRoot({ open, onClose, size, stickyHead, stickyFoot, 'aria-labelledby': labelledBy, 'aria-describedby': describedBy, role, initialFocusSelector, container, showCloseButton, closeLabel, closeOnBackdropClick, closeOnEscape, preventScrollOnRestore, className, children, ...rest }: ModalProps): import("react/jsx-runtime").JSX.Element | null;
61
+ declare function ModalRoot({ open, onClose, size, stickyHead, stickyFoot, 'aria-labelledby': labelledBy, 'aria-describedby': describedBy, role, initialFocusSelector, container, showCloseButton, closeLabel, closeOnBackdropClick, closeOnEscape, preventScrollOnRestore, restoreFocusTo, className, children, ...rest }: ModalProps): import("react/jsx-runtime").JSX.Element | null;
53
62
  type ModalCloseProps = {
54
63
  label?: string;
55
64
  className?: string;
@@ -4,11 +4,12 @@ import { createPortal } from 'react-dom';
4
4
  import { cx } from '../../utils/cx.js';
5
5
  import { isDev } from '../../utils/is-dev.js';
6
6
  import { getPortalRootFor } from '../../utils/portal.js';
7
+ import { lockScroll, unlockScroll } from '../../utils/scroll-lock.js';
7
8
  import { useFocusTrap, getInitialFocus } from '../../utils/focus-trap.js';
8
9
  import { ModalContext, useModalContext } from './context.js';
9
10
  import { IconButton } from '../IconButton/index.js';
10
11
  const isBrowser = typeof document !== 'undefined';
11
- function ModalRoot({ open, onClose, size = 'md', stickyHead, stickyFoot, 'aria-labelledby': labelledBy, 'aria-describedby': describedBy, role = 'dialog', initialFocusSelector, container, showCloseButton, closeLabel = 'Close', closeOnBackdropClick, closeOnEscape = true, preventScrollOnRestore = false, className, children, ...rest }) {
12
+ function ModalRoot({ open, onClose, size = 'md', stickyHead, stickyFoot, 'aria-labelledby': labelledBy, 'aria-describedby': describedBy, role = 'dialog', initialFocusSelector, container, showCloseButton, closeLabel = 'Close', closeOnBackdropClick, closeOnEscape = true, preventScrollOnRestore = false, restoreFocusTo, className, children, ...rest }) {
12
13
  const dialogRef = useRef(null);
13
14
  const anchorRef = useRef(null);
14
15
  const restoreRef = useRef(null);
@@ -110,28 +111,48 @@ function ModalRoot({ open, onClose, size = 'md', stickyHead, stickyFoot, 'aria-l
110
111
  'hidden container, or pass an explicit `container`.', buried);
111
112
  }
112
113
  }, [open, mount]);
113
- // Read at close time, not a dependency: the effect must run on close only.
114
+ // Read at close time, not dependencies: the effect must run on close only.
114
115
  const preventScrollOnRestoreRef = useRef(preventScrollOnRestore);
115
116
  preventScrollOnRestoreRef.current = preventScrollOnRestore;
116
- // Reset state when modal closes, restore focus to trigger.
117
+ const restoreFocusToRef = useRef(restoreFocusTo);
118
+ restoreFocusToRef.current = restoreFocusTo;
119
+ // Reset state when modal closes, restore focus: `restoreFocusTo` first, then
120
+ // whatever had focus at open. Each must still be in the document and
121
+ // actually take focus; a removed trigger's focus() is a silent no-op (#133).
117
122
  useEffect(() => {
118
123
  if (open)
119
124
  return;
120
- const el = restoreRef.current;
121
- if (el && typeof el.focus === 'function') {
122
- el.focus({ preventScroll: preventScrollOnRestoreRef.current });
123
- }
125
+ const captured = restoreRef.current;
124
126
  restoreRef.current = null;
125
127
  setMount(null);
128
+ if (!captured)
129
+ return; // no open cycle to close
130
+ const target = restoreFocusToRef.current;
131
+ const explicit = typeof target === 'function' ? target() : target?.current ?? null;
132
+ const candidates = [explicit, captured];
133
+ for (const el of candidates) {
134
+ if (!el || !el.isConnected || el === document.body)
135
+ continue;
136
+ el.focus({ preventScroll: preventScrollOnRestoreRef.current });
137
+ if (document.activeElement === el)
138
+ return;
139
+ }
140
+ // Only when a real target was lost. On WebKit a click doesn't focus the
141
+ // trigger, so `captured` is often <body> for an ordinary close; warning
142
+ // there would teach consumers to ignore the message.
143
+ if (isDev() && (explicit || captured !== document.body)) {
144
+ console.warn('[TUI Modal] Focus had nowhere to return on close: the element focused at open is ' +
145
+ 'gone or can\'t take focus, so focus fell to <body> (WCAG 2.4.3). Pass `restoreFocusTo` ' +
146
+ 'with an element that will still be there, such as the next row or the list heading.');
147
+ }
126
148
  }, [open]);
127
- // Body scroll lock.
149
+ // Body scroll lock, counted, so closing this modal doesn't unlock the page
150
+ // under another one (nested, or a vanilla modal open alongside).
128
151
  useEffect(() => {
129
152
  if (!open)
130
153
  return;
131
- document.body.classList.add('tui-modal-open');
132
- return () => {
133
- document.body.classList.remove('tui-modal-open');
134
- };
154
+ lockScroll();
155
+ return unlockScroll;
135
156
  }, [open]);
136
157
  // Inert sibling trees so screen readers cannot escape the dialog.
137
158
  // aria-modal alone is unreliable — NVDA/JAWS virtual cursor can still
@@ -188,7 +209,8 @@ function ModalRoot({ open, onClose, size = 'md', stickyHead, stickyFoot, 'aria-l
188
209
  }
189
210
  }
190
211
  if (!target) {
191
- target = getInitialFocus(dialog);
212
+ // The close button only when nothing else can take focus (#135).
213
+ target = getInitialFocus(dialog, undefined, { lastResort: '.tui-modal__close' });
192
214
  }
193
215
  target.focus({ preventScroll: true });
194
216
  // Development warning for missing labelledBy target
@@ -216,7 +238,7 @@ function ModalRoot({ open, onClose, size = 'md', stickyHead, stickyFoot, 'aria-l
216
238
  // Unmounts on the very next render (pre-paint), so it never lays anything out.
217
239
  if (!mount)
218
240
  return _jsx("span", { ref: anchorRef, hidden: true });
219
- return createPortal(_jsx(ModalContext.Provider, { value: contextValue, children: _jsxs("div", { className: "tui-modal", "data-state": "open", style: { pointerEvents: 'auto' }, children: [_jsx("div", { className: "tui-modal__backdrop", "aria-hidden": "true", onClick: backdropDismisses ? onClose : undefined }), _jsxs("div", { ref: dialogRef, role: role, "aria-modal": "true", "aria-labelledby": labelledBy, "aria-describedby": describedBy, className: cx('tui-modal__dialog', `is-size-${size}`, stickyHead && 'is-sticky-head', stickyFoot && 'is-sticky-foot', className), tabIndex: -1, ...rest, children: [showCloseButton && (_jsx(IconButton, { icon: "system/close", label: closeLabel, variant: "ghost", size: "sm", onClick: onClose, className: "tui-modal__close", showTooltip: true })), children] })] }) }), mount);
241
+ return createPortal(_jsx(ModalContext.Provider, { value: contextValue, children: _jsxs("div", { className: "tui-modal", "data-state": "open", style: { pointerEvents: 'auto' }, children: [_jsx("div", { className: "tui-modal__backdrop", "aria-hidden": "true", onClick: backdropDismisses ? onClose : undefined }), _jsxs("div", { ref: dialogRef, role: role, "aria-modal": "true", "aria-labelledby": labelledBy, "aria-describedby": describedBy, className: cx('tui-modal__dialog', `is-size-${size}`, stickyHead && 'is-sticky-head', stickyFoot && 'is-sticky-foot', className), tabIndex: -1, ...rest, children: [children, showCloseButton && (_jsx(IconButton, { icon: "system/close", label: closeLabel, variant: "ghost", size: "sm", onClick: onClose, className: "tui-modal__close", showTooltip: true }))] })] }) }), mount);
220
242
  }
221
243
  function ModalClose({ label = 'Close', className }) {
222
244
  const { onClose } = useModalContext();
package/figma-tokens.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.2.28",
2
+ "version": "0.2.29",
3
3
  "source": "publish/styles/all.expanded.css",
4
4
  "prefix": "tui-",
5
5
  "note": "Layer 1 primitives only. Component API tokens (--tui-{component}-*) are never defined in CSS — they exist only as fallback reads — so they have no Figma representation. CONTRACT: consumers read TUI defaults from this file at build time (variables[].cssVar, the \"Light\"/\"Dark\" mode names, and alias chains into TUI/Primitives). Renaming a cssVar or a mode is a breaking change to those consumers even when the CSS value is unchanged — a rename silently becomes an undefined default downstream — so treat it as at least a minor bump and call it out in the CHANGELOG.",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangible/ui",
3
- "version": "0.2.28",
3
+ "version": "0.2.29",
4
4
  "description": "Tangible Design System",
5
5
  "type": "module",
6
6
  "main": "./components/index.js",
@@ -58,6 +58,11 @@
58
58
  "./manifest.json": "./tui-manifest.json",
59
59
  "./skill": "./skills/building-with-tui/SKILL.md",
60
60
  "./figma-tokens.json": "./figma-tokens.json",
61
+ "./vanilla/modal": {
62
+ "import": "./vanilla/modal.js",
63
+ "types": "./vanilla/modal.d.ts"
64
+ },
65
+ "./vanilla/*": "./vanilla/*",
61
66
  "./components/Accordion": {
62
67
  "import": "./components/Accordion/index.js",
63
68
  "types": "./components/Accordion/index.d.ts"
@@ -270,7 +275,8 @@
270
275
  "tui-manifest.json",
271
276
  "figma-tokens.json",
272
277
  "types",
273
- "utils"
278
+ "utils",
279
+ "vanilla"
274
280
  ],
275
281
  "sideEffects": [
276
282
  "*.css",
@@ -11,8 +11,10 @@ the repo's own CLAUDE.md and `.claude/agents/*`.)
11
11
  The API is on disk and does not need guessing. What costs hours is the **wiring and the a11y
12
12
  plumbing**, because both fail silently rather than erroring. That is most of what follows.
13
13
 
14
- Verified against **0.2.11 + main** (Aug 22 2026). Version-specific claims are dated; re-check
15
- anything that reads as surprising.
14
+ Inventory figures (component counts, manifest coverage, subpaths, icons, `data-testid` pass-through)
15
+ were re-measured against **0.2.28** (Oct 13 2026). Other sections were last verified against
16
+ **0.2.11 + main** (Aug 22 2026) unless a claim carries its own date. Re-check anything that reads as
17
+ surprising.
16
18
 
17
19
  ## The minimum that works
18
20
 
@@ -41,9 +43,9 @@ there is no CSS at all.
41
43
  | which Storybook page is this? | `tui-manifest.json` → `components.<Name>.story.title` |
42
44
 
43
45
  Directory and file name match, with two exceptions: `Table/DataTable.d.ts` and
44
- `ColorPicker/ColorField.d.ts`. Props live in `types.d.ts` for 33 of 43 components; the other ten
46
+ `ColorPicker/ColorField.d.ts`. Props live in `types.d.ts` for 35 of 46 components; the other eleven
45
47
  declare them in the component file (Card, Chip, Chips, ColorPicker, Field, GradientPicker, Icon,
46
- Modal, Notice, OverlapStack).
48
+ Modal, Notice, OverlapStack, Toast).
47
49
  `<Dir>.d.ts` is still the better read for the **compound shape** — it spells out
48
50
  `type SelectCompound = … & { Trigger; Content; Option; Group; Label }` in one place, which the
49
51
  barrel's flat export list only implies.
@@ -58,21 +60,21 @@ the filter drops load-bearing API:
58
60
  - Any prop without a JSDoc comment is dropped, required or not. The clearest tell: the manifest's
59
61
  **`Checkbox` entry lists `rel` and `title` but not `checked`, `defaultChecked`, `indeterminate`
60
62
  or `onCheckedChange`** — the entire state API is missing while inherited HTML noise survives.
61
- - 36 components report `subcomponents: null`, and for 12 of those the compound API is real
63
+ - 39 components report `subcomponents: null`, and for 13 of those the compound API is real
62
64
  (Select, MultiSelect, SearchSelect, Combobox, MultiCombobox, Dropdown, Popover, Tooltip, Field,
63
- Sidebar, StepList, Toolbar) — [#87](https://github.com/TangibleInc/tangible-ui/issues/87).
64
- - Only 8 of 43 entries carry a `description`, and 4 carry `use`/`notFor`, so it is a thin guide to
65
+ Sidebar, StepList, Toolbar, NavMenu) — [#87](https://github.com/TangibleInc/tangible-ui/issues/87).
66
+ - Only 8 of 46 entries carry a `description`, and 4 carry `use`/`notFor`, so it is a thin guide to
65
67
  *which* component too. The two `guides` entries (Tabs vs SegmentedControl, Chip vs Button) are
66
68
  worth reading; the rest of that judgement is not in the file.
67
69
 
68
- **Manifest silence is not absence.** What it *is* good for: `cssTokens` (40 of 43 components list
70
+ **Manifest silence is not absence.** What it *is* good for: `cssTokens` (43 of 46 components list
69
71
  their full `--tui-<component>-*` API — the only shipped listing, since consumers have no SCSS) and
70
- `story` (all 43, pointing into <https://storybook-tangible-ui.pages.dev>).
72
+ `story` (all 46, pointing into <https://storybook-tangible-ui.pages.dev>).
71
73
 
72
74
  ### Types that will not resolve from the barrel
73
75
 
74
76
  `@tangible/ui` re-exports the main `*Props` types but systematically omits others. Import those from
75
- `@tangible/ui/components/<Dir>` — all 43 component subpaths are exported.
77
+ `@tangible/ui/components/<Dir>` — all 46 component subpaths are exported.
76
78
 
77
79
  - **Nearly every `*Labels` type** (the i18n prop): `ButtonLabels`, `FieldLabels`,
78
80
  `ComboboxLabels`, `MultiSelectLabels`, `RatingLabels`, `DataTableLabels`, `AvatarLabels`,
@@ -404,7 +406,10 @@ synthesise a second toggle. For a second control that toggles the same item (an
404
406
  **ConfirmDialog / AlertDialog → `Modal role="alertdialog"`** (needs both `aria-labelledby` and
405
407
  `aria-describedby`; the backdrop stops dismissing by default, Escape still cancels; put the actions in
406
408
  `Modal.Foot`, which is already an end-aligned flex row — `justify="between"` separates a destructive one).
407
- **Snackbar → `Toast`** (`ToastProvider` + `useToast()`). No Breadcrumb, no Skeleton, and no *standalone* time picker — but
409
+ **Snackbar → `Toast`** (`ToastProvider` + `useToast()`).
410
+ **Password / API key / token field → `SecretInput`** (a `TextInput` variant: masked, with a reveal
411
+ toggle whose name flips Show/Hide; `isSet` is a boolean so a stored secret never reaches the client,
412
+ it shows a "Saved" placeholder and typing replaces it; `locked` makes it read-only with no toggle). No Breadcrumb, no Skeleton, and no *standalone* time picker — but
408
413
  `DatePicker` / `DateRangePicker` take `withTime` for an hour/minute field (12- or 24-hour via
409
414
  `hour12`) plus a display-only `zoneLabel`; the value is a plain `Date` with wall-clock semantics,
410
415
  so timezone interpretation stays yours.
@@ -420,7 +425,7 @@ Two clusters are easy to pick wrong:
420
425
  chips in the trigger), `MultiCombobox` (multi, free-typing token field). All five share one
421
426
  listbox engine, so navigation and ARIA behave identically; the trigger is the choice.
422
427
 
423
- Icons are a registry, six sets, 237 entries (Aug 22 2026): `system` (99), `lms` (44), `reaction`
428
+ Icons are a registry, six sets, 255 entries (Oct 13 2026): `system` (116), `lms` (45), `reaction`
424
429
  (36), `player` (24), `membersync` (22), `cred` (12). `@tangible/ui/icons/manifest` is the
425
430
  machine-readable list.
426
431
 
@@ -435,8 +440,8 @@ There are no device icons (monitor / tablet / phone) in any set.
435
440
 
436
441
  `data-testid` pass-through is uneven, and the split is not the one you would guess. These spread
437
442
  rest props onto their primary element: **Button, Card, Checkbox, Chip, ColorPicker, ColorField,
438
- `Field`'s slots, GradientPicker, IconButton, Modal, Notice, SearchInput, SearchSelect, Switch,
439
- Textarea, TextInput**, **DataTable** (onto the `<table>`), and — since 0.2.16 — the group members
443
+ `Field`'s slots, GradientPicker, IconButton, Modal, NavMenu (root, `.Group`, `.Sub`, `.Item`),
444
+ Notice, SearchInput, SearchSelect, SecretInput, Switch, Textarea, TextInput, Toast**, **DataTable** (onto the `<table>`), and — since 0.2.16 — the group members
440
445
  **SegmentedControl.Item, Tabs.Tab and Radio**. Everything else drops them silently,
441
446
  including several that look like they would take them — Dropdown, Popover, Tooltip, Select,
442
447
  MultiSelect, Combobox, MultiCombobox, Sidebar, Toolbar, Pager, Rating, Progress,
@@ -467,6 +472,36 @@ One live trap there: **memoize `data`, or pass `autoResetPageIndex={false}`.** A
467
472
  a new identity every render, TanStack queues a page-0 reset on every `data` identity change, and
468
473
  with a controlled `pageIndex` that races your parent back to page 0 permanently.
469
474
 
475
+ ## Vanilla modal (no React)
476
+
477
+ For templates and plugin PHP with no React build (Tangible Blocks, L&L): `@tangible/ui` ships a framework-free modal on the native `<dialog>`. It replaces MicroModal; there is no compat layer, so the markup differs.
478
+
479
+ ```html
480
+ <link rel="stylesheet" href="https://unpkg.com/@tangible/ui/vanilla/styles.css"> <!-- or all.css, not both -->
481
+ <script src="https://unpkg.com/@tangible/ui/vanilla/modal.min.js" defer></script>
482
+
483
+ <button type="button" data-tui-modal-open="intro">Watch</button>
484
+
485
+ <dialog id="intro" class="tui-interface tui-modal" aria-labelledby="intro-title">
486
+ <div class="tui-modal__dialog is-size-lg"> <!-- required: a click on the <dialog> itself is the backdrop -->
487
+ <div class="tui-modal__head"><h2 id="intro-title">Intro</h2></div>
488
+ <div class="tui-modal__body"><div class="tui-modal__body-inner">
489
+ <iframe class="tui-modal__embed" title="Intro video" data-tui-modal-src="https://www.youtube.com/embed/ID?autoplay=1"></iframe>
490
+ </div></div>
491
+ <div class="tui-modal__foot">
492
+ <button type="button" class="tui-button" data-tui-modal-close>Close</button>
493
+ </div>
494
+ </div>
495
+ </dialog>
496
+ ```
497
+
498
+ - **Attributes.** `data-tui-modal-open="<id>"` and `data-tui-modal-close` go on any element (delegated, so markup added later works; `aria-disabled` triggers are ignored). On the dialog, `role="alertdialog"` (add `aria-describedby`) and `data-tui-modal-backdrop="dismiss" | "static"`; alertdialog defaults to static. `[autofocus]` / `[data-autofocus]` picks initial focus. A submit button or link carrying `data-tui-modal-close` keeps its default action. `data-tui-modal-restore-focus="<id>"` on the dialog names where focus goes on close, for when the opener is gone (a Delete-row confirm); otherwise it returns to the opener. Put `.tui-modal__close` last in the box: initial focus skips it unless it's the only control.
499
+ - **State and events.** The script sets `data-state` to `open`, `closing` or `closed`. `tui-modal-open` and `tui-modal-close` bubble from the dialog; close's `detail.returnValue` is the submitting button's value in a `<form method="dialog">`. `window.TangibleUI.modal` exposes `open(idOrDialog)` and `close(...)`.
500
+ - **Embeds.** `data-tui-modal-src` loads on open and is dropped on close, which stops a YouTube or Vimeo player with no `postMessage` script. `<audio>`/`<video>` pause. Always give the iframe a `title`.
501
+ - **Name it.** The dialog needs `aria-labelledby` pointing at an element that exists (a phantom id leaves it unnamed) or an `aria-label`, and an icon-only close needs its own `aria-label` (the script can't see that one). The script warns in the console about a missing or phantom name, a dangling `aria-describedby`, an alertdialog without `aria-describedby`, a missing `.tui-modal__dialog` box and no close control; warnings are always on.
502
+ - **Two enqueues are fine.** If Blocks and L&L both load the script, only the first copy installs.
503
+ - **Limit: the top layer.** A native modal puts everything else inert and renders above it. A React Select, datepicker or any widget portaled to `<body>` renders under the dialog and can't be used inside it. Keep such controls in the dialog's own markup.
504
+
470
505
  ## Known issues
471
506
 
472
507
  Each is tracked in the repo, so **follow the link for current state rather than trusting this