@cahyo-dimas/freeday 3.17.0 → 3.19.0

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.
package/dist/freeday.js CHANGED
@@ -251,6 +251,7 @@
251
251
  root.dataset.fdyAcReady = '1';
252
252
 
253
253
  var input = root.querySelector('input[role="combobox"]') || root.querySelector('input');
254
+ root._fdyInvalid = !!input && input.getAttribute('aria-invalid') === 'true';
254
255
  var listbox = root.querySelector('[role="listbox"]');
255
256
  if (!input || !listbox) return;
256
257
  var options = Array.prototype.slice.call(listbox.querySelectorAll('[role="option"]'));
@@ -285,6 +286,7 @@
285
286
  input.removeAttribute('aria-activedescendant');
286
287
  active = -1;
287
288
  clearHighlight();
289
+ showAll();
288
290
  document.removeEventListener('click', onDocClick, true);
289
291
  }
290
292
  function onDocClick(e) { if (!root.contains(e.target)) close(); }
@@ -299,6 +301,14 @@
299
301
  vis[i].scrollIntoView({ block: 'nearest' });
300
302
  }
301
303
 
304
+ /* A list opens whole; only typing narrows it. A value that was already in the field (a default,
305
+ a saved record) is not a query, and filtering by it opened a one-item list that looked broken
306
+ (#115). Reset on close, so the arrow keys reopen it whole as well. */
307
+ function showAll() {
308
+ options.forEach(function (o) { o.hidden = false; });
309
+ if (emptyEl) emptyEl.hidden = options.length !== 0;
310
+ }
311
+
302
312
  function applyFilter() {
303
313
  var q = input.value.trim().toLowerCase();
304
314
  var shown = 0;
@@ -322,7 +332,11 @@
322
332
  }
323
333
 
324
334
  input.addEventListener('input', applyFilter);
