tyrell-components 1.0.0-RC16 → 1.0.0-RC18

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 (240) hide show
  1. package/README.md +1 -1
  2. package/css/tyrell-colors-static.css +1 -316
  3. package/css/tyrell-theme.css +1 -1471
  4. package/css/tyrell.css +1 -1385
  5. package/dist/tyrell-colors-static.css +1 -1
  6. package/dist/tyrell-theme.css +1 -1
  7. package/dist/tyrell.js +1 -1
  8. package/lib/base/ty-component.d.ts +28 -15
  9. package/lib/base/ty-component.js +81 -38
  10. package/lib/components/button.d.ts +14 -0
  11. package/lib/components/button.js +55 -7
  12. package/lib/components/calendar-month.d.ts +7 -1
  13. package/lib/components/calendar-month.js +35 -28
  14. package/lib/components/calendar-navigation.js +19 -6
  15. package/lib/components/calendar.d.ts +27 -3
  16. package/lib/components/calendar.js +107 -63
  17. package/lib/components/checkbox.d.ts +8 -1
  18. package/lib/components/checkbox.js +27 -6
  19. package/lib/components/copy.d.ts +2 -0
  20. package/lib/components/copy.js +15 -31
  21. package/lib/components/date-picker.d.ts +53 -18
  22. package/lib/components/date-picker.js +217 -146
  23. package/lib/components/file-upload.d.ts +4 -1
  24. package/lib/components/file-upload.js +23 -5
  25. package/lib/components/input.d.ts +73 -3
  26. package/lib/components/input.js +158 -22
  27. package/lib/components/modal.d.ts +2 -0
  28. package/lib/components/modal.js +97 -17
  29. package/lib/components/option.d.ts +19 -0
  30. package/lib/components/option.js +45 -31
  31. package/lib/components/popup.js +115 -15
  32. package/lib/components/radio.d.ts +10 -1
  33. package/lib/components/radio.js +22 -29
  34. package/lib/components/resize-observer.js +2 -0
  35. package/lib/components/scroll-container.js +2 -0
  36. package/lib/components/select.d.ts +150 -190
  37. package/lib/components/select.js +501 -796
  38. package/lib/components/selected-tags.d.ts +14 -4
  39. package/lib/components/selected-tags.js +35 -8
  40. package/lib/components/switch.d.ts +9 -1
  41. package/lib/components/switch.js +27 -6
  42. package/lib/components/tabs.js +1 -1
  43. package/lib/components/tag.d.ts +0 -9
  44. package/lib/components/tag.js +0 -11
  45. package/lib/components/textarea.d.ts +47 -2
  46. package/lib/components/textarea.js +81 -17
  47. package/lib/index.d.ts +1 -0
  48. package/lib/index.js +1 -0
  49. package/lib/styles/button.js +21 -19
  50. package/lib/styles/calendar-month.js +1 -1
  51. package/lib/styles/calendar.js +3 -0
  52. package/lib/styles/checkbox.js +11 -5
  53. package/lib/styles/date-picker.js +16 -4
  54. package/lib/styles/file-upload.d.ts +1 -1
  55. package/lib/styles/file-upload.js +3 -3
  56. package/lib/styles/icon.d.ts +1 -1
  57. package/lib/styles/icon.js +2 -2
  58. package/lib/styles/input.js +6 -10
  59. package/lib/styles/option.d.ts +1 -1
  60. package/lib/styles/option.js +6 -7
  61. package/lib/styles/popup.d.ts +1 -1
  62. package/lib/styles/popup.js +2 -0
  63. package/lib/styles/radio.js +12 -6
  64. package/lib/styles/select-base.js +22 -60
  65. package/lib/styles/select.d.ts +1 -1
  66. package/lib/styles/select.js +13 -2
  67. package/lib/styles/switch.js +10 -5
  68. package/lib/styles/tag.js +3 -5
  69. package/lib/styles/textarea.d.ts +1 -1
  70. package/lib/styles/textarea.js +7 -0
  71. package/lib/types/common.d.ts +3 -3
  72. package/lib/utils/calendar-utils.d.ts +49 -0
  73. package/lib/utils/calendar-utils.js +63 -6
  74. package/lib/utils/property-manager.d.ts +6 -5
  75. package/lib/utils/property-manager.js +14 -15
  76. package/lib/utils/scroll-lock.d.ts +10 -4
  77. package/lib/utils/scroll-lock.js +102 -2
  78. package/lib/utils/upgrade-properties.d.ts +21 -0
  79. package/lib/utils/upgrade-properties.js +47 -0
  80. package/lib/utils/validity.d.ts +98 -2
  81. package/lib/utils/validity.js +244 -8
  82. package/lib/version.d.ts +1 -1
  83. package/lib/version.js +1 -1
  84. package/package.json +8 -6
  85. package/lib/base/ty-component.d.ts.map +0 -1
  86. package/lib/base/ty-component.js.map +0 -1
  87. package/lib/components/button.d.ts.map +0 -1
  88. package/lib/components/button.js.map +0 -1
  89. package/lib/components/calendar-month.d.ts.map +0 -1
  90. package/lib/components/calendar-month.js.map +0 -1
  91. package/lib/components/calendar-navigation.d.ts.map +0 -1
  92. package/lib/components/calendar-navigation.js.map +0 -1
  93. package/lib/components/calendar.d.ts.map +0 -1
  94. package/lib/components/calendar.js.map +0 -1
  95. package/lib/components/checkbox.d.ts.map +0 -1
  96. package/lib/components/checkbox.js.map +0 -1
  97. package/lib/components/copy.d.ts.map +0 -1
  98. package/lib/components/copy.js.map +0 -1
  99. package/lib/components/date-picker.d.ts.map +0 -1
  100. package/lib/components/date-picker.js.map +0 -1
  101. package/lib/components/dropdown.d.ts +0 -403
  102. package/lib/components/dropdown.d.ts.map +0 -1
  103. package/lib/components/dropdown.js +0 -1315
  104. package/lib/components/dropdown.js.map +0 -1
  105. package/lib/components/icon.d.ts.map +0 -1
  106. package/lib/components/icon.js.map +0 -1
  107. package/lib/components/input.d.ts.map +0 -1
  108. package/lib/components/input.js.map +0 -1
  109. package/lib/components/modal.d.ts.map +0 -1
  110. package/lib/components/modal.js.map +0 -1
  111. package/lib/components/multiselect.d.ts +0 -389
  112. package/lib/components/multiselect.d.ts.map +0 -1
  113. package/lib/components/multiselect.js +0 -1301
  114. package/lib/components/multiselect.js.map +0 -1
  115. package/lib/components/option.d.ts.map +0 -1
  116. package/lib/components/option.js.map +0 -1
  117. package/lib/components/popup.d.ts.map +0 -1
  118. package/lib/components/popup.js.map +0 -1
  119. package/lib/components/resize-observer.d.ts.map +0 -1
  120. package/lib/components/resize-observer.js.map +0 -1
  121. package/lib/components/scroll-container.d.ts.map +0 -1
  122. package/lib/components/scroll-container.js.map +0 -1
  123. package/lib/components/step.d.ts.map +0 -1
  124. package/lib/components/step.js.map +0 -1
  125. package/lib/components/tab.d.ts.map +0 -1
  126. package/lib/components/tab.js.map +0 -1
  127. package/lib/components/tabs.d.ts.map +0 -1
  128. package/lib/components/tabs.js.map +0 -1
  129. package/lib/components/tag.d.ts.map +0 -1
  130. package/lib/components/tag.js.map +0 -1
  131. package/lib/components/textarea.d.ts.map +0 -1
  132. package/lib/components/textarea.js.map +0 -1
  133. package/lib/components/tooltip.d.ts.map +0 -1
  134. package/lib/components/tooltip.js.map +0 -1
  135. package/lib/components/wizard.d.ts.map +0 -1
  136. package/lib/components/wizard.js.map +0 -1
  137. package/lib/icons/fontawesome/brands.d.ts.map +0 -1
  138. package/lib/icons/fontawesome/brands.js.map +0 -1
  139. package/lib/icons/fontawesome/regular.d.ts.map +0 -1
  140. package/lib/icons/fontawesome/regular.js.map +0 -1
  141. package/lib/icons/fontawesome/solid.d.ts.map +0 -1
  142. package/lib/icons/fontawesome/solid.js.map +0 -1
  143. package/lib/icons/heroicons/micro.d.ts.map +0 -1
  144. package/lib/icons/heroicons/micro.js.map +0 -1
  145. package/lib/icons/heroicons/mini.d.ts.map +0 -1
  146. package/lib/icons/heroicons/mini.js.map +0 -1
  147. package/lib/icons/heroicons/outline.d.ts.map +0 -1
  148. package/lib/icons/heroicons/outline.js.map +0 -1
  149. package/lib/icons/heroicons/solid.d.ts.map +0 -1
  150. package/lib/icons/heroicons/solid.js.map +0 -1
  151. package/lib/icons/lucide.d.ts.map +0 -1
  152. package/lib/icons/lucide.js.map +0 -1
  153. package/lib/icons/material/filled.d.ts.map +0 -1
  154. package/lib/icons/material/filled.js.map +0 -1
  155. package/lib/icons/material/outlined.d.ts.map +0 -1
  156. package/lib/icons/material/outlined.js.map +0 -1
  157. package/lib/icons/material/round.d.ts.map +0 -1
  158. package/lib/icons/material/round.js.map +0 -1
  159. package/lib/icons/material/sharp.d.ts.map +0 -1
  160. package/lib/icons/material/sharp.js.map +0 -1
  161. package/lib/icons/material/two-tone.d.ts.map +0 -1
  162. package/lib/icons/material/two-tone.js.map +0 -1
  163. package/lib/index.d.ts.map +0 -1
  164. package/lib/index.js.map +0 -1
  165. package/lib/styles/button.d.ts.map +0 -1
  166. package/lib/styles/button.js.map +0 -1
  167. package/lib/styles/calendar-month.d.ts.map +0 -1
  168. package/lib/styles/calendar-month.js.map +0 -1
  169. package/lib/styles/calendar-navigation.d.ts.map +0 -1
  170. package/lib/styles/calendar-navigation.js.map +0 -1
  171. package/lib/styles/calendar.d.ts.map +0 -1
  172. package/lib/styles/calendar.js.map +0 -1
  173. package/lib/styles/copy.d.ts.map +0 -1
  174. package/lib/styles/copy.js.map +0 -1
  175. package/lib/styles/date-picker.d.ts.map +0 -1
  176. package/lib/styles/date-picker.js.map +0 -1
  177. package/lib/styles/dropdown.d.ts +0 -12
  178. package/lib/styles/dropdown.d.ts.map +0 -1
  179. package/lib/styles/dropdown.js +0 -725
  180. package/lib/styles/dropdown.js.map +0 -1
  181. package/lib/styles/icon.d.ts.map +0 -1
  182. package/lib/styles/icon.js.map +0 -1
  183. package/lib/styles/input.d.ts.map +0 -1
  184. package/lib/styles/input.js.map +0 -1
  185. package/lib/styles/modal.d.ts.map +0 -1
  186. package/lib/styles/modal.js.map +0 -1
  187. package/lib/styles/multiselect.d.ts +0 -6
  188. package/lib/styles/multiselect.d.ts.map +0 -1
  189. package/lib/styles/multiselect.js +0 -568
  190. package/lib/styles/multiselect.js.map +0 -1
  191. package/lib/styles/option.d.ts.map +0 -1
  192. package/lib/styles/option.js.map +0 -1
  193. package/lib/styles/popup.d.ts.map +0 -1
  194. package/lib/styles/popup.js.map +0 -1
  195. package/lib/styles/resize-observer.d.ts.map +0 -1
  196. package/lib/styles/resize-observer.js.map +0 -1
  197. package/lib/styles/scroll-container.d.ts.map +0 -1
  198. package/lib/styles/scroll-container.js.map +0 -1
  199. package/lib/styles/step.d.ts.map +0 -1
  200. package/lib/styles/step.js.map +0 -1
  201. package/lib/styles/tab.d.ts.map +0 -1
  202. package/lib/styles/tab.js.map +0 -1
  203. package/lib/styles/tabs.d.ts.map +0 -1
  204. package/lib/styles/tabs.js.map +0 -1
  205. package/lib/styles/tag.d.ts.map +0 -1
  206. package/lib/styles/tag.js.map +0 -1
  207. package/lib/styles/textarea.d.ts.map +0 -1
  208. package/lib/styles/textarea.js.map +0 -1
  209. package/lib/styles/tooltip.d.ts.map +0 -1
  210. package/lib/styles/tooltip.js.map +0 -1
  211. package/lib/styles/wizard.d.ts.map +0 -1
  212. package/lib/styles/wizard.js.map +0 -1
  213. package/lib/types/common.d.ts.map +0 -1
  214. package/lib/types/common.js.map +0 -1
  215. package/lib/utils/calendar-utils.d.ts.map +0 -1
  216. package/lib/utils/calendar-utils.js.map +0 -1
  217. package/lib/utils/icon-registry.d.ts.map +0 -1
  218. package/lib/utils/icon-registry.js.map +0 -1
  219. package/lib/utils/locale.d.ts.map +0 -1
  220. package/lib/utils/locale.js.map +0 -1
  221. package/lib/utils/number-format.d.ts.map +0 -1
  222. package/lib/utils/number-format.js.map +0 -1
  223. package/lib/utils/parse-boolean.d.ts +0 -39
  224. package/lib/utils/parse-boolean.d.ts.map +0 -1
  225. package/lib/utils/parse-boolean.js +0 -23
  226. package/lib/utils/parse-boolean.js.map +0 -1
  227. package/lib/utils/positioning.d.ts.map +0 -1
  228. package/lib/utils/positioning.js.map +0 -1
  229. package/lib/utils/property-capture.d.ts.map +0 -1
  230. package/lib/utils/property-capture.js.map +0 -1
  231. package/lib/utils/property-manager.d.ts.map +0 -1
  232. package/lib/utils/property-manager.js.map +0 -1
  233. package/lib/utils/resize-observer.d.ts.map +0 -1
  234. package/lib/utils/resize-observer.js.map +0 -1
  235. package/lib/utils/scroll-lock.d.ts.map +0 -1
  236. package/lib/utils/scroll-lock.js.map +0 -1
  237. package/lib/utils/styles.d.ts.map +0 -1
  238. package/lib/utils/styles.js.map +0 -1
  239. package/lib/version.d.ts.map +0 -1
  240. package/lib/version.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import { ensureStyles } from '../utils/styles.js';
