tyrell-components 1.0.0-RC15 → 1.0.0-RC17

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 (108) hide show
  1. package/README.md +44 -52
  2. package/css/tyrell-colors-static.css +14 -0
  3. package/css/tyrell-theme.css +13 -7
  4. package/css/tyrell.css +15 -22
  5. package/dist/tyrell-colors-static.css +1 -1
  6. package/dist/tyrell-theme.css +1 -1
  7. package/dist/tyrell.css +1 -1
  8. package/dist/tyrell.js +1 -1
  9. package/lib/base/ty-component.d.ts +37 -15
  10. package/lib/base/ty-component.js +90 -26
  11. package/lib/components/button.d.ts +14 -0
  12. package/lib/components/button.js +61 -7
  13. package/lib/components/calendar-month.d.ts +7 -1
  14. package/lib/components/calendar-month.js +38 -30
  15. package/lib/components/calendar-navigation.d.ts +11 -0
  16. package/lib/components/calendar-navigation.js +68 -44
  17. package/lib/components/calendar.d.ts +52 -3
  18. package/lib/components/calendar.js +274 -61
  19. package/lib/components/checkbox.d.ts +8 -1
  20. package/lib/components/checkbox.js +29 -8
  21. package/lib/components/copy.d.ts +2 -0
  22. package/lib/components/copy.js +24 -33
  23. package/lib/components/date-picker.d.ts +68 -34
  24. package/lib/components/date-picker.js +386 -389
  25. package/lib/components/file-upload.d.ts +7 -0
  26. package/lib/components/file-upload.js +36 -4
  27. package/lib/components/input.d.ts +73 -3
  28. package/lib/components/input.js +159 -24
  29. package/lib/components/modal.d.ts +4 -8
  30. package/lib/components/modal.js +103 -33
  31. package/lib/components/option.js +7 -5
  32. package/lib/components/popup.js +117 -14
  33. package/lib/components/radio.d.ts +24 -0
  34. package/lib/components/radio.js +55 -32
  35. package/lib/components/resize-observer.js +2 -0
  36. package/lib/components/scroll-container.d.ts +3 -2
  37. package/lib/components/scroll-container.js +7 -8
  38. package/lib/components/select.d.ts +68 -11
  39. package/lib/components/select.js +196 -44
  40. package/lib/components/selected-tags.d.ts +7 -1
  41. package/lib/components/selected-tags.js +10 -1
  42. package/lib/components/switch.d.ts +9 -1
  43. package/lib/components/switch.js +29 -8
  44. package/lib/components/tab.d.ts +49 -1
  45. package/lib/components/tab.js +151 -10
  46. package/lib/components/tabs.d.ts +14 -2
  47. package/lib/components/tabs.js +185 -136
  48. package/lib/components/tag.d.ts +4 -7
  49. package/lib/components/tag.js +6 -7
  50. package/lib/components/textarea.d.ts +51 -5
  51. package/lib/components/textarea.js +95 -30
  52. package/lib/components/tooltip.d.ts +4 -3
  53. package/lib/components/tooltip.js +34 -24
  54. package/lib/components/wizard.d.ts +5 -4
  55. package/lib/components/wizard.js +120 -156
  56. package/lib/index.d.ts +2 -1
  57. package/lib/index.js +1 -0
  58. package/lib/styles/button.js +21 -19
  59. package/lib/styles/calendar-month.d.ts +3 -0
  60. package/lib/styles/calendar-month.js +43 -27
  61. package/lib/styles/calendar-navigation.d.ts +1 -1
  62. package/lib/styles/calendar-navigation.js +55 -26
  63. package/lib/styles/calendar.d.ts +3 -2
  64. package/lib/styles/calendar.js +77 -0
  65. package/lib/styles/checkbox.js +31 -13
  66. package/lib/styles/copy.js +5 -1
  67. package/lib/styles/date-picker.js +68 -26
  68. package/lib/styles/file-upload.d.ts +1 -1
  69. package/lib/styles/file-upload.js +3 -3
  70. package/lib/styles/icon.d.ts +1 -1
  71. package/lib/styles/icon.js +2 -2
  72. package/lib/styles/input.js +6 -10
  73. package/lib/styles/option.d.ts +1 -1
  74. package/lib/styles/option.js +7 -3
  75. package/lib/styles/popup.d.ts +1 -1
  76. package/lib/styles/popup.js +10 -5
  77. package/lib/styles/radio.js +18 -6
  78. package/lib/styles/scroll-container.d.ts +1 -1
  79. package/lib/styles/scroll-container.js +1 -1
  80. package/lib/styles/select-base.js +24 -3
  81. package/lib/styles/select.d.ts +1 -1
  82. package/lib/styles/select.js +10 -0
  83. package/lib/styles/step.d.ts +1 -1
  84. package/lib/styles/step.js +1 -9
  85. package/lib/styles/switch.js +14 -6
  86. package/lib/styles/tab.d.ts +1 -1
  87. package/lib/styles/tab.js +67 -3
  88. package/lib/styles/tabs.d.ts +1 -1
  89. package/lib/styles/tabs.js +7 -3
  90. package/lib/styles/tag.js +3 -3
  91. package/lib/styles/textarea.d.ts +1 -1
  92. package/lib/styles/textarea.js +7 -0
  93. package/lib/styles/wizard.d.ts +9 -5
  94. package/lib/styles/wizard.js +211 -99
  95. package/lib/types/common.d.ts +2 -2
  96. package/lib/utils/calendar-utils.d.ts +49 -0
  97. package/lib/utils/calendar-utils.js +63 -6
  98. package/lib/utils/property-manager.d.ts +7 -1
  99. package/lib/utils/property-manager.js +16 -4
  100. package/lib/utils/scroll-lock.d.ts +10 -4
  101. package/lib/utils/scroll-lock.js +102 -2
  102. package/lib/utils/upgrade-properties.d.ts +21 -0
  103. package/lib/utils/upgrade-properties.js +47 -0
  104. package/lib/utils/validity.d.ts +122 -0
  105. package/lib/utils/validity.js +289 -0
  106. package/lib/version.d.ts +1 -1
  107. package/lib/version.js +1 -1
  108. package/package.json +27 -5