325
- input.addEventListener('focus', function () { applyFilter(); });
335
+ input.addEventListener('focus', function () {
336
+ if (!listbox.hidden) return;
337
+ showAll();
338
+ open();
339
+ });
326
340
  input.addEventListener('keydown', function (e) {
327
341
  var vis = visible();
328
342
  switch (e.key) {
@@ -374,10 +388,14 @@
374
388
  if (!input || !state) return;
375
389
  if (state.disabled != null) input.disabled = !!state.disabled;
376
390
  if (state.readonly != null) input.readOnly = !!state.readonly;
377
- if (state.invalid != null) {
391
+ /* Only when the HOST changes it: an unchanged push must not erase what freeday-form.js painted (#114). */
392
+ if (state.invalid != null && !!state.invalid !== root._fdyInvalid) {
393
+ root._fdyInvalid = !!state.invalid;
378
394
  if (state.invalid) input.setAttribute('aria-invalid', 'true');
379
395
  else input.removeAttribute('aria-invalid');
380
396
  }
397
+ /* Native `required` on the input itself: it is editable, so constraint validation applies (#114). */
398
+ if (state.required != null) input.required = !!state.required;
381
399
  }
382
400
 
383
401
  window.FreedayAutocomplete = { init: initAutocomplete, initAll: initAll, setState: setState };
@@ -995,16 +1013,26 @@
995
1013
  trigger.disabled = stateDisabled;
996
1014
  if (stateReadonly) trigger.setAttribute('aria-readonly', 'true');
997
1015
  else trigger.removeAttribute('aria-readonly');
1016
+ if ((stateDisabled || stateReadonly) && !panel.hidden) close(false);
1017
+ }
1018
+ /* `invalid` is written only when the HOST changes it. A render-once host (Blazor) pushes every
1019
+ state on every parent re-render, and rewriting an unchanged `false` erased the mark
1020
+ freeday-form.js had painted, leaving its message under a field no longer red (#114). */
1021
+ function applyInvalid() {
998
1022
  if (stateInvalid) trigger.setAttribute('aria-invalid', 'true');
999
1023
  else trigger.removeAttribute('aria-invalid');
1000
1024
  wrap.classList.toggle('fdy-cascade--error', stateInvalid);
1001
- if ((stateDisabled || stateReadonly) && !panel.hidden) close(false);
1002
1025
  }
1003
1026
  function setState(next) {
1004
1027
  if (!next) return;
1005
1028
  if (next.disabled != null) stateDisabled = !!next.disabled;
1006
1029
  if (next.readonly != null) stateReadonly = !!next.readonly;
1007
- if (next.invalid != null) stateInvalid = !!next.invalid;
1030
+ if (next.invalid != null && !!next.invalid !== stateInvalid) {
1031
+ stateInvalid = !!next.invalid;
1032
+ applyInvalid();
1033
+ }
1034
+ /* `required` too: a render-once host (Blazor) has no other way to change it later (#114). */
1035
+ if (next.required != null) wrap.toggleAttribute('data-fdy-required', !!next.required);
1008
1036
  applyState();
1009
1037
  }
1010
1038
 
@@ -1065,6 +1093,7 @@
1065
1093
  }
1066
1094
 
1067
1095
  applyState();
1096
+ applyInvalid();
1068
1097
 
1069
1098
  var api = {
1070
1099
  wrap: wrap,
@@ -1201,15 +1230,26 @@
1201
1230
  countEl.textContent = textOf(dialog, 'selected', { n: n });
1202
1231
  }
1203
1232
 
1233
+ /* The row's `data-value`, else the text the field shows: what the group mirrors as its live
1234
+ value, so `freeday-form.js` can require a choose-from-list. Its input is readonly, which
1235
+ bars it from constraint validation, so a native `required` on it never refuses (#114). */
1236
+ function rowValue(row, key) {
1237
+ if (row.value != null && row.value !== '') return String(row.value);
1238
+ return row[key] != null ? String(row[key]) : '';
1239
+ }
1240
+
1204
1241
  function fillGroup(detail) {
1205
1242
  if (!activeGroup) return;
1243
+ var key = activeGroup.getAttribute('data-fdy-cfl-display') || 'value';
1244
+ activeGroup.setAttribute('data-value', detail.rows
1245
+ ? detail.rows.map(function (r) { return rowValue(r, key); }).join(',')
1246
+ : rowValue(detail.row, key));
1206
1247
  var input = activeGroup.querySelector('.fdy-input');
1207
1248
  if (input) {
1208
1249
  if (detail.rows) {
1209
1250
  var tpl = activeGroup.getAttribute('data-fdy-cfl-summary') || '{n} selected';
1210
1251
  input.value = detail.rows.length ? tpl.replace('{n}', String(detail.rows.length)) : '';
1211
1252
  } else {
1212
- var key = activeGroup.getAttribute('data-fdy-cfl-display') || 'value';
1213
1253
  input.value = detail.row[key] != null ? detail.row[key] : (detail.row.value || '');
1214
1254
  }
1215
1255
  }
@@ -2701,16 +2741,26 @@
2701
2741
  trigger.disabled = stateDisabled;
2702
2742
  if (stateReadonly) trigger.setAttribute('aria-readonly', 'true');
2703
2743
  else trigger.removeAttribute('aria-readonly');
2744
+ if ((stateDisabled || stateReadonly) && !panel.hidden) close(false);
2745
+ }
2746
+ /* `invalid` is written only when the HOST changes it. A render-once host (Blazor) pushes every
2747
+ state on every parent re-render, and rewriting an unchanged `false` erased the mark
2748
+ freeday-form.js had painted, leaving its message under a field no longer red (#114). */
2749
+ function applyInvalid() {
2704
2750
  if (stateInvalid) trigger.setAttribute('aria-invalid', 'true');
2705
2751
  else trigger.removeAttribute('aria-invalid');
2706
2752
  wrap.classList.toggle('fdy-datepicker--error', stateInvalid);
2707
- if ((stateDisabled || stateReadonly) && !panel.hidden) close(false);
2708
2753
  }
2709
2754
  function setState(next) {
2710
2755
  if (!next) return;
2711
2756
  if (next.disabled != null) stateDisabled = !!next.disabled;
2712
2757
  if (next.readonly != null) stateReadonly = !!next.readonly;
2713
- if (next.invalid != null) stateInvalid = !!next.invalid;
2758
+ if (next.invalid != null && !!next.invalid !== stateInvalid) {
2759
+ stateInvalid = !!next.invalid;
2760
+ applyInvalid();
2761
+ }
2762
+ /* `required` too: a render-once host (Blazor) has no other way to change it later (#114). */
2763
+ if (next.required != null) wrap.toggleAttribute('data-fdy-required', !!next.required);
2714
2764
  applyState();
2715
2765
  }
2716
2766
 
@@ -2747,6 +2797,7 @@
2747
2797
  updateDisplay();
2748
2798
 
2749
2799
  applyState();
2800
+ applyInvalid();
2750
2801
 
2751
2802
  var api = {
2752
2803
  wrap: wrap,
@@ -3061,10 +3112,11 @@
3061
3112
  * data-fdy-required the app asking for it, on the control's ROOT
3062
3113
  * data-value the live value, which every value-bearing kit control now mirrors
3063
3114
  * and the element that takes aria-invalid and focus is found by `aria-haspopup`, which every
3064
- * popup-style kit trigger already sets. `FdyAutocomplete` and `FdyCfl` are absent on purpose:
3065
- * they render a real <input>, so the NATIVE `required` is what fits them, and routing them
3066
- * through here would give one field two sources of truth. No prop exposes that yet, which is a
3067
- * separate gap and is written down in NEXT-UP.md rather than half-closed here. */
3115
+ * popup-style kit trigger already sets. A choose-from-list belongs here too: its <input> is
3116
+ * `readonly`, and a readonly input is barred from constraint validation, so a native `required`
3117
+ * on it never refuses anything; its open button carries `aria-haspopup="dialog"`. An
3118
+ * autocomplete does NOT: its input is editable, so the native `required` is the one that fits,
3119
+ * and routing it through here would give one field two sources of truth (#114). */
3068
3120
  function kitRoots(form) {
3069
3121
  return Array.prototype.slice.call(form.querySelectorAll('[data-fdy-required]'));
3070
3122
  }
@@ -3076,6 +3128,9 @@
3076
3128
  }
3077
3129
 
3078
3130
  function kitMessage(root) {
3131
+ /* Read again on every pass, not only when the root was collected: a field required only under
3132
+ a condition loses the attribute while its error is still painted (#114). */
3133
+ if (!root.hasAttribute('data-fdy-required')) return '';
3079
3134
  if ((root.getAttribute('data-value') || '') !== '') return '';
3080
3135
  var form = root.closest('form');
3081
3136
  return root.getAttribute('data-fdy-msg-required')
@@ -3122,6 +3177,17 @@
3122
3177
  return custom || el.getAttribute('data-fdy-msg') || (alias && textOf(form, alias)) || el.validationMessage || textOf(form, 'invalid');
3123
3178
  }
3124
3179
 
3180
+ /* Two controls can share one `.fdy-field` and so one message slot: a date range's two ends, or two
3181
+ native inputs side by side. The slot is found per FIELD, so clearing the end that was filled
3182
+ used to erase the message the other end still needed, leaving it red with nothing to say why
3183
+ (#114). The slot is kept while any other control that points at it is still invalid. */
3184
+ function stillClaimed(errEl, except) {
3185
+ var scope = except.closest('form') || document;
3186
+ return Array.prototype.some.call(scope.querySelectorAll('[aria-invalid="true"]'), function (other) {
3187
+ return other !== except && (other.getAttribute('aria-describedby') || '').split(/\s+/).indexOf(errEl.id) !== -1;
3188
+ });
3189
+ }
3190
+
3125
3191
  function paint(el, message) {
3126
3192
  var errEl = ensureErrorEl(el);
3127
3193
  if (message) {
@@ -3130,6 +3196,7 @@
3130
3196
  errEl.hidden = false;
3131
3197
  } else {
3132
3198
  el.removeAttribute('aria-invalid');
3199
+ if (stillClaimed(errEl, el)) return;
3133
3200
  errEl.textContent = '';
3134
3201
  errEl.hidden = true;
3135
3202
  }
@@ -3187,7 +3254,7 @@
3187
3254
  root.dataset.fdyKitBound = '1';
3188
3255
  new MutationObserver(function () {
3189
3256
  if (submitted || eager) validateKit(root);
3190
- }).observe(root, { attributes: true, attributeFilter: ['data-value'] });
3257
+ }).observe(root, { attributes: true, attributeFilter: ['data-value', 'data-fdy-required'] });
3191
3258
  }