2
2
  import { calendarNavigationStyles } from '../styles/calendar-navigation.js';
3
- import { getMonthName, parseISODate } from '../utils/calendar-utils.js';
3
+ import { getMonthName, parseDateDay } from '../utils/calendar-utils.js';
4
4
  import { getEffectiveLocale, observeLocaleChanges } from '../utils/locale.js';
5
5
  import { TyComponent } from '../base/ty-component.js';
6
6
  const CHEVRON_LEFT_SVG = `<?xml version='1.0' encoding='UTF-8'?>
@@ -31,6 +31,7 @@ onConnect() {
31
31
  this._state.displayMonth = this.displayMonth;
32
32
  this._state.displayYear = this.displayYear;
33
33
  this._localeObserver = observeLocaleChanges(this, () => {
34
+ if (!this.getProperty('locale'))
34
35
  this.render();
35
36
  });
36
37
  this.render();
@@ -122,8 +123,8 @@ static monthIndex(year, month) {
122
123
  return year * 12 + (month - 1);
123
124
  }
124
125
  boundIndices() {
125
- const min = parseISODate(this.min);
126
- const max = parseISODate(this.max);
126
+ const min = parseDateDay(this.min);
127
+ const max = parseDateDay(this.max);
127
128
  return {
128
129
  minIdx: min ? TyCalendarNavigation.monthIndex(min.year, min.month) : null,
129
130
  maxIdx: max ? TyCalendarNavigation.monthIndex(max.year, max.month) : null,
@@ -175,6 +176,12 @@ this.style.removeProperty('--nav-width');
175
176
  }
176
177
  const months = this.view === 'months';
177
178
  const monthName = getMonthName(this._state.displayMonth, this.locale, 'long');
179
+ const had = root.activeElement;
180
+ const place = !had ? null
181
+ : had.classList.contains('nav-title') ? 'title'
182
+ : had.className.includes('-prev') ? 'prev'
183
+ : had.className.includes('-next') ? 'next'
184
+ : null;
178
185
  root.innerHTML = '';
179
186
  const header = document.createElement('div');
180
187
  header.className = 'calendar-navigation-header';
@@ -206,11 +213,17 @@ const step = months ? 12 : 1;
206
213
  const unit = months ? 'year' : 'month';
207
214
  const arrows = document.createElement('div');
208
215
  arrows.className = 'nav-group nav-arrows';
209
- arrows.appendChild(this.createButton(`nav-btn nav-${unit}-prev`, `Previous ${unit}`, CHEVRON_LEFT_SVG, () => this.navigateBy(-step), this.isNavDisabled(-step)));
210
- arrows.appendChild(this.createButton(`nav-btn nav-${unit}-next`, `Next ${unit}`, CHEVRON_RIGHT_SVG, () => this.navigateBy(step), this.isNavDisabled(step)));
216
+ const prev = this.createButton(`nav-btn nav-${unit}-prev`, `Previous ${unit}`, CHEVRON_LEFT_SVG, () => this.navigateBy(-step), this.isNavDisabled(-step));
217
+ const next = this.createButton(`nav-btn nav-${unit}-next`, `Next ${unit}`, CHEVRON_RIGHT_SVG, () => this.navigateBy(step), this.isNavDisabled(step));
218
+ arrows.appendChild(prev);
219
+ arrows.appendChild(next);
211
220
  header.appendChild(title);
212
221
  header.appendChild(arrows);
213
222
  root.appendChild(header);
223
+ if (place) {
224
+ const successor = place === 'prev' ? prev : place === 'next' ? next : title;
225
+ (successor.disabled ? title : successor).focus({ preventScroll: true });
226
+ }
214
227
  }
215
228
  }
216
229
  TyCalendarNavigation.properties = {
@@ -251,7 +264,7 @@ return num;
251
264
  locale: {
252
265
  type: 'string',
253
266
  visual: true,
254
- default: 'en-US'
267
+ default: ''
255
268
  },
256
269
  size: {
257
270
  type: 'string',
@@ -50,6 +50,9 @@ export declare class TyCalendar extends HTMLElement {
50
50
  private _internals?;
51
51
  private _validity?;
52
52
  private _initialValue;
53
+ private _initialized;
54
+ private _valueSets;
55
+ private _pressing;
53
56
  private _localeObserver?;
54
57
  static formAssociated: boolean;
55
58
  static get observedAttributes(): string[];
@@ -63,6 +66,8 @@ export declare class TyCalendar extends HTMLElement {
63
66
  set max(value: string | undefined);
64
67
  get flavor(): string;
65
68
  set flavor(value: string);
69
+ get required(): boolean;
70
+ set required(value: boolean);
66
71
  get year(): number | undefined;
67
72
  set year(value: number | undefined);
68
73
  get month(): number | undefined;
@@ -84,7 +89,12 @@ export declare class TyCalendar extends HTMLElement {
84
89
  get customCSS(): CSSStyleSheet | undefined;
85
90
  set customCSS(sheet: CSSStyleSheet | undefined);
86
91
  get value(): string;
87
- set value(isoDate: string);
92
+ /**
93
+ * Reads what ty-date-picker reads: 'YYYY-MM-DD', 'YYYY-MM-DDTHH:mm[:ss]'
94
+ * (that day), an ISO instant with Z/offset or epoch ms / a Date (its local
95
+ * day). The value stays 'YYYY-MM-DD'; anything else is no value.
96
+ */
97
+ set value(isoDate: string | number | Date | null | undefined);
88
98
  /**
89
99
  * Initialize state from HTML attributes on first load
90
100
  */
@@ -94,8 +104,12 @@ export declare class TyCalendar extends HTMLElement {
94
104
  private syncChildComponents;
95
105
  private updateFormValue;
96
106
  /**
97
- * Selection outside [min, max] => rangeUnderflow/rangeOverflow.
98
- * UI can't produce this (days are disabled), but programmatic values can.
107
+ * required with no selection => valueMissing; a selection outside
108
+ * [min, max] => rangeUnderflow/rangeOverflow (UI can't pick one, days are
109
+ * disabled, but programmatic values can). With a native date input's
110
+ * message. The grid's tab stop is the anchor, so a submit focuses it and
111
+ * the browser shows its bubble there; the cells are rebuilt on every grid
112
+ * render, so each one runs this again.
99
113
  */
100
114
  private updateValidity;
101
115
  get form(): HTMLFormElement | null;
@@ -128,5 +142,15 @@ export declare class TyCalendar extends HTMLElement {
128
142
  private pickMonth;
129
143
  private handleKeydown;
130
144
  private focusNavTitle;
145
+ /**
146
+ * The grid's tab stop: the focused day, or month in the month view. When
147
+ * every day shown is disabled (a value outside min/max) there is none: then
148
+ * the selected day, or the first one; disabled cells still take focus.
149
+ * Disabled month cells don't (buttons): with every month of the year
150
+ * disabled, the navigation title (back to the days) stands in.
151
+ */
152
+ private gridCell;
153
+ /** Focus the grid's tab stop (see gridCell). */
154
+ focus(options?: FocusOptions): void;
131
155
  private focusDayGrid;
132
156
  }
@@ -1,10 +1,11 @@
1
1
  import { ensureStyles } from '../utils/styles.js';
2
+ import { liftProperties, upgradeProperties } from '../utils/upgrade-properties.js';
2
3
  import { calendarStyles } from '../styles/calendar.js';
3
4
  import './calendar-month.js';
4
5
  import './calendar-navigation.js';
5
- import { parseISODate, getMonthName } from '../utils/calendar-utils.js';
6
+ import { parseDateDay, formatISODay, toISODay, getMonthName, localMidnight, utcMidnight } from '../utils/calendar-utils.js';
6
7
  import { getEffectiveLocale, observeLocaleChanges } from '../utils/locale.js';
7
- import { ValidityController } from '../utils/validity.js';
8
+ import { ValidityController, nativeMessage } from '../utils/validity.js';
8
9
  function getCurrentDate() {
9
10
  const now = new Date();
10
11
  return {
@@ -31,14 +32,12 @@ const day = parseInt(dayStr, 10);
31
32
  const daysInMonth = new Date(year, month, 0).getDate();
32
33
  return day >= 1 && day <= daysInMonth ? day : null;
33
34
  }
34
- function formatDateISO(year, month, day) {
35
- const monthStr = month.toString().padStart(2, '0');
36
- const dayStr = day.toString().padStart(2, '0');
37
- return `${year}-${monthStr}-${dayStr}`;
35
+ function formatYear(year) {
36
+ return year.toString().padStart(4, '0');
38
37
  }
39
38
  export class TyCalendar extends HTMLElement {
40
39
  static get observedAttributes() {
41
- return ['value', 'year', 'month', 'day', 'hide-navigation', 'stateless', 'locale', 'name', 'size', 'width', 'min', 'max', 'flavor'];
40
+ return ['value', 'year', 'month', 'day', 'hide-navigation', 'stateless', 'locale', 'name', 'size', 'width', 'min', 'max', 'flavor', 'required'];
42
41
  }
43
42
  constructor() {
44
43
  super();
@@ -49,49 +48,27 @@ this._flavor = 'primary';
49
48
  this._view = 'days';
50
49
  this._dayGridHeight = 0;
51
50
  this._initialValue = '';
51
+ this._initialized = false;
52
+ this._valueSets = 0;
53
+ this._pressing = false;
52
54
  const current = getCurrentDate();
53
55
  this._state = {
54
56
  displayYear: current.year,
55
57
  displayMonth: current.month,
56
58
  };
57
- this.attachShadow({ mode: 'open' });
59
+ this.attachShadow({ mode: 'open', delegatesFocus: true });
60
+ liftProperties(this);
58
61
  if ('attachInternals' in this) {
59
62
  this._internals = this.attachInternals();
60
63
  this._validity = new ValidityController(this, this._internals);
61
64
  }
62
65
  }
63
66
  connectedCallback() {
67
+ if (!this._initialized) {
64
68
  this.initializeFromAttributes();
65
- const plainDayContentFn = this.dayContentFn;
66
- if (plainDayContentFn && !this._dayContentFn) {
67
- this._dayContentFn = plainDayContentFn;
68
- delete this.dayContentFn;
69
- }
70
- const plainCustomCSS = this.customCSS;
71
- if (plainCustomCSS && !this._customCSS) {
72
- this._customCSS = plainCustomCSS;
73
- delete this.customCSS;
74
- }
75
- const plainValue = this.value;
76
- if (plainValue && typeof plainValue === 'string' && plainValue !== this.value) {
77
- const match = plainValue.match(/^(\d{4})-(\d{2})-(\d{2})$/);
78
- if (match) {
79
- const year = parseInt(match[1], 10);
80
- const month = parseInt(match[2], 10);
81
- const day = parseInt(match[3], 10);
82
- this._state.selectedYear = year;
83
- this._state.selectedMonth = month;
84
- this._state.selectedDay = day;
85
- this._state.displayYear = year;
86
- this._state.displayMonth = month;
87
- if (!this._stateless) {
88
- this.setAttribute('year', year.toString());
89
- this.setAttribute('month', month.toString());
90
- this.setAttribute('day', day.toString());
91
- }
92
- }
93
- delete this.value;
69
+ this._initialized = true;
94
70
  }
71
+ upgradeProperties(this);
95
72
  this.render();
96
73
  this.updateFormValue();
97
74
  this._localeObserver = observeLocaleChanges(this, () => {
@@ -158,6 +135,9 @@ this[name === 'min' ? '_min' : '_max'] = newValue || undefined;
158
135
  this.syncChildComponents();
159
136
  this.updateValidity();
160
137
  break;
138
+ case 'required':
139
+ this.updateValidity();
140
+ break;
161
141
  case 'flavor':
162
142
  this._flavor = newValue || 'primary';
163
143
  this.syncChildComponents();
@@ -191,6 +171,12 @@ this.setAttribute('flavor', value);
191
171
  else
192
172
  this.removeAttribute('flavor');
193
173
  }
174
+ get required() {
175
+ return this.hasAttribute('required');
176
+ }
177
+ set required(value) {
178
+ this.toggleAttribute('required', !!value);
179
+ }
194
180
  get year() {
195
181
  return this._state.selectedYear;
196
182
  }
@@ -198,12 +184,12 @@ set year(value) {
198
184
  if (value !== undefined) {
199
185
  if (this._stateless) {
200
186
  this._state.displayYear = value;
201
- this.setAttribute('year', value.toString());
187
+ this.setAttribute('year', formatYear(value));
202
188
  }
203
189
  else {
204
190
  this._state.selectedYear = value;
205
191
  this._state.displayYear = value;
206
- this.setAttribute('year', value.toString());
192
+ this.setAttribute('year', formatYear(value));
207
193
  }
208
194
  }
209
195
  else {
@@ -332,35 +318,43 @@ this.syncChildComponents();
332
318
  get value() {
333
319
  const { selectedYear, selectedMonth, selectedDay } = this._state;
334
320
  if (selectedYear && selectedMonth && selectedDay) {
335
- return formatDateISO(selectedYear, selectedMonth, selectedDay);
321
+ return formatISODay(selectedYear, selectedMonth, selectedDay);
336
322
  }
337
323
  return '';
338
324
  }
339
325
  set value(isoDate) {
340
- if (!isoDate) {
326
+ const set = ++this._valueSets;
327
+ const superseded = () => set !== this._valueSets;
328
+ if (isoDate === null || isoDate === undefined || isoDate === '') {
341
329
  delete this._state.selectedYear;
342
330
  delete this._state.selectedMonth;
343
331
  delete this._state.selectedDay;
344
332
  if (!this._stateless) {
345
333
  this.removeAttribute('year');
334
+ if (superseded())
335
+ return;
346
336
  this.removeAttribute('month');
337
+ if (superseded())
338
+ return;
347
339
  this.removeAttribute('day');
348
340
  }
349
341
  }
350
342
  else {
351
- const match = isoDate.match(/^(\d{4})-(\d{2})-(\d{2})$/);
352
- if (match) {
353
- const year = parseInt(match[1], 10);
354
- const month = parseInt(match[2], 10);
355
- const day = parseInt(match[3], 10);
343
+ const parsed = parseDateDay(isoDate);
344
+ if (parsed) {
345
+ const { year, month, day } = parsed;
356
346
  this._state.selectedYear = year;
357
347
  this._state.selectedMonth = month;
358
348
  this._state.selectedDay = day;
359
349
  this._state.displayYear = year;
360
350
  this._state.displayMonth = month;
361
351
  if (!this._stateless) {
362
- this.setAttribute('year', year.toString());
352
+ this.setAttribute('year', formatYear(year));
353
+ if (superseded())
354
+ return;
363
355
  this.setAttribute('month', month.toString());
356
+ if (superseded())
357
+ return;
364
358
  this.setAttribute('day', day.toString());
365
359
  }
366
360
  }
@@ -471,13 +465,13 @@ this._monthDisplay.customCSS = this._customCSS;
471
465
  }
472
466
  const { selectedYear, selectedMonth, selectedDay } = this._state;
473
467
  if (selectedYear && selectedMonth && selectedDay) {
474
- const date = new Date(selectedYear, selectedMonth - 1, selectedDay);
475
- this._monthDisplay.value = date.getTime();
468
+ this._monthDisplay.value = localMidnight(selectedYear, selectedMonth, selectedDay).getTime();
476
469
  }
477
470
  else {
478
471
  this._monthDisplay.value = null;
479
472
  }
480
473
  }
474
+ this.updateValidity();
481
475
  }
482
476
  updateFormValue() {
483
477
  if (this._stateless)
@@ -487,7 +481,7 @@ return;
487
481
  const elementName = this.getAttribute('name');
488
482
  const { selectedYear, selectedMonth, selectedDay } = this._state;
489
483
  if (elementName && selectedYear && selectedMonth && selectedDay) {
490
- const isoDate = formatDateISO(selectedYear, selectedMonth, selectedDay);
484
+ const isoDate = formatISODay(selectedYear, selectedMonth, selectedDay);
491
485
  this._internals.setFormValue(isoDate);
492
486
  }
493
487
  else {
@@ -498,21 +492,27 @@ this.updateValidity();
498
492
  updateValidity() {
499
493
  if (!this._internals)
500
494
  return;
495
+ const anchor = this.gridCell() ?? undefined;
501
496
  const { selectedYear, selectedMonth, selectedDay } = this._state;
502
497
  if (selectedYear && selectedMonth && selectedDay) {
503
- const sel = Date.UTC(selectedYear, selectedMonth - 1, selectedDay);
504
- const min = this._min ? parseISODate(this._min) : null;
505
- const max = this._max ? parseISODate(this._max) : null;
506
- if (min && sel < Date.UTC(min.year, min.month - 1, min.day)) {
507
- this._validity.set({ rangeUnderflow: true }, `Date must be ${this._min} or later`);
498
+ const sel = utcMidnight(selectedYear, selectedMonth, selectedDay);
499
+ const min = this._min ? parseDateDay(this._min) : null;
500
+ const max = this._max ? parseDateDay(this._max) : null;
501
+ const message = () => nativeMessage('input', { type: 'date', min: toISODay(this._min) ?? undefined, max: toISODay(this._max) ?? undefined }, formatISODay(selectedYear, selectedMonth, selectedDay));
502
+ if (min && sel < utcMidnight(min.year, min.month, min.day)) {
503
+ this._validity.set({ rangeUnderflow: true }, message(), anchor);
508
504
  return;
509
505
  }
510
- if (max && sel > Date.UTC(max.year, max.month - 1, max.day)) {
511
- this._validity.set({ rangeOverflow: true }, `Date must be ${this._max} or earlier`);
506
+ if (max && sel > utcMidnight(max.year, max.month, max.day)) {
507
+ this._validity.set({ rangeOverflow: true }, message(), anchor);
512
508
  return;
513
509
  }
514
510
  }
515
- this._validity.set({});
511
+ else if (this.required) {
512
+ this._validity.set({ valueMissing: true }, nativeMessage('input', { type: 'date', required: true }), anchor);
513
+ return;
514
+ }
515
+ this._validity.set({}, undefined, anchor);
516
516
  }
517
517
  get form() { return this._internals?.form ?? null; }
518
518
  get validity() { return this._internals?.validity; }
@@ -562,7 +562,7 @@ this._state.selectedMonth = month;
562
562
  this._state.selectedDay = day;
563
563
  this._state.displayYear = year;
564
564
  this._state.displayMonth = month;
565
- this.setAttribute('year', year.toString());
565
+ this.setAttribute('year', formatYear(year));
566
566
  this.setAttribute('month', month.toString());
567
567
  this.setAttribute('day', day.toString());
568
568
  this.updateFormValue();
@@ -587,6 +587,7 @@ this.syncChildComponents();
587
587
  if (this._monthDisplay && typeof this._monthDisplay.refresh === 'function') {
588
588
  this._monthDisplay.refresh();
589
589
  }
590
+ this.updateValidity();
590
591
  }
591
592
  createNavigation() {
592
593
  const nav = document.createElement('ty-calendar-navigation');
@@ -622,8 +623,7 @@ month.width = this._width;
622
623
  }
623
624
  const { selectedYear, selectedMonth, selectedDay } = this._state;
624
625
  if (selectedYear && selectedMonth && selectedDay) {
625
- const date = new Date(selectedYear, selectedMonth - 1, selectedDay);
626
- month.value = date.getTime();
626
+ month.value = localMidnight(selectedYear, selectedMonth, selectedDay).getTime();
627
627
  }
628
628
  if (this._dayContentFn) {
629
629
  month.dayContentFn = this._dayContentFn;
@@ -632,6 +632,7 @@ if (this._customCSS) {
632
632
  month.customCSS = this._customCSS;
633
633
  }
634
634
  month.addEventListener('day-click', (e) => this.handleDayClick(e));
635
+ month.shadowRoot?.addEventListener('focusin', () => this.updateValidity());
635
636
  this._monthDisplay = month;
636
637
  return month;
637
638
  }
@@ -644,7 +645,23 @@ root.innerHTML = '';
644
645
  this._monthGrid = undefined;
645
646
  const container = document.createElement('div');
646
647
  container.className = 'calendar-container';
648
+ container.tabIndex = -1;
649
+ const press = () => {
650
+ this._pressing = true;
651
+ setTimeout(() => { this._pressing = false; });
652
+ };
653
+ container.addEventListener('pointerdown', press);
654
+ container.addEventListener('mousedown', press);
655
+ container.addEventListener('focus', () => {
656
+ if (this._pressing)
657
+ return;
658
+ queueMicrotask(() => {
659
+ if (this.shadowRoot?.activeElement === container)
660
+ this.gridCell()?.focus();
661
+ });
662
+ });
647
663
  container.addEventListener('keydown', (e) => this.handleKeydown(e));
664
+ container.addEventListener('focusin', () => this.updateValidity());
648
665
  this._container = container;
649
666
  if (!this._hideNavigation) {
650
667
  const nav = this.createNavigation();
@@ -655,6 +672,7 @@ container.appendChild(month);
655
672
  root.appendChild(container);
656
673
  if (this._view === 'months')
657
674
  this.showBody();
675
+ this.updateValidity();
658
676
  }
659
677
  setView(view) {
660
678
  if (view === this._view)
@@ -666,6 +684,7 @@ this._view = view;
666
684
  if (this._navigation)
667
685
  this._navigation.view = view;
668
686
  this.showBody();
687
+ this.updateValidity();
669
688
  }
670
689
  showBody() {
671
690
  const container = this._container;
@@ -691,8 +710,8 @@ static monthIndex(year, month) {
691
710
  return year * 12 + (month - 1);
692
711
  }
693
712
  boundIndices() {
694
- const min = this._min ? parseISODate(this._min) : null;
695
- const max = this._max ? parseISODate(this._max) : null;
713
+ const min = this._min ? parseDateDay(this._min) : null;
714
+ const max = this._max ? parseDateDay(this._max) : null;
696
715
  return {
697
716
  minIdx: min ? TyCalendar.monthIndex(min.year, min.month) : null,
698
717
  maxIdx: max ? TyCalendar.monthIndex(max.year, max.month) : null,
@@ -757,6 +776,11 @@ this.goTo(month, this._state.displayYear);
757
776
  this.focusDayGrid();
758
777
  }
759
778
  handleKeydown(e) {
779
+ if (e.target === this._container && e.key.startsWith('Arrow')) {
780
+ e.preventDefault();
781
+ this.gridCell()?.focus();
782
+ return;
783
+ }
760
784
  if (e.key === 'Escape' && this._view === 'months') {
761
785
  e.preventDefault();
762
786
  e.stopPropagation();
@@ -792,6 +816,26 @@ requestAnimationFrame(() => {
792
816
  this._navigation?.shadowRoot?.querySelector('.nav-title')?.focus();
793
817
  });
794
818
  }
819
+ gridCell() {
820
+ if (this._view === 'months') {
821
+ return this._monthGrid?.querySelector('.month-cell[tabindex="0"]:not(:disabled)')
822
+ ?? this._monthGrid?.querySelector('.month-cell:not(:disabled)')
823
+ ?? this._navigation?.shadowRoot?.querySelector('.nav-title')
824
+ ?? null;
825
+ }
826
+ const root = this._monthDisplay?.shadowRoot;
827
+ return root?.querySelector('.calendar-day-cell[tabindex="0"]')
828
+ ?? root?.querySelector('.calendar-day-cell.selected')
829
+ ?? root?.querySelector('.calendar-day-cell')
830
+ ?? null;
831
+ }
832
+ focus(options) {
833
+ const cell = this.gridCell();
834
+ if (cell)
835
+ cell.focus(options);
836
+ else
837
+ super.focus(options);
838
+ }
795
839
  focusDayGrid() {
796
840
  requestAnimationFrame(() => {
797
841
  const cell = this._monthDisplay?.shadowRoot?.querySelector('.calendar-day-cell[tabindex="0"]');
@@ -32,6 +32,8 @@ export interface TyCheckboxElement extends HTMLElement {
32
32
  */
33
33
  export declare class TyCheckbox extends TyComponent<CheckboxState> implements TyCheckboxElement {
34
34
  static formAssociated: boolean;
35
+ protected static delegatesFocus: boolean;
36
+ protected static labelClicks: boolean;
35
37
  protected static properties: {
36
38
  checked: {
37
39
  type: "boolean";
@@ -98,6 +100,9 @@ export declare class TyCheckbox extends TyComponent<CheckboxState> implements Ty
98
100
  protected getFormValue(): FormDataEntryValue | null;
99
101
  private buildClassList;
100
102
  private handleCheckboxClick;
103
+ /** The ring is for keyboard use: keys show it, a click hides it — also a
104
+ * <label>'s, which in Chromium focuses the box as :focus-visible. */
105
+ private showFocusRing;
101
106
  private handleCheckboxKeydown;
102
107
  private removeEventListeners;
103
108
  /**
@@ -110,7 +115,9 @@ export declare class TyCheckbox extends TyComponent<CheckboxState> implements Ty
110
115
  * Label, required asterisk, and error UI are the consumer's responsibility.
111
116
  */
112
117
  protected render(): void;
113
- /** required + unchecked => valueMissing; otherwise valid. */
118
+ /** Focus the checkbox itself (the host is not focusable; its role element is). */
119
+ focus(options?: FocusOptions): void;
120
+ /** required + unchecked => valueMissing (the browser's own message); otherwise valid. */
114
121
  private updateValidity;
115
122
  get checked(): boolean;
116
123
  set checked(value: boolean);
@@ -3,6 +3,7 @@ import { TyComponent } from "../base/ty-component.js";
3
3
  import { ensureStyles } from "../utils/styles.js";
4
4
  import { syncCustomFlavorSheet } from "../utils/flavor-sheet.js";
5
5
  import { checkboxStyles, checkboxCustomFlavorCss } from "../styles/checkbox.js";
6
+ import { nativeMessage } from "../utils/validity.js";
6
7
  const CHECK_ICON = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"><path d="M20 6 9 17l-5-5"/></svg>`;