@@ -1,5 +1,7 @@
1
1
  import { lockScroll, unlockScroll } from '../utils/scroll-lock.js';
2
+ import { coerceBoolean } from '../utils/property-manager.js';
2
3
  import { ensureStyles } from '../utils/styles.js';
4
+ import { upgradeProperties } from '../utils/upgrade-properties.js';
3
5
  import { modalStyles } from '../styles/modal.js';
4
6
  const backdropClickHandlers = new WeakMap();
5
7
  const escapeKeyHandlers = new WeakMap();
@@ -8,6 +10,13 @@ const hoverEnterHandlers = new WeakMap();
8
10
  const hoverLeaveHandlers = new WeakMap();
9
11
  const modalIds = new WeakMap();
10
12
  const pendingCloseReasons = new WeakMap();
13
+ const detachedOpen = new WeakSet();
14
+ const openStack = [];
15
+ function dropFromStack(el) {
16
+ const i = openStack.indexOf(el);
17
+ if (i >= 0)
18
+ openStack.splice(i, 1);
19
+ }
11
20
  const CLOSE_ICON = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-x-icon lucide-x"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>`;
12
21
  function parseBoolAttr(el, name) {
13
22
  if (!el.hasAttribute(name)) {
@@ -22,17 +31,9 @@ return true;
22
31
  function getModalAttributes(el) {
23
32
  return {
24
33
  open: parseBoolAttr(el, 'open'),
25
- backdrop: el.hasAttribute('backdrop') ? parseBoolAttr(el, 'backdrop') : true,
26
- closeOnOutsideClick: parseBoolAttr(el, 'prevent-outside-click')
27
- ? false
28
- : el.hasAttribute('close-on-outside-click')
29
- ? parseBoolAttr(el, 'close-on-outside-click')
30
- : true,
31
- closeOnEscape: parseBoolAttr(el, 'prevent-escape')
32
- ? false
33
- : el.hasAttribute('close-on-escape')
34
- ? parseBoolAttr(el, 'close-on-escape')
35
- : true,
34
+ backdrop: !parseBoolAttr(el, 'no-backdrop'),
35
+ closeOnOutsideClick: !parseBoolAttr(el, 'prevent-outside-click'),
36
+ closeOnEscape: !parseBoolAttr(el, 'prevent-escape'),
36
37
  };
37
38
  }
38
39
  function getModalDialog(shadowRoot) {
@@ -105,13 +106,72 @@ event.preventDefault();
105
106
  closeModal(el, 'backdrop');
106
107
  }
107
108
  }
109
+ function fromNestedDialog(dialog, event) {
110
+ for (const node of event.composedPath()) {
111
+ if (node === dialog)
112
+ return false;
113
+ if (node instanceof HTMLDialogElement && node.matches(':modal'))
114
+ return true;
115
+ }
116
+ return false;
117
+ }
118
+ function closeNestedDialogs(root) {
119
+ walkNested(root, (node) => {
120
+ if (node instanceof TyModal && node.open)
121
+ node.removeAttribute('open');
122
+ if (node instanceof HTMLDialogElement && node.matches(':modal'))
123
+ node.close();
124
+ return false;
125
+ });
126
+ }
127
+ function hasOpenNestedDialog(root) {
128
+ return walkNested(root, (node) => node instanceof HTMLDialogElement && node.matches(':modal'));
129
+ }
130
+ function walkNested(root, visit, seen = new WeakSet()) {
131
+ const walk = (node) => {
132
+ if (seen.has(node))
133
+ return false;
134
+ seen.add(node);
135
+ if (visit(node))
136
+ return true;
137
+ if (node.shadowRoot && walkNested(node.shadowRoot, visit, seen))
138
+ return true;
139
+ if (node instanceof HTMLSlotElement) {
140
+ for (const assigned of node.assignedElements({ flatten: true })) {
141
+ if (walk(assigned) || walkNested(assigned, visit, seen))
142
+ return true;
143
+ }
144
+ }
145
+ return false;
146
+ };
147
+ return Array.from(root.querySelectorAll('*')).some(walk);
148
+ }
108
149
  function handleEscapeKey(el, event) {
150
+ const dialog = event.currentTarget;
151
+ if (fromNestedDialog(dialog, event))
152
+ return;
109
153
  event.stopPropagation();
110
154
  if (event.key === 'Escape') {
111
155
  event.preventDefault();
112
156
  closeModal(el, 'escape');
113
157
  }
114
158
  }
159
+ function handleDocumentEscape(event) {
160
+ if (event.key !== 'Escape' || event.defaultPrevented)
161
+ return;
162
+ const top = openStack[openStack.length - 1];
163
+ if (!top)
164
+ return;
165
+ if (event.composedPath().some((n) => n instanceof HTMLDialogElement && n.open))
166
+ return;
167
+ if (hasOpenNestedDialog(top))
168
+ return;
169
+ event.preventDefault();
170
+ if (getModalAttributes(top).closeOnEscape)
171
+ closeModal(top, 'escape');
172
+ }
173
+ if (typeof document !== 'undefined')
174
+ document.addEventListener('keydown', handleDocumentEscape);
115
175
  function handleCloseButtonClick(el, event) {
116
176
  event.preventDefault();
117
177
  event.stopPropagation();
@@ -162,7 +222,7 @@ dialog.addEventListener('keydown', handler);
162
222
  }
163
223
  else {
164
224
  const handler = (e) => {
165
- if (e.key === 'Escape')
225
+ if (e.key === 'Escape' && !fromNestedDialog(dialog, e))
166
226
  e.preventDefault();
167
227
  };
168
228
  escapeKeyHandlers.set(el, handler);
@@ -247,19 +307,20 @@ setupCloseButtonHover(el, dialog);
247
307
  if (attributes.open) {
248
308
  if (!dialog.open) {
249
309
  lockScroll(modalId);
250
- if (attributes.backdrop) {
251
310
  dialog.showModal();
252
- }
253
- else {
254
- dialog.show();
255
- }
311
+ dropFromStack(el);
312
+ openStack.push(el);
256
313
  syncBackdropZoom();
314
+ if (!detachedOpen.delete(el))
257
315
  dispatchModalEvent(el, 'open', {});
258
316
  }
259
317
  }
260
318
  else {
319
+ detachedOpen.delete(el);
320
+ dropFromStack(el);
261
321
  if (dialog.open) {
262
322
  unlockScroll(modalId);
323
+ closeNestedDialogs(el);
263
324
  dialog.close();
264
325
  syncBackdropZoom();
265
326
  const reason = pendingCloseReasons.get(el) ?? 'programmatic';
@@ -267,10 +328,13 @@ pendingCloseReasons.delete(el);
267
328
  dispatchModalEvent(el, 'close', { reason });
268
329
  }
269
330
  }
331
+ syncBackdropZoom();
270
332
  dialog.onclose = (event) => {
271
- if (event.target !== dialog)
333
+ if (event.target !== dialog || dialog.open || !el.isConnected)
272
334
  return;
273
335
  unlockScroll(modalId);
336
+ dropFromStack(el);
337
+ closeNestedDialogs(el);
274
338
  if (el.hasAttribute('open')) {
275
339
  el.removeAttribute('open');
276
340
  dispatchModalEvent(el, 'close', {
@@ -282,16 +346,15 @@ syncBackdropZoom();
282
346
  };
283
347
  }
284
348
  function syncBackdropZoom() {
285
- const anyOpen = Array.from(document.querySelectorAll('ty-modal[open][backdrop-zoom], ty-dialog[open][backdrop-zoom]')).some((m) => {
286
- const v = m.getAttribute('backdrop-zoom').toLowerCase().trim();
287
- return v !== 'false' && v !== '0';
288
- });
289
- document.documentElement.classList.toggle('ty-modal-zoom', anyOpen);
349
+ const zoom = Array.from(document.querySelectorAll('ty-modal[open], ty-dialog[open]'))
350
+ .some((m) => parseBoolAttr(m, 'open') && !parseBoolAttr(m, 'no-backdrop') && !parseBoolAttr(m, 'no-zoom'));
351
+ document.documentElement.classList.toggle('ty-modal-zoom', zoom);
290
352
  }
291
353
  function cleanup(el) {
292
354
  const modalId = modalIds.get(el);
293
355
  const shadowRoot = el.shadowRoot;
294
356
  const dialog = shadowRoot ? getModalDialog(shadowRoot) : null;
357
+ dropFromStack(el);
295
358
  if (modalId) {
296
359
  unlockScroll(modalId);
297
360
  modalIds.delete(el);
@@ -299,6 +362,10 @@ modalIds.delete(el);
299
362
  syncBackdropZoom();
300
363
  if (!dialog)
301
364
  return;
365
+ if (dialog.open) {
366
+ dialog.close();
367
+ detachedOpen.add(el);
368
+ }
302
369
  const backdropHandler = backdropClickHandlers.get(el);
303
370
  if (backdropHandler) {
304
371
  dialog.removeEventListener('click', backdropHandler);
@@ -333,29 +400,32 @@ hoverLeaveHandlers.delete(el);
333
400
  }
334
401
  export class TyModal extends HTMLElement {
335
402
  static get observedAttributes() {
336
- return ['open', 'backdrop', 'close-on-outside-click', 'close-on-escape', 'prevent-outside-click', 'prevent-escape', 'label'];
403
+ return ['open', 'no-backdrop', 'no-zoom', 'prevent-outside-click', 'prevent-escape', 'label'];
337
404
  }
338
405
  get open() { return parseBoolAttr(this, 'open'); }
339
- set open(v) { v ? this.setAttribute('open', 'true') : this.removeAttribute('open'); }
340
- get backdrop() { return getModalAttributes(this).backdrop; }
341
- set backdrop(v) { this.setAttribute('backdrop', String(!!v)); }
342
- get closeOnOutsideClick() { return getModalAttributes(this).closeOnOutsideClick; }
343
- set closeOnOutsideClick(v) { this.setAttribute('close-on-outside-click', String(!!v)); }
344
- get closeOnEscape() { return getModalAttributes(this).closeOnEscape; }
345
- set closeOnEscape(v) { this.setAttribute('close-on-escape', String(!!v)); }
406
+ set open(v) { coerceBoolean(v) ? this.setAttribute('open', 'true') : this.removeAttribute('open'); }
407
+ get noBackdrop() { return parseBoolAttr(this, 'no-backdrop'); }
408
+ set noBackdrop(v) {
409
+ coerceBoolean(v) ? this.setAttribute('no-backdrop', '') : this.removeAttribute('no-backdrop');
410
+ }
411
+ get noZoom() { return parseBoolAttr(this, 'no-zoom'); }
412
+ set noZoom(v) {
413
+ coerceBoolean(v) ? this.setAttribute('no-zoom', '') : this.removeAttribute('no-zoom');
414
+ }
346
415
  get preventOutsideClick() { return parseBoolAttr(this, 'prevent-outside-click'); }
347
416
  set preventOutsideClick(v) {
348
- v ? this.setAttribute('prevent-outside-click', '') : this.removeAttribute('prevent-outside-click');
417
+ coerceBoolean(v) ? this.setAttribute('prevent-outside-click', '') : this.removeAttribute('prevent-outside-click');
349
418
  }
350
419
  get preventEscape() { return parseBoolAttr(this, 'prevent-escape'); }
351
420
  set preventEscape(v) {
352
- v ? this.setAttribute('prevent-escape', '') : this.removeAttribute('prevent-escape');
421
+ coerceBoolean(v) ? this.setAttribute('prevent-escape', '') : this.removeAttribute('prevent-escape');
353
422
  }
354
423
  constructor() {
355
424
  super();
356
425
  this.attachShadow({ mode: 'open' });
357
426
  }
358
427
  connectedCallback() {
428
+ upgradeProperties(this);
359
429
  render(this);
360
430
  this.show = () => openModal(this);
361
431
  this.hide = (opts) => closeModal(this, 'programmatic', opts);
@@ -1,4 +1,6 @@
1
1
  import { ensureStyles } from '../utils/styles.js';
2
+ import { coerceBoolean } from '../utils/property-manager.js';
3
+ import { upgradeProperties } from '../utils/upgrade-properties.js';
2
4
  import { optionStyles } from '../styles/option.js';
3
5
  const CHECK_SVG = `
4
6
  <svg class="option-check" viewBox="0 0 24 24" fill="none" stroke="currentColor"
@@ -22,11 +24,7 @@ static get observedAttributes() {
22
24
  return ['value', 'disabled', 'selected', 'highlighted', 'hidden'];
23
25
  }
24
26
  connectedCallback() {
25
- const instanceValue = Object.getOwnPropertyDescriptor(this, 'value');
26
- if (instanceValue) {
27
- this._value = instanceValue.value;
28
- delete this.value;
29
- }
27
+ upgradeProperties(this);
30
28
  this.render();
31
29
  }
32
30
  attributeChangedCallback(name, oldValue, newValue) {
@@ -80,6 +78,7 @@ get selected() {
80
78
  return this._selected;
81
79
  }
82
80
  set selected(value) {
81
+ value = coerceBoolean(value);
83
82
  if (this._selected !== value) {
84
83
  this._selected = value;
85
84
  if (value) {
@@ -95,6 +94,7 @@ get disabled() {
95
94
  return this._disabled;
96
95
  }
97
96
  set disabled(value) {
97
+ value = coerceBoolean(value);
98
98
  if (this._disabled !== value) {
99
99
  this._disabled = value;
100
100
  if (value) {
@@ -110,6 +110,7 @@ get highlighted() {
110
110
  return this._highlighted;
111
111
  }
112
112
  set highlighted(value) {
113
+ value = coerceBoolean(value);
113
114
  if (this._highlighted !== value) {
114
115
  this._highlighted = value;
115
116
  if (value) {
@@ -125,6 +126,7 @@ get hidden() {
125
126
  return this._hidden;
126
127
  }
127
128
  set hidden(value) {
129
+ value = coerceBoolean(value);
128
130
  if (this._hidden !== value) {
129
131
  this._hidden = value;
130
132
  if (value) {
@@ -5,9 +5,13 @@ import { popupStyles } from '../styles/popup.js';
5
5
  const anchorClickHandlers = new WeakMap();
6
6
  const anchorKeyClickHandlers = new WeakMap();
7
7
  const outsideClickHandlers = new WeakMap();
8
+ const closeTimers = new WeakMap();
8
9
  const escapeHandlers = new WeakMap();
9
10
  const closeRequestHandlers = new WeakMap();
10
11
  const popupIds = new WeakMap();
12
+ const anchors = new WeakMap();
13
+ const escapeGuards = new WeakMap();
14
+ const pointerPresses = new WeakSet();
11
15
  function parseBoolAttr(el, name) {
12
16
  return el.hasAttribute(name);
13
17
  }
@@ -74,27 +78,57 @@ dialog.classList.remove('preparing-animation');
74
78
  const anchor = getAnchorElement(el);
75
79
  if (anchor?.hasAttribute('aria-haspopup'))
76
80
  anchor.setAttribute('aria-expanded', 'false');
77
- setTimeout(() => {
81
+ const exitMs = Math.max(0, ...getComputedStyle(dialog).transitionDuration
82
+ .split(',').map((d) => parseFloat(d) * (d.trim().endsWith('ms') ? 1 : 1000)));
83
+ clearTimeout(closeTimers.get(el));
84
+ closeTimers.set(el, setTimeout(() => {
85
+ closeTimers.delete(el);
78
86
  dialog.classList.remove('position-calculated');
79
87
  dialog.close();
80
- }, 200);
88
+ }, exitMs + 20));
81
89
  }
82
90
  function openPopup(el) {
83
- const popupId = getPopupId(el);
84
- lockScroll(popupId);
85
91
  const shadowRoot = el.shadowRoot;
86
92
  const dialog = shadowRoot ? getPopupDialog(shadowRoot) : null;
87
- if (!dialog)
93
+ if (!dialog || !el.isConnected)
88
94
  return;
89
- dialog.showModal();
90
95
  const anchor = getAnchorElement(el);
96
+ if (dialog.open) {
97
+ const pending = closeTimers.get(el);
98
+ if (pending !== undefined) {
99
+ clearTimeout(pending);
100
+ closeTimers.delete(el);
101
+ dialog.classList.add('open');
102
+ if (anchor?.hasAttribute('aria-haspopup'))
103
+ anchor.setAttribute('aria-expanded', 'true');
104
+ }
105
+ return;
106
+ }
107
+ const popupId = getPopupId(el);
108
+ lockScroll(popupId);
109
+ dialog.showModal();
110
+ guardEscape(el);
91
111
  if (anchor?.hasAttribute('aria-haspopup'))
92
112
  anchor.setAttribute('aria-expanded', 'true');
93
113
  requestAnimationFrame(() => {
94
114
  updatePosition(el);
95
115
  dialog.classList.add('preparing-animation');
116
+ dialog.getBoundingClientRect();
96
117
  requestAnimationFrame(() => {
97
118
  dialog.classList.add('open');
119
+ if (!el.matches(':focus-within')) {
120
+ const target = el.querySelector('[autofocus]');
121
+ target?.focus({ preventScroll: true });
122
+ if (!el.matches(':focus-within')) {
123
+ dialog.focus({ preventScroll: true });
124
+ if (target) {
125
+ requestAnimationFrame(() => requestAnimationFrame(() => {
126
+ if (dialog.open && shadowRoot.activeElement === dialog)
127
+ target.focus({ preventScroll: true });
128
+ }));
129
+ }
130
+ }
131
+ }
98
132
  el.dispatchEvent(new CustomEvent('open'));
99
133
  });
100
134
  });
@@ -125,7 +159,36 @@ event.preventDefault();
125
159
  closePopup(el);
126
160
  }
127
161
  }
162
+ function fromNestedDialog(el, event) {
163
+ const dialog = el.shadowRoot ? getPopupDialog(el.shadowRoot) : null;
164
+ for (const node of event.composedPath()) {
165
+ if (node === dialog)
166
+ return false;
167
+ if (node instanceof HTMLDialogElement && node.matches(':modal'))
168
+ return true;
169
+ }
170
+ return false;
171
+ }
172
+ function guardEscape(el) {
173
+ if (escapeGuards.has(el))
174
+ return;
175
+ const guard = (e) => {
176
+ if (e.key === 'Escape' && getPopupAttributes(el).disableClose && !fromNestedDialog(el, e))
177
+ e.preventDefault();
178
+ };
179
+ escapeGuards.set(el, guard);
180
+ document.addEventListener('keydown', guard, true);
181
+ }
182
+ function unguardEscape(el) {
183
+ const guard = escapeGuards.get(el);
184
+ if (!guard)
185
+ return;
186
+ document.removeEventListener('keydown', guard, true);
187
+ escapeGuards.delete(el);
188
+ }
128
189
  function handleEscape(el, event) {
190
+ if (fromNestedDialog(el, event))
191
+ return;
129
192
  event.stopPropagation();
130
193
  if (event.key === 'Escape') {
131
194
  const { disableClose } = getPopupAttributes(el);
@@ -149,26 +212,39 @@ return;
149
212
  anchor.setAttribute('aria-haspopup', 'dialog');
150
213
  if (!anchor.hasAttribute('aria-expanded'))
151
214
  anchor.setAttribute('aria-expanded', 'false');
215
+ const previous = anchors.get(el) ?? anchor;
152
216
  const existingHandler = anchorClickHandlers.get(el);
153
217
  if (existingHandler) {
154
- anchor.removeEventListener('pointerdown', existingHandler);
218
+ previous.removeEventListener('pointerdown', existingHandler);
155
219
  }
156
220
  const existingKeyHandler = anchorKeyClickHandlers.get(el);
157
221
  if (existingKeyHandler) {
158
- anchor.removeEventListener('click', existingKeyHandler);
222
+ previous.removeEventListener('click', existingKeyHandler);
159
223
  }
160
- const handler = (e) => handleAnchorClick(el, e);
224
+ anchors.set(el, anchor);
225
+ const handler = (e) => {
226
+ pointerPresses.add(el);
227
+ handleAnchorClick(el, e);
228
+ };
161
229
  anchorClickHandlers.set(el, handler);
162
230
  anchor.addEventListener('pointerdown', handler);
163
231
  const keyHandler = (e) => {
164
- if (e.detail === 0)
232
+ if (pointerPresses.delete(el))
233
+ return;
234
+ const d = e.detail;
235
+ const click = typeof d === 'number' ? e : d?.originalEvent ?? e;
236
+ if (click.detail !== 0)
237
+ return;
238
+ if (click.composedPath().includes(el))
239
+ return;
165
240
  handleAnchorClick(el, e);
166
241
  };
167
242
  anchorKeyClickHandlers.set(el, keyHandler);
168
243
  anchor.addEventListener('click', keyHandler);
169
244
  }
170
245
  function cleanupAnchorEvents(el) {
171
- const anchor = getAnchorElement(el);
246
+ const anchor = anchors.get(el);
247
+ anchors.delete(el);
172
248
  const handler = anchorClickHandlers.get(el);
173
249
  if (anchor && handler) {
174
250
  anchor.removeEventListener('pointerdown', handler);
@@ -193,6 +269,7 @@ const dialog = document.createElement('dialog');
193
269
  const container = document.createElement('div');
194
270
  const content = document.createElement('slot');
195
271
  dialog.className = 'popup-dialog';
272
+ dialog.tabIndex = -1;
196
273
  container.className = 'popup-container';
197
274
  content.id = 'popup-content';
198
275
  shadowRoot.appendChild(dialog);
@@ -206,17 +283,40 @@ dialog.addEventListener('pointerdown', outsideHandler);
206
283
  const escapeHandler = (e) => handleEscape(el, e);
207
284
  escapeHandlers.set(el, escapeHandler);
208
285
  el.addEventListener('keydown', escapeHandler);
209
- dialog.addEventListener('close', () => {
210
- const popupId = getPopupId(el);
211
- unlockScroll(popupId);
286
+ const inertKeys = (e) => {
287
+ if ((e.key === 'Enter' || e.key === ' ') && e.composedPath()[0] === dialog)
288
+ e.preventDefault();
289
+ };
290
+ for (const type of ['keydown', 'keypress', 'keyup'])
291
+ dialog.addEventListener(type, inertKeys);
292
+ dialog.addEventListener('cancel', (e) => {
293
+ if (getPopupAttributes(el).disableClose)
294
+ e.preventDefault();
295
+ });
296
+ new MutationObserver(() => {
297
+ if (dialog.open)
298
+ return;
299
+ clearTimeout(closeTimers.get(el));
300
+ closeTimers.delete(el);
301
+ pointerPresses.delete(el);
302
+ unguardEscape(el);
303
+ unlockScroll(getPopupId(el));
212
304
  dialog.classList.remove('open');
213
305
  dialog.classList.remove('preparing-animation');
306
+ const anchor = getAnchorElement(el);
307
+ if (anchor?.hasAttribute('aria-haspopup'))
308
+ anchor.setAttribute('aria-expanded', 'false');
309
+ }).observe(dialog, { attributes: true, attributeFilter: ['open'] });
310
+ dialog.addEventListener('close', () => {
214
311
  el.dispatchEvent(new CustomEvent('close'));
215
312
  });
216
313
  }
217
314
  el.closePopup = () => closePopup(el, true);
218
315
  el.openPopup = () => openPopup(el);
219
316
  el.togglePopup = () => togglePopup(el);
317
+ const existingCloseRequest = closeRequestHandlers.get(el);
318
+ if (existingCloseRequest)
319
+ el.removeEventListener('ty:close-popup', existingCloseRequest);
220
320
  const closeRequestHandler = (e) => handleCloseRequest(el, e);
221
321
  closeRequestHandlers.set(el, closeRequestHandler);
222
322
  el.addEventListener('ty:close-popup', closeRequestHandler);
@@ -237,12 +337,15 @@ if (outsideHandler) {
237
337
  dialog.removeEventListener('pointerdown', outsideHandler);
238
338
  outsideClickHandlers.delete(el);
239
339
  }
340
+ if (dialog.open)
341
+ dialog.close();
240
342
  }
241
343
  const escapeHandler = escapeHandlers.get(el);
242
344
  if (escapeHandler) {
243
345
  el.removeEventListener('keydown', escapeHandler);
244
346
  escapeHandlers.delete(el);
245
347
  }
348
+ unguardEscape(el);
246
349
  const closeRequestHandler = closeRequestHandlers.get(el);
247
350
  if (closeRequestHandler) {
248
351
  el.removeEventListener('ty:close-popup', closeRequestHandler);
@@ -17,6 +17,7 @@ export interface TyRadioElement extends HTMLElement {
17
17
  flavor: Flavor;
18
18
  }
19
19
  export declare class TyRadio extends TyComponent<RadioState> implements TyRadioElement {
20
+ protected static labelClicks: boolean;
20
21
  protected static properties: {
21
22
  value: {
22
23
  type: "string";
@@ -48,7 +49,12 @@ export declare class TyRadio extends TyComponent<RadioState> implements TyRadioE
48
49
  private _clickHandler;
49
50
  private _focusHandler;
50
51
  private _blurHandler;
52
+ private _tabStop;
51
53
  constructor();
54
+ /** @internal Group-managed roving tabindex. */
55
+ setTabStop(on: boolean): void;
56
+ /** Focus the radio itself (the host is not focusable; its role element is). */
57
+ focus(options?: FocusOptions): void;
52
58
  protected onConnect(): void;
53
59
  protected onDisconnect(): void;
54
60
  protected onPropertiesChanged(changes: PropertyChange[]): void;
@@ -147,10 +153,28 @@ export declare class TyRadioGroup extends TyComponent<RadioGroupState> implement
147
153
  /**
148
154
  * Find ty-radio descendants in this group's light DOM. Searches deeply
149
155
  * because consumers may wrap each radio in a `<label>` for click delegation.
156
+ *
157
+ * Only upgraded radios: when a group is cloned from a template or set via
158
+ * innerHTML, elements upgrade in tree order, so the group's initial `value`
159
+ * sync runs while its radios are still plain HTMLElements. Writing
160
+ * checked/size/flavor onto those would create own properties that shadow
161
+ * the accessors after upgrade. Each radio fires ty-radio-connected once
162
+ * upgraded, which re-syncs the group.
150
163
  */
164
+ /** Focus the group's tab stop: the checked radio, else the first enabled one. */
165
+ focus(options?: FocusOptions): void;
151
166
  private getRadios;
152
167
  private syncChildren;
168
+ /** Report `required` to the owning form — without this the asterisk
169
+ showed but an empty group submitted anyway. The message is a native
170
+ radio's; it needs a name, a nameless radio never reports valueMissing. */
171
+ private updateValidity;
153
172
  private handleRadioSelect;
173
+ /**
174
+ * Select a value as the user did: input + change, like a native radio,
175
+ * whether by click, arrow keys or Space. Nothing fires when it is already selected.
176
+ */
177
+ private select;
154
178
  /**
155
179
  * Arrow-key navigation within group (W3C radio practice: arrow keys move
156
180
  * focus and selection together).