3192
3259
  function validateOne(el) {
3193
3260
  var msg = messageFor(el);
@@ -3901,6 +3968,7 @@
3901
3968
  var options = Array.prototype.slice.call(root.querySelectorAll('.fdy-combo__option'));
3902
3969
  if (!button || !listbox || !valueEl || options.length === 0) return;
3903
3970
  root.dataset.fdyComboReady = '1';
3971
+ root._fdyInvalid = button.getAttribute('aria-invalid') === 'true';
3904
3972
 
3905
3973
  seq += 1;
3906
3974
  if (!listbox.id) listbox.id = 'fdy-combo-list-' + seq;
@@ -4084,10 +4152,16 @@
4084
4152
  if (state.readonly) button.setAttribute('aria-readonly', 'true');
4085
4153
  else button.removeAttribute('aria-readonly');
4086
4154
  }
4087
- if (state.invalid != null) {
4155
+ /* `invalid` is written only when the HOST changes it. A render-once host (Blazor) pushes every
4156
+ state on every parent re-render, and rewriting an unchanged `false` erased the mark
4157
+ freeday-form.js had painted, leaving its message under a field no longer red (#114). */
4158
+ if (state.invalid != null && !!state.invalid !== root._fdyInvalid) {
4159
+ root._fdyInvalid = !!state.invalid;
4088
4160
  if (state.invalid) button.setAttribute('aria-invalid', 'true');
4089
4161
  else button.removeAttribute('aria-invalid');
4090
4162
  }
4163
+ /* `required` too: a render-once host (Blazor) has no other way to change it later (#114). */
4164
+ if (state.required != null) root.toggleAttribute('data-fdy-required', !!state.required);
4091
4165
  }