7
8
  const DASH_ICON = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14"/></svg>`;
8
9
  export class TyCheckbox extends TyComponent {
@@ -20,6 +21,9 @@ ensureStyles(shadow, { css: checkboxStyles, id: "ty-checkbox" });
20
21
  onConnect() {
21
22
  this.setupEventListeners();
22
23
  this._syncCustomFlavor();
24
+ const el = this.shadowRoot.querySelector(".checkbox-container");
25
+ if (el && this.shadowRoot.activeElement !== el)
26
+ el.classList.remove("focused");
23
27
  }
24
28
  _syncCustomFlavor() {
25
29
  this._customFlavorSheet = syncCustomFlavorSheet(this.shadowRoot, this._customFlavorSheet, this.flavor, ({ base }) => checkboxCustomFlavorCss(base));
@@ -46,8 +50,7 @@ return classes.join(" ");
46
50
  handleCheckboxClick(e) {
47
51
  if (this.disabled)
48
52
  return;
49
- if (this.isDuplicateActivationClick())
50
- return;
53
+ this.showFocusRing(e instanceof KeyboardEvent);
51
54
  const newValue = this.indeterminate ? true : !this.checked;
52
55
  if (this.indeterminate)
53
56
  this.indeterminate = false;
@@ -71,6 +74,9 @@ composed: true,
71
74
  }));
