@tangible/ui 0.2.53 → 0.2.55

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.
@@ -4,6 +4,7 @@
4
4
  --tui-button-bg
5
5
  --tui-button-fg
6
6
  --tui-button-border
7
+ --tui-button-border-width
7
8
  --tui-button-radius
8
9
  --tui-button-bg-interact
9
10
  --tui-button-fg-interact
@@ -59,6 +60,7 @@ $_typography-lineHeight: var(--#{sys.$prefix}button-line-height, 1.4);
59
60
  // --tui-button-bg Background color
60
61
  // --tui-button-fg Foreground/text color
61
62
  // --tui-button-border Border color
63
+ // --tui-button-border-width Border width (default: --tui-border-width)
62
64
  // --tui-button-radius Border radius
63
65
  // --tui-button-bg-interact Hover/focus/active background
64
66
  // --tui-button-fg-interact Hover/focus/active foreground
@@ -156,7 +158,7 @@ $_typography-lineHeight: var(--#{sys.$prefix}button-line-height, 1.4);
156
158
  color: var(--_fg) !important;
157
159
  border-color: var(--_border) !important;
158
160
  border-style: solid;
159
- border-width: var(--#{sys.$prefix}border-width);
161
+ border-width: var(--#{sys.$prefix}button-border-width, var(--#{sys.$prefix}border-width));
160
162
 
161
163
  // Icons track the label, never the presentation scale — the [class*=]
162
164
  // arm outranks Icon's is-size-* rules so changes to the global icon
@@ -500,7 +502,7 @@ $_typography-lineHeight: var(--#{sys.$prefix}button-line-height, 1.4);
500
502
 
501
503
  background-color: var(--_bg);
502
504
  color: var(--_fg);
503
- border: var(--#{sys.$prefix}border-width) solid var(--_border);
505
+ border: var(--#{sys.$prefix}button-border-width, var(--#{sys.$prefix}border-width)) solid var(--_border);
504
506
  }
505
507
 
506
508
  &:hover::file-selector-button {
@@ -215,7 +215,8 @@
215
215
  // -------------------------------------------------------------------------
216
216
  // :where() on the layout context keeps slot specificity equal to base
217
217
  // selectors — consumers can override without fighting the cascade.
218
- @container tuiCard (width >= 400px) {
218
+ // rem, like Notice's and Pager's: the breakpoint scales with the text.
219
+ @container tuiCard (width >= 25rem) {
219
220
  :where(&.is-layout-inline) > .#{sys.$prefix}card__inner {
220
221
  display: flex;
221
222
  flex-direction: row;
@@ -2,6 +2,7 @@
2
2
 
3
3
  /* @tui-tokens
4
4
  --tui-checkbox-accent
5
+ --tui-checkbox-icon
5
6
  --tui-checkbox-border
6
7
  --tui-checkbox-border-hover
7
8
  --tui-checkbox-border-invalid
@@ -13,9 +14,10 @@
13
14
  --tui-checkbox-fg-disabled
14
15
  */
15
16
 
16
- // Structural SCSS constants (compile away, not overridable)
17
- $_checkmark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
18
- $_indeterminate: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3.5' stroke-linecap='round'%3E%3Cpath d='M6 12h12'/%3E%3C/svg%3E");
17
+ // Structural SCSS constants (compile away, not overridable). Used as masks:
18
+ // only their shape counts, the colour comes from --_icon.
19
+ $_checkmark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
20
+ $_indeterminate: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='3.5' stroke-linecap='round'%3E%3Cpath d='M6 12h12'/%3E%3C/svg%3E");
19
21
 
20
22
  @mixin styles() {
21
23
  // ==========================================================================
@@ -31,6 +33,12 @@ $_indeterminate: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/sv
31
33
  // Component API tokens (never defined here, only read via fallback):
32
34
  // --tui-checkbox-accent Accent color for checked/indeterminate
33
35
  // → --tui-input-accent → --tui-theme-primary-base
36
+ // --tui-checkbox-icon Tick and dash colour on the accent fill
37
+ // → --tui-theme-primary-on-base
38
+ // Doesn't follow an accent override: set
39
+ // it with --tui-checkbox-accent or
40
+ // --tui-input-accent when the fill isn't
41
+ // primary (as Chip's -icon, Button's -fg)
34
42
  // --tui-checkbox-border Border color (unchecked)
35
43
  // --tui-checkbox-border-hover Hover border (opt-in; default: no change)
36
44
  // → --tui-input-border → --tui-color-border-control
@@ -46,10 +54,11 @@ $_indeterminate: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/sv
46
54
  // --tui-checkbox-fg-disabled Label color when disabled (default fg-muted);
47
55
  // wins over -label-color
48
56
  //
49
- // Note: Checkmark/indeterminate icons are white (#fff) SVGs embedded as
50
- // data URIs. CSS custom properties cannot be referenced inside data URIs,
51
- // so the icon colour is fixed. Accent overrides must contrast against white
52
- // at 3:1 or better to keep the icon legible.
57
+ // The tick and dash are a ::before painted in --_icon through an SVG mask,
58
+ // so they follow the fill's on-base colour: white on TUI's default fills,
59
+ // dark on a lifted dark-mode fill. A baked white SVG can't read a custom
60
+ // property, and vanished on light fills. Chromium, WebKit and Firefox
61
+ // (162) all draw pseudo-elements on an appearance: none checkbox.
53
62
  //
54
63
  // ==========================================================================
55
64
 
@@ -69,6 +78,7 @@ $_indeterminate: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/sv
69
78
  --_border: var(--_border-rest);
70
79
  --_radius: var(--#{sys.$prefix}checkbox-radius, var(--#{sys.$prefix}radius-sm));
71
80
  --_bg: var(--#{sys.$prefix}checkbox-bg, var(--#{sys.$prefix}color-bg));
81
+ --_icon: var(--#{sys.$prefix}checkbox-icon, var(--#{sys.$prefix}theme-primary-on-base));
72
82
 
73
83
  // Reset native appearance
74
84
  appearance: none;
@@ -81,6 +91,7 @@ $_indeterminate: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/sv
81
91
 
82
92
  // Box
83
93
  display: inline-block;
94
+ position: relative; // contains the ::before mark
84
95
  width: 1em;
85
96
  min-width: 1em;
86
97
  height: 1em;
@@ -91,10 +102,25 @@ $_indeterminate: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/sv
91
102
  border: var(--#{sys.$prefix}border-width) solid var(--_border);
92
103
  border-radius: var(--_radius);
93
104
  background-color: var(--_bg);
94
- background-size: 75%;
95
- background-position: center;
96
- background-repeat: no-repeat;
97
105
  cursor: pointer;
106
+ // The fill and the mark are both backgrounds, which print drops by
107
+ // default: checked would print as an empty box.
108
+ print-color-adjust: exact;
109
+
110
+ // The mark: hidden until checked or indeterminate sets its shape.
111
+ &::before {
112
+ content: "";
113
+ position: absolute;
114
+ inset: 0;
115
+ margin: auto;
116
+ width: 75%;
117
+ height: 75%;
118
+ background-color: var(--_icon);
119
+ print-color-adjust: exact;
120
+ -webkit-mask: var(--_icon-shape, none) center / contain no-repeat;
121
+ mask: var(--_icon-shape, none) center / contain no-repeat;
122
+ visibility: hidden;
123
+ }
98
124
 
99
125
  // Transitions
100
126
  transition-duration: var(--#{sys.$prefix}motion-duration);
@@ -105,7 +131,11 @@ $_indeterminate: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/sv
105
131
  &:checked {
106
132
  background-color: var(--_accent);
107
133
  border-color: var(--_accent);
108
- background-image: $_checkmark;
134
+
135
+ &::before {
136
+ --_icon-shape: #{$_checkmark};
137
+ visibility: visible;
138
+ }
109
139
  }
110
140
 
111
141
  // Indeterminate — uses :indeterminate pseudo-class which tracks the DOM property.
@@ -115,7 +145,11 @@ $_indeterminate: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/sv
115
145
  &:indeterminate {
116
146
  background-color: var(--_accent);
117
147
  border-color: var(--_accent);
118
- background-image: $_indeterminate;
148
+
149
+ &::before {
150
+ --_icon-shape: #{$_indeterminate};
151
+ visibility: visible;
152
+ }
119
153
  }
120
154
 
121
155
  // Hover: before Invalid so an invalid box keeps its red. Checked and
@@ -193,6 +227,13 @@ $_indeterminate: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/sv
193
227
  ) {
194
228
  // Let the browser render the checkbox natively in WHCM
195
229
  forced-color-adjust: auto;
230
+
231
+ // The forced palette would repaint the mark's background-color to
232
+ // Canvas, the same as the box: draw it in the text colour instead.
233
+ &::before {
234
+ forced-color-adjust: none;
235
+ background-color: CanvasText;
236
+ }
196
237
  }
197
238
 
198
239
  // The fg-muted cue is replaced by the system palette.
@@ -31,6 +31,8 @@
31
31
  --tui-nav-menu-icon-gap
32
32
  --tui-nav-menu-indicator-width
33
33
  --tui-nav-menu-indicator-color
34
+ --tui-nav-menu-indicator-inset-block
35
+ --tui-nav-menu-indicator-radius
34
36
  --tui-nav-menu-sub-indent
35
37
  --tui-nav-menu-sub-border
36
38
  --tui-nav-menu-bar-gap
@@ -202,6 +204,15 @@ $_knob-defaults: (
202
204
  // underline on the page or its
203
205
  // ancestor (try 2px).
204
206
  // --tui-nav-menu-indicator-color That bar's colour
207
+ // --tui-nav-menu-indicator-inset-block
208
+ // Vertical only: the bar's gap from the
209
+ // row's top and bottom (default: 25%;
210
+ // 0 runs it the row's full height)
211
+ // --tui-nav-menu-indicator-radius Corner radius: the bar's two trailing
212
+ // corners (default: radius-xs), or the
213
+ // underline's ends (default:
214
+ // radius-full). The default differs
215
+ // by orientation; 0 squares both
205
216
  // --tui-nav-menu-sub-indent / -border Nested list indent and guide line.
206
217
  // Under a parent with an icon, the
207
218
  // default indent lines the nested
@@ -332,10 +343,10 @@ $_knob-defaults: (
332
343
  content: "";
333
344
  position: absolute;
334
345
  inset-inline-start: 0;
335
- inset-block: 25%;
346
+ inset-block: var(--#{sys.$prefix}nav-menu-indicator-inset-block, 25%);
336
347
  inline-size: var(--_indicator);
337
- border-start-end-radius: var(--#{sys.$prefix}radius-xs);
338
- border-end-end-radius: var(--#{sys.$prefix}radius-xs);
348
+ border-start-end-radius: var(--#{sys.$prefix}nav-menu-indicator-radius, var(--#{sys.$prefix}radius-xs));
349
+ border-end-end-radius: var(--#{sys.$prefix}nav-menu-indicator-radius, var(--#{sys.$prefix}radius-xs));
339
350
  background: var(--#{sys.$prefix}nav-menu-indicator-color, var(--#{sys.$prefix}theme-primary-base));
340
351
  }
341
352
  }
@@ -474,7 +485,7 @@ $_knob-defaults: (
474
485
  inset-inline: var(--_item-pad, var(--#{sys.$prefix}nav-menu-item-padding-inline, var(--#{sys.$prefix}spacing-sm)));
475
486
  inset-block-end: 0;
476
487
  block-size: var(--_indicator);
477
- border-radius: var(--#{sys.$prefix}radius-full, 9999px);
488
+ border-radius: var(--#{sys.$prefix}nav-menu-indicator-radius, var(--#{sys.$prefix}radius-full, 9999px));
478
489
  background: var(--#{sys.$prefix}nav-menu-indicator-color, var(--#{sys.$prefix}theme-primary-base));
479
490
  }
480
491
  }
@@ -214,7 +214,11 @@
214
214
  align-items: center;
215
215
  }
216
216
 
217
- @container tuiNotice (width >= 400px) {
217
+ // The inline breakpoint is in rem, like Pager's: the content it guards is
218
+ // sized in rem (text, Toast's 26rem width), so the two must scale
219
+ // together. A px breakpoint stacked a host's toasts once its root
220
+ // interface set --tui-typography-size: 15px (26rem = 390px < 400px).
221
+ @container tuiNotice (width >= 25rem) {
218
222
  &.is-layout-inline {
219
223
  // Make root a flex container so dismiss button flows at end
220
224
  display: flex;
@@ -284,7 +288,7 @@
284
288
  // :where() keeps the row at (0,1,0) like the slot rules above, so it stays
285
289
  // overridable; it wins on source order. Child combinators, as in Card: a
286
290
  // Notice nested in this one's Body must not pick up its alignment.
287
- @container tuiNotice (width >= 400px) {
291
+ @container tuiNotice (width >= 25rem) {
288
292
  :where(&[data-align="start"]) > .#{sys.$prefix}notice__inner {
289
293
  align-items: flex-start;
290
294
 
@@ -314,7 +318,7 @@
314
318
  }
315
319
 
316
320
  // In inline mode, dismiss flows so no reserved space needed
317
- @container tuiNotice (width >= 400px) {
321
+ @container tuiNotice (width >= 25rem) {
318
322
  :where(&.is-layout-inline.is-dismissible) .#{sys.$prefix}notice__inner {
319
323
  padding-inline-end: 0;
320
324
 
@@ -88,13 +88,14 @@
88
88
  // to match the sibling buttons' height at each size tier (keyed on the
89
89
  // `is-size-*` class the component adds). The border reads the bridged
90
90
  // Button token defined on the group above — not Button's --_border
91
- // internal, which only exists on actual Buttons.
91
+ // internal, which only exists on actual Buttons — and Button's
92
+ // border-width token, so it stays the same weight as its neighbours.
92
93
  .#{sys.$prefix}pager__ellipsis {
93
94
  @include sys.control-sizing(sys.$prefix);
94
95
  display: inline-flex;
95
96
  align-items: center;
96
97
  justify-content: center;
97
- border: var(--#{sys.$prefix}border-width) solid var(--#{sys.$prefix}button-border);
98
+ border: var(--#{sys.$prefix}button-border-width, var(--#{sys.$prefix}border-width)) solid var(--#{sys.$prefix}button-border);
98
99
  background: transparent;
99
100
  color: var(--#{sys.$prefix}color-fg-muted);
100
101
  border-radius: var(--#{sys.$prefix}radius-sm);
@@ -8,6 +8,9 @@
8
8
  --tui-sidebar-border
9
9
  --tui-sidebar-divider
10
10
  --tui-sidebar-padding
11
+ --tui-sidebar-header-padding
12
+ --tui-sidebar-nav-padding
13
+ --tui-sidebar-footer-padding
11
14
  --tui-sidebar-z
12
15
  */
13
16
 
@@ -23,7 +26,12 @@
23
26
  // --tui-sidebar-fg Text color
24
27
  // --tui-sidebar-border Edge border color (docked left/right edge)
25
28
  // --tui-sidebar-divider Header/footer divider color
26
- // --tui-sidebar-padding Internal padding
29
+ // --tui-sidebar-padding Internal padding: the three regions, and
30
+ // the collapsed rail and its toggle
31
+ // --tui-sidebar-header-padding Header padding (default: --tui-sidebar-padding)
32
+ // --tui-sidebar-nav-padding Nav padding (default: --tui-sidebar-padding).
33
+ // `var(--tui-spacing-md) 0` runs rows edge to edge
34
+ // --tui-sidebar-footer-padding Footer padding (default: --tui-sidebar-padding)
27
35
  // --tui-sidebar-z Z-index (drawer mode only)
28
36
  //
29
37
  // To override from consuming code:
@@ -78,7 +86,7 @@
78
86
 
79
87
  :where(.#{sys.$prefix}interface) .#{sys.$prefix}sidebar__header {
80
88
  flex-shrink: 0;
81
- padding: var(--_padding);
89
+ padding: var(--#{sys.$prefix}sidebar-header-padding, var(--_padding));
82
90
  border-bottom: var(--#{sys.$prefix}border-width) solid var(--_divider);
83
91
 
84
92
  // Flex column layout for typical header content
@@ -99,7 +107,7 @@
99
107
  :where(.#{sys.$prefix}interface) .#{sys.$prefix}sidebar__footer {
100
108
  flex-shrink: 0;
101
109
  margin-top: auto;
102
- padding: var(--_padding);
110
+ padding: var(--#{sys.$prefix}sidebar-footer-padding, var(--_padding));
103
111
  border-top: var(--#{sys.$prefix}border-width) solid var(--_divider);
104
112
 
105
113
  display: flex;
@@ -114,7 +122,7 @@
114
122
  :where(.#{sys.$prefix}interface) .#{sys.$prefix}sidebar__nav {
115
123
  flex: 1;
116
124
  overflow-y: auto;
117
- padding: var(--_padding);
125
+ padding: var(--#{sys.$prefix}sidebar-nav-padding, var(--_padding));
118
126
  }
119
127
 
120
128
  // ---------------------------------------------------------------------------
@@ -30,7 +30,7 @@
30
30
  //
31
31
  // Toast's own API tokens (never defined here, only read via fallback):
32
32
  // --tui-toast-width Toast width (default 26rem — the default must keep
33
- // Notice's inline container query (content ≥ 400px)
33
+ // Notice's inline container query (content ≥ 25rem)
34
34
  // true, or the layout falls back to stacked). Read
35
35
  // by the REGION, which owns all sizing (toasts fill
36
36
  // it) — override it on .tui-toast-region or
package/tui-manifest.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
- "version": "0.2.53",
3
- "generated": "2026-11-26T19:55:17.116Z",
2
+ "version": "0.2.55",
3
+ "generated": "2026-12-03T05:00:14.996Z",
4
4
  "components": {
5
5
  "Accordion": {
6
6
  "props": {
@@ -333,6 +333,7 @@
333
333
  "--tui-button-bg",
334
334
  "--tui-button-fg",
335
335
  "--tui-button-border",
336
+ "--tui-button-border-width",
336
337
  "--tui-button-radius",
337
338
  "--tui-button-bg-interact",
338
339
  "--tui-button-fg-interact",
@@ -573,6 +574,7 @@
573
574
  },
574
575
  "cssTokens": [
575
576
  "--tui-checkbox-accent",
577
+ "--tui-checkbox-icon",
576
578
  "--tui-checkbox-border",
577
579
  "--tui-checkbox-border-hover",
578
580
  "--tui-checkbox-border-invalid",
@@ -2370,6 +2372,8 @@
2370
2372
  "--tui-nav-menu-icon-gap",
2371
2373
  "--tui-nav-menu-indicator-width",
2372
2374
  "--tui-nav-menu-indicator-color",
2375
+ "--tui-nav-menu-indicator-inset-block",
2376
+ "--tui-nav-menu-indicator-radius",
2373
2377
  "--tui-nav-menu-sub-indent",
2374
2378
  "--tui-nav-menu-sub-border",
2375
2379
  "--tui-nav-menu-bar-gap",
@@ -2467,7 +2471,7 @@
2467
2471
  "type": "\"center\" | \"start\"",
2468
2472
  "required": false,
2469
2473
  "defaultValue": "'center'",
2470
- "description": "Inline layout only: how the Head and Body sit on the row's cross axis.\n`center` (default) centres them; `start` top-aligns them and centres a\nlone Head icon on the Body's first line, for a multi-line Body (a bold\ntitle over a detail line). The Foot stays centred either way.\nPublished as `data-align`, not an is-align class (it would collide with the flex utility).\nIgnored (with a dev warning) without `inline`, and below the 400px\ncontainer width, where inline Notices fall back to stacked. No `end`:\nnothing needs a bottom-aligned row, and `start`'s first-line rule has no\n`end` counterpart."
2474
+ "description": "Inline layout only: how the Head and Body sit on the row's cross axis.\n`center` (default) centres them; `start` top-aligns them and centres a\nlone Head icon on the Body's first line, for a multi-line Body (a bold\ntitle over a detail line). The Foot stays centred either way.\nPublished as `data-align`, not an is-align class (it would collide with the flex utility).\nIgnored (with a dev warning) without `inline`, and below the 25rem (400px at a 16px root)\ncontainer width, where inline Notices fall back to stacked. No `end`:\nnothing needs a bottom-aligned row, and `start`'s first-line rule has no\n`end` counterpart."
2471
2475
  },
2472
2476
  "elevated": {
2473
2477
  "type": "boolean",
@@ -3892,6 +3896,9 @@
3892
3896
  "--tui-sidebar-border",
3893
3897
  "--tui-sidebar-divider",
3894
3898
  "--tui-sidebar-padding",
3899
+ "--tui-sidebar-header-padding",
3900
+ "--tui-sidebar-nav-padding",
3901
+ "--tui-sidebar-footer-padding",
3895
3902
  "--tui-sidebar-z"
3896
3903
  ],
3897
3904
  "story": {
@@ -41,14 +41,21 @@ export function useFocusTrap(containerRef, options) {
41
41
  const first = nodes[0];
42
42
  const last = nodes[nodes.length - 1];
43
43
  const active = document.activeElement;
44
+ // Wrap by position, not identity: focus can sit on something outside the
45
+ // Tab order (an autofocus heading or the container at tabindex="-1", an
46
+ // inactive roving option someone clicked). From before the first stop,
47
+ // Shift+Tab leaves the trap; from after the last, Tab does.
48
+ const inside = !!active && container.contains(active);
49
+ const beforeFirst = active === first || (inside && !!(first.compareDocumentPosition(active) & Node.DOCUMENT_POSITION_PRECEDING));
50
+ const afterLast = active === last || (inside && !!(last.compareDocumentPosition(active) & Node.DOCUMENT_POSITION_FOLLOWING));
44
51
  if (e.shiftKey) {
45
- if (active === first || !container.contains(active)) {
52
+ if (beforeFirst || !inside) {
46
53
  e.preventDefault();
47
54
  last.focus();
48
55
  }
49
56
  }
50
57
  else {
51
- if (active === last || !container.contains(active)) {
58
+ if (afterLast || !inside) {
52
59
  e.preventDefault();
53
60
  first.focus();
54
61
  }
@@ -27,7 +27,7 @@ export declare function findFocusTarget(container: HTMLElement, selector: string
27
27
  target: HTMLElement | null;
28
28
  problem?: string;
29
29
  };
30
- /** The focusable elements in `container` that can actually take focus, in DOM order. */
30
+ /** The elements in `container` that are in the Tab sequence and can take focus, in DOM order. */
31
31
  export declare function getTabbable(container: HTMLElement): HTMLElement[];
32
32
  /**
33
33
  * Finds the first focusable element within a container.
package/utils/tabbable.js CHANGED
@@ -5,7 +5,6 @@
5
5
  * Used by focus trap and initial focus logic.
6
6
  */
7
7
  export const FOCUSABLE_SELECTOR = [
8
- '[data-autofocus]',
9
8
  'a[href]',
10
9
  'area[href]',
11
10
  'button:not([disabled])',
@@ -16,6 +15,8 @@ export const FOCUSABLE_SELECTOR = [
16
15
  'audio[controls]',
17
16
  'video[controls]',
18
17
  '[contenteditable]:not([contenteditable="false"])',
18
+ // Only -1 is excluded here; getTabbable drops every negative value
19
+ // (isOutOfTabOrder), including -1 on a natively focusable element.
19
20
  '[tabindex]:not([tabindex="-1"])',
20
21
  ].join(',');
21
22
  /**
@@ -72,9 +73,21 @@ export function findFocusTarget(container, selector) {
72
73
  }
73
74
  return { target: match };
74
75
  }
75
- /** The focusable elements in `container` that can actually take focus, in DOM order. */
76
+ /**
77
+ * Whether `el` opted out of the Tab sequence with a negative `tabindex`: a
78
+ * roving group's inactive members (SegmentedControl, Tabs, Toolbar). The
79
+ * selector still matches them (`button:not([disabled])`), and as a trap's
80
+ * first or last edge they let Tab walk out of the dialog. Read from the
81
+ * attribute, since jsdom's `tabIndex` default differs from browsers'.
82
+ */
83
+ function isOutOfTabOrder(el) {
84
+ // An unparseable value (NaN) counts as in the order, as browsers ignore it.
85
+ const attr = el.getAttribute('tabindex');
86
+ return attr !== null && Number.parseInt(attr, 10) < 0;
87
+ }
88
+ /** The elements in `container` that are in the Tab sequence and can take focus, in DOM order. */
76
89
  export function getTabbable(container) {
77
- return Array.from(container.querySelectorAll(FOCUSABLE_SELECTOR)).filter((n) => isTabbable(n, container));
90
+ return Array.from(container.querySelectorAll(FOCUSABLE_SELECTOR)).filter((n) => !isOutOfTabOrder(n) && isTabbable(n, container));
78
91
  }
79
92
  /**
80
93
  * Finds the first focusable element within a container.
@@ -94,10 +107,12 @@ export function getInitialFocus(container, preferredSelector, { lastResort } = {
94
107
  return target;
95
108
  }
96
109
  // [data-autofocus] first, then DOM order, skipping anything that can't take focus.
97
- const tabbable = getTabbable(container);
98
- const autofocus = tabbable.find((n) => n.matches('[data-autofocus]'));
110
+ // A [data-autofocus] target may sit outside the Tab order (a heading with
111
+ // tabindex="-1"), so it's looked up on its own, not among the tabbables.
112
+ const autofocus = Array.from(container.querySelectorAll('[data-autofocus]')).find((n) => isFocusTarget(n, container));
99
113
  if (autofocus)
100
114
  return autofocus;
115
+ const tabbable = getTabbable(container);
101
116
  const first = lastResort ? tabbable.find((n) => !n.matches(lastResort)) : tabbable[0];
102
117
  return first ?? tabbable[0] ?? container;
103
118
  }
package/vanilla/modal.js CHANGED
@@ -53,7 +53,7 @@
53
53
  * Anything that portals to <body> (a React Select, a third-party datepicker)
54
54
  * renders under the top layer and is inert while a modal is open.
55
55
  */
56
- import { getTabbable, isTabbable } from '../utils/tabbable.js';
56
+ import { getTabbable, isFocusTarget } from '../utils/tabbable.js';
57
57
  import { lockScroll, unlockScroll } from '../utils/scroll-lock.js';
58
58
  const OPEN_ATTR = 'data-tui-modal-open';
59
59
  const CLOSE_ATTR = 'data-tui-modal-close';
@@ -186,7 +186,7 @@ function waitForExit(dialog) {
186
186
  }
187
187
  function initialFocus(box) {
188
188
  const preferred = box.querySelector('[autofocus], [data-autofocus]');
189
- if (preferred && isTabbable(preferred, box))
189
+ if (preferred && isFocusTarget(preferred, box))
190
190
  return preferred;
191
191
  const controls = getTabbable(box).filter((el) => !el.matches(EMBED_SELECTOR));
192
192
  return controls.find((el) => !el.matches(CLOSE_BUTTON_SELECTOR)) ?? controls[0] ?? box;
@@ -1 +1 @@
1
- (()=>{var Y=Object.defineProperty;var J=(t,e)=>{for(var n in e)Y(t,n,{get:e[n],enumerable:!0})};var D={};J(D,{MODAL_CLOSE_EVENT:()=>j,MODAL_OPEN_EVENT:()=>y,close:()=>p,init:()=>S,open:()=>K});var Q=["[data-autofocus]","a[href]","area[href]","button:not([disabled])",'input:not([disabled]):not([type="hidden"])',"select:not([disabled])","textarea:not([disabled])","iframe","audio[controls]","video[controls]",'[contenteditable]:not([contenteditable="false"])','[tabindex]:not([tabindex="-1"])'].join(",");function h(t,e){if(t.matches(":disabled")||t.closest("[inert]"))return!1;if(typeof t.checkVisibility=="function")return t.checkVisibility({visibilityProperty:!0});for(let n=t;n&&n!==e;n=n.parentElement){if(n.hidden)return!1;let o=getComputedStyle(n);if(o.display==="none"||n===t&&o.visibility==="hidden")return!1}return!0}function x(t){return Array.from(t.querySelectorAll(Q)).filter(e=>h(e,t))}var k="tui-modal-open",g="tuiScrollLock",C="--tui-scroll-lock-pad",w="--tui-scroll-lock-gutter",Z=["left","right"];function L(){return Number(document.body.dataset[g]??0)||0}function P(t){t.style.removeProperty(C);for(let e of Z)t.classList.remove(`tui-scroll-lock-pad-${e}`),t.style.removeProperty(`${w}-${e}`)}function _(){let t=document.body,e=L()===0;if(t.dataset[g]=String(L()+1),!e)return;P(t);let n=document.documentElement,o=n.clientWidth,r=t.getBoundingClientRect().left;t.classList.add(k);let i=n.clientWidth-o;if(i<=0)return;let l=t.getBoundingClientRect().left<r?"left":"right",a=parseFloat(getComputedStyle(t)[l==="left"?"paddingLeft":"paddingRight"])||0;t.style.setProperty(C,`${a+i}px`),t.style.setProperty(`${w}-${l}`,`${i}px`),t.classList.add(`tui-scroll-lock-pad-${l}`)}function O(){let t=document.body,e=L()-1;if(e>0){t.dataset[g]=String(e);return}delete t.dataset[g],t.classList.remove(k),P(t)}var b="data-tui-modal-open",c="data-tui-modal-close",tt="data-tui-modal-backdrop",M="data-tui-modal-src",R="data-tui-modal-restore-focus",et=".tui-modal__close",nt=":scope > .tui-modal__dialog",ot="iframe, object, embed, audio, video",it=1e3,y="tui-modal-open",j="tui-modal-close",m=new WeakMap,f=new WeakMap,B=new WeakSet,v=null,E=null,N=0;function s(t){console.warn(`[TUI modal] ${t}`)}function u(t){let e=t.getAttribute("data-state");return e==="open"||e==="closing"}function T(t){return t.querySelector(nt)}function I(t){return t.matches(":disabled")||t.closest('[aria-disabled="true"]')!==null}function z(t){if(typeof t!="string")return t;let e=document.getElementById(t);return e instanceof HTMLDialogElement?e:(s(e?`#${t} is a <${e.tagName.toLowerCase()}>, not a <dialog>. The modal must be a <dialog> element.`:`No element with id "${t}".`),null)}function q(t){return t.split(/\s+/).filter(e=>e&&!document.getElementById(e))}function rt(t){if(B.has(t))return;B.add(t);let e=`<dialog id="${t.id}">`,n=t.getAttribute("aria-labelledby"),o=t.getAttribute("aria-describedby");if(n){let i=q(n);i.length&&s(`${e} has aria-labelledby="${n}", but nothing has the id ${i.map(l=>`"${l}"`).join(", ")}, so the dialog has no name. Give the heading that id.`)}else t.hasAttribute("aria-label")||s(`${e} has no accessible name. Point aria-labelledby at its visible heading (WCAG 4.1.2).`);o&&q(o).length&&s(`${e} has aria-describedby="${o}", but not every id in it exists.`),t.getAttribute("role")==="alertdialog"&&!o&&s(`${e} is role="alertdialog" without aria-describedby. Point it at the message, or screen readers announce the heading and nothing about what is being confirmed.`),T(t)||s(`${e} has no .tui-modal__dialog box as its child. The box is the visible dialog; without it the backdrop can't be told apart and backdrop clicks are ignored.`),t.querySelector(`[${c}], form[method="dialog"]`)||Array.from(document.querySelectorAll(`[${c}]`)).some(i=>i.getAttribute(c)===t.id)||s(`${e} has no close control. Touch screen-reader users have no Escape key; add a button with ${c}.`)}function lt(t){let e=t.getAttribute(tt);return e==="dismiss"?!0:e==="static"?!1:t.getAttribute("role")!=="alertdialog"}function F(t){let e=getComputedStyle(t),n=i=>{let l=parseFloat(i);return Number.isNaN(l)?0:i.trim().endsWith("ms")?l:l*1e3},o=e.transitionDuration.split(","),r=e.transitionDelay.split(",");return Math.max(0,...o.map((i,l)=>n(i)+n(r[l%r.length]??"")))}function st(t){let e=T(t),n=Math.min(it,Math.max(F(t),e?F(e):0));return n>0?new Promise(o=>setTimeout(o,n)):Promise.resolve()}function at(t){let e=t.querySelector("[autofocus], [data-autofocus]");if(e&&h(e,t))return e;let n=x(t).filter(o=>!o.matches(ot));return n.find(o=>!o.matches(et))??n[0]??t}function K(t,e){let n=z(t);if(!n)return!1;if(n.getAttribute("data-state")==="closing")return f.delete(n),e&&m.set(n,e),n.setAttribute("data-state","open"),A(n,y,{opener:m.get(n)??null}),!0;if(n.open&&u(n))return!0;u(n)&&H(n),n.open&&(s(`<dialog id="${n.id}"> was already open, not as a modal. Drop the open attribute from the markup.`),n.close()),rt(n);try{n.showModal()}catch(a){return s(`<dialog id="${n.id}"> couldn't open: ${a.message}`),!1}_();let o=document.activeElement,r=e??(o instanceof HTMLElement&&o!==document.body?o:null);m.set(n,r);for(let a of n.querySelectorAll(`[${M}]`))a.hasAttribute("src")||a.setAttribute("src",a.getAttribute(M)??"");let i=T(n)??n,l=at(i);return l===i&&!i.hasAttribute("tabindex")&&(i.tabIndex=-1),l.focus(),n.offsetWidth,n.setAttribute("data-state","open"),A(n,y,{opener:r}),!0}function p(t){let e=z(t);if(!e?.open)return Promise.resolve();if(!u(e))return e.close(),Promise.resolve();let n=f.get(e);if(n)return n;e.setAttribute("data-state","closing");let o=st(e).then(()=>{f.get(e)===o&&(e.close(),H(e))});return f.set(e,o),o}function A(t,e,n){t.dispatchEvent(new CustomEvent(e,{bubbles:!0,detail:n}))}function H(t){if(!u(t))return;t.setAttribute("data-state","closed"),f.delete(t);for(let n of t.querySelectorAll("audio, video"))n.paused||n.pause();for(let n of t.querySelectorAll(`[${M}][src]`)){n.removeAttribute("src");let o=n.parentNode,r=n.nextSibling;n.remove(),o?.insertBefore(n,r)}O();let e=m.get(t)??null;m.delete(t),ct(t,e),A(t,j,{opener:e,returnValue:t.returnValue})}function ct(t,e){let n=t.getAttribute(R),o=[n?document.getElementById(n):null,e,...Array.from(document.querySelectorAll(`[${b}]`)).filter(r=>r.getAttribute(b)===t.id)];for(let r of o)if(!(!r?.isConnected||r===document.body)&&(r.focus(),document.activeElement===r))return;!e&&!n||s(`Focus had nowhere to return when <dialog id="${t.id}"> closed: its trigger is gone or can't take focus, so focus fell to <body> (WCAG 2.4.3). Set ${R}="<id>" on the dialog to name an element that will still be there.`)}function ut(t){return t.matches('a[href], input[type="submit"]')?!0:t instanceof HTMLButtonElement&&t.type==="submit"&&t.form!==null}function W(t){v=t.target,E=null}function U(t){E=t.target}function V(t){let e=v,n=E;v=E=null;let o=t.target;if(!(o instanceof Element))return;let r=o.closest(`[${b}]`);if(r){if(I(r))return;t.preventDefault(),K(r.getAttribute(b)??"",r);return}let i=o.closest(`[${c}]`);if(i){if(I(i))return;let a=i.getAttribute(c)||i.closest("dialog");if(!a){s(`A [${c}] control is outside any <dialog>. Give it the dialog's id as its value.`);return}ut(i)||t.preventDefault(),p(a);return}o instanceof HTMLDialogElement&&u(o)&&e===o&&n===o&&T(o)!==null&&lt(o)&&!dt(o,t)&&p(o)}function dt(t,e){let{clientWidth:n,clientHeight:o}=t;return n>0&&e.offsetX>=n||o>0&&e.offsetY>=o}function G(t){let e=t.target;!(e instanceof HTMLDialogElement)||!u(e)||t.cancelable&&(t.preventDefault(),p(e))}function X(t){let e=t.target;e instanceof HTMLDialogElement&&!e.open&&H(e)}function S(){N++===0&&(document.addEventListener("pointerdown",W,!0),document.addEventListener("pointerup",U,!0),document.addEventListener("click",V),document.addEventListener("cancel",G,!0),document.addEventListener("close",X,!0));let t=!1;return()=>{t||(t=!0,!(--N>0)&&(document.removeEventListener("pointerdown",W,!0),document.removeEventListener("pointerup",U,!0),document.removeEventListener("click",V),document.removeEventListener("cancel",G,!0),document.removeEventListener("close",X,!0)))}}var $=Symbol.for("tangible-ui/vanilla/modal"),d=globalThis;d[$]||(d[$]=D,S());d.TangibleUI=d.TangibleUI||{};d.TangibleUI.modal=d[$];})();
1
+ (()=>{var Q=Object.defineProperty;var Z=(t,e)=>{for(var n in e)Q(t,n,{get:e[n],enumerable:!0})};var S={};Z(S,{MODAL_CLOSE_EVENT:()=>K,MODAL_OPEN_EVENT:()=>M,close:()=>p,init:()=>H,open:()=>J});var $=["a[href]","area[href]","button:not([disabled])",'input:not([disabled]):not([type="hidden"])',"select:not([disabled])","textarea:not([disabled])","iframe","audio[controls]","video[controls]",'[contenteditable]:not([contenteditable="false"])','[tabindex]:not([tabindex="-1"])'].join(",");function x(t,e){if(t.matches(":disabled")||t.closest("[inert]"))return!1;if(typeof t.checkVisibility=="function")return t.checkVisibility({visibilityProperty:!0});for(let n=t;n&&n!==e;n=n.parentElement){if(n.hidden)return!1;let o=getComputedStyle(n);if(o.display==="none"||n===t&&o.visibility==="hidden")return!1}return!0}function k(t,e){return(t.matches($)||t.hasAttribute("tabindex"))&&x(t,e)}function tt(t){let e=t.getAttribute("tabindex");return e!==null&&Number.parseInt(e,10)<0}function C(t){return Array.from(t.querySelectorAll($)).filter(e=>!tt(e)&&x(e,t))}var w="tui-modal-open",g="tuiScrollLock",P="--tui-scroll-lock-pad",O="--tui-scroll-lock-gutter",et=["left","right"];function h(){return Number(document.body.dataset[g]??0)||0}function _(t){t.style.removeProperty(P);for(let e of et)t.classList.remove(`tui-scroll-lock-pad-${e}`),t.style.removeProperty(`${O}-${e}`)}function R(){let t=document.body,e=h()===0;if(t.dataset[g]=String(h()+1),!e)return;_(t);let n=document.documentElement,o=n.clientWidth,i=t.getBoundingClientRect().left;t.classList.add(w);let r=n.clientWidth-o;if(r<=0)return;let l=t.getBoundingClientRect().left<i?"left":"right",a=parseFloat(getComputedStyle(t)[l==="left"?"paddingLeft":"paddingRight"])||0;t.style.setProperty(P,`${a+r}px`),t.style.setProperty(`${O}-${l}`,`${r}px`),t.classList.add(`tui-scroll-lock-pad-${l}`)}function B(){let t=document.body,e=h()-1;if(e>0){t.dataset[g]=String(e);return}delete t.dataset[g],t.classList.remove(w),_(t)}var b="data-tui-modal-open",c="data-tui-modal-close",nt="data-tui-modal-backdrop",L="data-tui-modal-src",N="data-tui-modal-restore-focus",ot=".tui-modal__close",rt=":scope > .tui-modal__dialog",it="iframe, object, embed, audio, video",lt=1e3,M="tui-modal-open",K="tui-modal-close",m=new WeakMap,f=new WeakMap,I=new WeakSet,y=null,E=null,q=0;function s(t){console.warn(`[TUI modal] ${t}`)}function u(t){let e=t.getAttribute("data-state");return e==="open"||e==="closing"}function T(t){return t.querySelector(rt)}function F(t){return t.matches(":disabled")||t.closest('[aria-disabled="true"]')!==null}function Y(t){if(typeof t!="string")return t;let e=document.getElementById(t);return e instanceof HTMLDialogElement?e:(s(e?`#${t} is a <${e.tagName.toLowerCase()}>, not a <dialog>. The modal must be a <dialog> element.`:`No element with id "${t}".`),null)}function W(t){return t.split(/\s+/).filter(e=>e&&!document.getElementById(e))}function st(t){if(I.has(t))return;I.add(t);let e=`<dialog id="${t.id}">`,n=t.getAttribute("aria-labelledby"),o=t.getAttribute("aria-describedby");if(n){let r=W(n);r.length&&s(`${e} has aria-labelledby="${n}", but nothing has the id ${r.map(l=>`"${l}"`).join(", ")}, so the dialog has no name. Give the heading that id.`)}else t.hasAttribute("aria-label")||s(`${e} has no accessible name. Point aria-labelledby at its visible heading (WCAG 4.1.2).`);o&&W(o).length&&s(`${e} has aria-describedby="${o}", but not every id in it exists.`),t.getAttribute("role")==="alertdialog"&&!o&&s(`${e} is role="alertdialog" without aria-describedby. Point it at the message, or screen readers announce the heading and nothing about what is being confirmed.`),T(t)||s(`${e} has no .tui-modal__dialog box as its child. The box is the visible dialog; without it the backdrop can't be told apart and backdrop clicks are ignored.`),t.querySelector(`[${c}], form[method="dialog"]`)||Array.from(document.querySelectorAll(`[${c}]`)).some(r=>r.getAttribute(c)===t.id)||s(`${e} has no close control. Touch screen-reader users have no Escape key; add a button with ${c}.`)}function at(t){let e=t.getAttribute(nt);return e==="dismiss"?!0:e==="static"?!1:t.getAttribute("role")!=="alertdialog"}function U(t){let e=getComputedStyle(t),n=r=>{let l=parseFloat(r);return Number.isNaN(l)?0:r.trim().endsWith("ms")?l:l*1e3},o=e.transitionDuration.split(","),i=e.transitionDelay.split(",");return Math.max(0,...o.map((r,l)=>n(r)+n(i[l%i.length]??"")))}function ct(t){let e=T(t),n=Math.min(lt,Math.max(U(t),e?U(e):0));return n>0?new Promise(o=>setTimeout(o,n)):Promise.resolve()}function ut(t){let e=t.querySelector("[autofocus], [data-autofocus]");if(e&&k(e,t))return e;let n=C(t).filter(o=>!o.matches(it));return n.find(o=>!o.matches(ot))??n[0]??t}function J(t,e){let n=Y(t);if(!n)return!1;if(n.getAttribute("data-state")==="closing")return f.delete(n),e&&m.set(n,e),n.setAttribute("data-state","open"),v(n,M,{opener:m.get(n)??null}),!0;if(n.open&&u(n))return!0;u(n)&&A(n),n.open&&(s(`<dialog id="${n.id}"> was already open, not as a modal. Drop the open attribute from the markup.`),n.close()),st(n);try{n.showModal()}catch(a){return s(`<dialog id="${n.id}"> couldn't open: ${a.message}`),!1}R();let o=document.activeElement,i=e??(o instanceof HTMLElement&&o!==document.body?o:null);m.set(n,i);for(let a of n.querySelectorAll(`[${L}]`))a.hasAttribute("src")||a.setAttribute("src",a.getAttribute(L)??"");let r=T(n)??n,l=ut(r);return l===r&&!r.hasAttribute("tabindex")&&(r.tabIndex=-1),l.focus(),n.offsetWidth,n.setAttribute("data-state","open"),v(n,M,{opener:i}),!0}function p(t){let e=Y(t);if(!e?.open)return Promise.resolve();if(!u(e))return e.close(),Promise.resolve();let n=f.get(e);if(n)return n;e.setAttribute("data-state","closing");let o=ct(e).then(()=>{f.get(e)===o&&(e.close(),A(e))});return f.set(e,o),o}function v(t,e,n){t.dispatchEvent(new CustomEvent(e,{bubbles:!0,detail:n}))}function A(t){if(!u(t))return;t.setAttribute("data-state","closed"),f.delete(t);for(let n of t.querySelectorAll("audio, video"))n.paused||n.pause();for(let n of t.querySelectorAll(`[${L}][src]`)){n.removeAttribute("src");let o=n.parentNode,i=n.nextSibling;n.remove(),o?.insertBefore(n,i)}B();let e=m.get(t)??null;m.delete(t),dt(t,e),v(t,K,{opener:e,returnValue:t.returnValue})}function dt(t,e){let n=t.getAttribute(N),o=[n?document.getElementById(n):null,e,...Array.from(document.querySelectorAll(`[${b}]`)).filter(i=>i.getAttribute(b)===t.id)];for(let i of o)if(!(!i?.isConnected||i===document.body)&&(i.focus(),document.activeElement===i))return;!e&&!n||s(`Focus had nowhere to return when <dialog id="${t.id}"> closed: its trigger is gone or can't take focus, so focus fell to <body> (WCAG 2.4.3). Set ${N}="<id>" on the dialog to name an element that will still be there.`)}function mt(t){return t.matches('a[href], input[type="submit"]')?!0:t instanceof HTMLButtonElement&&t.type==="submit"&&t.form!==null}function V(t){y=t.target,E=null}function G(t){E=t.target}function X(t){let e=y,n=E;y=E=null;let o=t.target;if(!(o instanceof Element))return;let i=o.closest(`[${b}]`);if(i){if(F(i))return;t.preventDefault(),J(i.getAttribute(b)??"",i);return}let r=o.closest(`[${c}]`);if(r){if(F(r))return;let a=r.getAttribute(c)||r.closest("dialog");if(!a){s(`A [${c}] control is outside any <dialog>. Give it the dialog's id as its value.`);return}mt(r)||t.preventDefault(),p(a);return}o instanceof HTMLDialogElement&&u(o)&&e===o&&n===o&&T(o)!==null&&at(o)&&!ft(o,t)&&p(o)}function ft(t,e){let{clientWidth:n,clientHeight:o}=t;return n>0&&e.offsetX>=n||o>0&&e.offsetY>=o}function j(t){let e=t.target;!(e instanceof HTMLDialogElement)||!u(e)||t.cancelable&&(t.preventDefault(),p(e))}function z(t){let e=t.target;e instanceof HTMLDialogElement&&!e.open&&A(e)}function H(){q++===0&&(document.addEventListener("pointerdown",V,!0),document.addEventListener("pointerup",G,!0),document.addEventListener("click",X),document.addEventListener("cancel",j,!0),document.addEventListener("close",z,!0));let t=!1;return()=>{t||(t=!0,!(--q>0)&&(document.removeEventListener("pointerdown",V,!0),document.removeEventListener("pointerup",G,!0),document.removeEventListener("click",X),document.removeEventListener("cancel",j,!0),document.removeEventListener("close",z,!0)))}}var D=Symbol.for("tangible-ui/vanilla/modal"),d=globalThis;d[D]||(d[D]=S,H());d.TangibleUI=d.TangibleUI||{};d.TangibleUI.modal=d[D];})();