4092
4166
 
4093
4167
  window.FreedayCombo = { init: initCombo, initAll: initAll, setValue: setValue, setState: setState };
@@ -5456,16 +5530,26 @@
5456
5530
  trigger.disabled = stateDisabled;
5457
5531
  if (stateReadonly) trigger.setAttribute('aria-readonly', 'true');
5458
5532
  else trigger.removeAttribute('aria-readonly');
5533
+ if ((stateDisabled || stateReadonly) && !panel.hidden) close(false);
5534
+ }
5535
+ /* `invalid` is written only when the HOST changes it. A render-once host (Blazor) pushes every
5536
+ state on every parent re-render, and rewriting an unchanged `false` erased the mark
5537
+ freeday-form.js had painted, leaving its message under a field no longer red (#114). */
5538
+ function applyInvalid() {
5459
5539
  if (stateInvalid) trigger.setAttribute('aria-invalid', 'true');
5460
5540
  else trigger.removeAttribute('aria-invalid');
5461
5541
  wrap.classList.toggle('fdy-timepicker--error', stateInvalid);
5462
- if ((stateDisabled || stateReadonly) && !panel.hidden) close(false);
5463
5542
  }
5464
5543
  function setState(next) {
5465
5544
  if (!next) return;
5466
5545
  if (next.disabled != null) stateDisabled = !!next.disabled;
5467
5546
  if (next.readonly != null) stateReadonly = !!next.readonly;
5468
- if (next.invalid != null) stateInvalid = !!next.invalid;
5547
+ if (next.invalid != null && !!next.invalid !== stateInvalid) {
5548
+ stateInvalid = !!next.invalid;
5549
+ applyInvalid();
5550
+ }
5551
+ /* `required` too: a render-once host (Blazor) has no other way to change it later (#114). */
5552
+ if (next.required != null) wrap.toggleAttribute('data-fdy-required', !!next.required);
5469
5553
  applyState();
5470
5554
  }
5471
5555
 
@@ -5553,6 +5637,7 @@
5553
5637
 
5554
5638
  updateDisplay();
5555
5639
  applyState();
5640
+ applyInvalid();
5556
5641
 