72
75
  }, 0);
73
76
  }
77
+ showFocusRing(on) {
78
+ this.shadowRoot?.querySelector(".checkbox-container")?.classList.toggle("focused", on);
79
+ }
74
80
  handleCheckboxKeydown(e) {
75
81
  if (this.disabled)
76
82
  return;
@@ -123,7 +129,7 @@ this._keydownHandler = (e) => {
123
129
  this.handleCheckboxKeydown(e);
124
130
  };
125
131
  this._focusHandler = () => {
126
- checkboxEl.classList.add("focused");
132
+ checkboxEl.classList.toggle("focused", checkboxEl.matches(":focus-visible"));
127
133
  };
128
134
  this._blurHandler = () => {
129
135
  checkboxEl.classList.remove("focused");
@@ -142,7 +148,8 @@ const ariaChecked = this.indeterminate ? "mixed" : String(this.checked);
142
148
  if (!checkboxEl) {
143
149
  checkboxEl = document.createElement("div");
144
150
  checkboxEl.className = "checkbox-container " + classes;
145
- checkboxEl.tabIndex = this.disabled ? -1 : 0;
151
+ if (!this.disabled)
152
+ checkboxEl.tabIndex = 0;
146
153
  checkboxEl.setAttribute("role", "checkbox");
147
154
  checkboxEl.setAttribute("aria-checked", ariaChecked);
148
155
  checkboxEl.setAttribute("aria-disabled", String(this.disabled));
@@ -153,8 +160,13 @@ checkboxEl.appendChild(checkboxIcon);
153
160
  shadow.appendChild(checkboxEl);
154
161
  }
155
162
  else {
163
+ const focused = checkboxEl.classList.contains("focused") && shadow.activeElement === checkboxEl;
156
164
  checkboxEl.className = "checkbox-container " + classes;
157
- checkboxEl.tabIndex = this.disabled ? -1 : 0;
165
+ checkboxEl.classList.toggle("focused", focused && !this.disabled);
166
+ if (this.disabled)
167
+ checkboxEl.removeAttribute("tabindex");
168
+ else
169
+ checkboxEl.tabIndex = 0;
158
170
  checkboxEl.setAttribute("aria-checked", ariaChecked);
159
171
  checkboxEl.setAttribute("aria-disabled", String(this.disabled));
160
172
  checkboxEl.setAttribute("aria-required", String(this.required));
@@ -165,6 +177,13 @@ this.setupEventListeners();
165
177
  this.applyLabelName(checkboxEl);
166
178
  this.updateValidity();
167
179
  }
180
+ focus(options) {
181
+ const el = this.shadowRoot?.querySelector(".checkbox-container");
182
+ if (el)
183
+ el.focus(options);
184
+ else
185
+ super.focus(options);
186
+ }
168
187
  updateValidity() {
169
188
  const anchor = this.shadowRoot?.querySelector(".checkbox-container");
170
189
  if (this.disabled) {
@@ -172,7 +191,7 @@ this.applyValidity({});
172
191
  return;
173
192
  }
174
193
  if (this.required && !this.checked) {
175
- this.applyValidity({ valueMissing: true }, "Please check this box", anchor ?? undefined);
194
+ this.applyValidity({ valueMissing: true }, nativeMessage("input", { type: "checkbox", required: true }), anchor ?? undefined);
176
195
  }
177
196
  else {
178
197
  this.applyValidity({});
@@ -231,6 +250,8 @@ return this._internals.form;
231
250
  }
232
251
  }
233
252
  TyCheckbox.formAssociated = true;
253
+ TyCheckbox.delegatesFocus = true;
254
+ TyCheckbox.labelClicks = true;
234
255
  TyCheckbox.properties = {
235
256
  checked: {
236
257
  type: "boolean",
@@ -109,6 +109,8 @@ export declare class TyCopy extends TyComponent<CopyState> implements TyCopyElem
109
109
  * Uses state flag so render() can show the correct icon
110
110
  */
111
111
  private showCopySuccess;
112
+ /** Feedback over: the copy icon again. */
113
+ private resetCopyButton;
112
114
  /**
113
115
  * Show copy error animation
114
116
  * Swaps copy icon → red X icon → copy icon