5557
5642
  var api = {
5558
5643
  wrap: wrap,
@@ -68,7 +68,8 @@ wrapper, use the raw markup and hydrate it:
68
68
  2. Components only touch semantic tokens (`--color-*`), never the primitive ramp (`--azure-600`).
69
69
  3. `.fdy-btn` is already the primary action (there is no `--primary`). One per screen; everything
70
70
  else is `--ghost` or `--text`.
71
- 4. Three title roles only: `.fdy-title-page` (one `<h1>`) / `.fdy-title-section` / `.fdy-title-card`.
71
+ 4. Three title roles only: `.fdy-title-page` (one `<h1>`; `<h2>` inside `.fdy-app`, whose topbar title
72
+ is the `<h1>` and names the current page) / `.fdy-title-section` / `.fdy-title-card`.
72
73
  Never reuse a card title as a page title.
73
74
  5. Assemble from the frame down: `.fdy-app` → `.fdy-page` → `.fdy-page-section` → components.
74
75
  6. Form errors: `aria-invalid="true"` + `aria-describedby` → a `.fdy-help.fdy-help--error`.
@@ -198,7 +198,7 @@ live docs also have a copy button per component.
198
198
  ```bash
199
199
  npm i @cahyo-dimas/freeday
200
200
  ```
201
- Lands in `package.json` as `"@cahyo-dimas/freeday": "^3.17.0"` (public npm package). `dist/` is
201
+ Lands in `package.json` as `"@cahyo-dimas/freeday": "^3.19.0"` (public npm package). `dist/` is
202
202
  committed and published → no build step; `npm ci` runs without auth.
203
203
 
204
204
  ### 2. Import the CSS + enhancers **once** in your entry (`src/main.ts`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cahyo-dimas/freeday",
3
- "version": "3.17.0",
3
+ "version": "3.19.0",
4
4
  "description": "Freeday: token-driven, framework-agnostic UI KIT (design source-of-truth).",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -97,7 +97,7 @@
97
97
  "scripts": {
98
98
  "build": "node tokens/build.mjs",
99
99
  "test": "node --test",
100
- "test:browser": "node --test --test-concurrency=3 browser/color-mix.mjs browser/vanilla.mjs browser/adapter.mjs browser/layout.mjs browser/theme.mjs browser/state.mjs browser/root-init.mjs browser/upload-states.mjs browser/number.mjs browser/card-stretch.mjs browser/stretch-warn.mjs browser/hidden-attr.mjs browser/form-grid-rows.mjs browser/theme-pref.mjs browser/text-override.mjs browser/control-heights.mjs browser/field-width.mjs browser/cfl-multi.mjs browser/cfl-dialog-only.mjs browser/crowding.mjs browser/over-dialog.mjs browser/chart-scale.mjs browser/overlay-stack.mjs browser/chart-a11y.mjs browser/app-shell.mjs browser/bottom-nav.mjs browser/picker-states.mjs browser/tabs-strip.mjs browser/tabs-vertical.mjs browser/menu-align.mjs browser/cfl-narrow.mjs browser/form-reveal.mjs browser/confirm-search-copy.mjs browser/daterange-settled.mjs browser/display-parts.mjs browser/table-empty.mjs browser/table-footer-text.mjs browser/month-mode.mjs browser/monthpicker.mjs browser/page-columns.mjs browser/table-hover.mjs browser/typed-popover.mjs browser/filter-parity.mjs browser/filter-wrap.mjs browser/filter-stack.mjs browser/timepicker.mjs browser/form-kit-required.mjs browser/picker-in-modal.mjs browser/harness-contract.mjs browser/app-owned.mjs browser/sortable.mjs browser/modal-phone.mjs browser/empty-ref.mjs browser/stack-standalone.mjs",
100
+ "test:browser": "node --test --test-concurrency=3 browser/color-mix.mjs browser/vanilla.mjs browser/adapter.mjs browser/layout.mjs browser/theme.mjs browser/state.mjs browser/root-init.mjs browser/upload-states.mjs browser/number.mjs browser/card-stretch.mjs browser/stretch-warn.mjs browser/hidden-attr.mjs browser/form-grid-rows.mjs browser/theme-pref.mjs browser/text-override.mjs browser/control-heights.mjs browser/field-width.mjs browser/cfl-multi.mjs browser/cfl-dialog-only.mjs browser/crowding.mjs browser/over-dialog.mjs browser/chart-scale.mjs browser/overlay-stack.mjs browser/chart-a11y.mjs browser/app-shell.mjs browser/bottom-nav.mjs browser/picker-states.mjs browser/tabs-strip.mjs browser/tabs-vertical.mjs browser/menu-align.mjs browser/cfl-narrow.mjs browser/form-reveal.mjs browser/confirm-search-copy.mjs browser/daterange-settled.mjs browser/display-parts.mjs browser/table-empty.mjs browser/table-footer-text.mjs browser/month-mode.mjs browser/monthpicker.mjs browser/page-columns.mjs browser/table-hover.mjs browser/typed-popover.mjs browser/filter-parity.mjs browser/filter-wrap.mjs browser/filter-stack.mjs browser/timepicker.mjs browser/form-kit-required.mjs browser/form-required-rest.mjs browser/autocomplete-open.mjs browser/picker-in-modal.mjs browser/harness-contract.mjs browser/app-owned.mjs browser/sortable.mjs browser/modal-phone.mjs browser/empty-ref.mjs browser/stack-standalone.mjs",
101
101
  "prepack": "node tokens/build.mjs",
102
102
  "version": "node tokens/build.mjs && git add dist",
103
103
  "typecheck:react": "tsc -p adapters/react/tsconfig.json --noEmit",