@cahyo-dimas/freeday 3.17.0 → 3.18.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/CHANGELOG.md CHANGED
@@ -9,6 +9,64 @@ benar. Perubahan seperti itu ditulis di bawah `### Changed: BREAKING (types)`
9
9
  lama → tipe baru, dan cara menyempitkannya — bukan di bawah `### Added`, betapapun aditifnya dari
10
10
  sisi kit.
11
11
 
12
+ ## [3.18.0] - 2026-11-07
13
+
14
+ **Setiap kontrol bernilai kini dapat dijadikan wajib, di ketiga stack.** 3.12.0 (`#096`) memberi
15
+ `required` ke lima kontrol berpemicu tombol dan meninggalkan tiga (`CATATAN-FREEDAY.md` §24).
16
+ Akibatnya, menukar isian wajib ke `FdyAutocomplete` **membuang validasinya tanpa suara**: tidak ada
17
+ galat dan tidak ada peringatan. Formulirnya hanya berhenti menuntut isian itu. Audit kelasnya
18
+ menemukan dua kontrol lain dengan celah yang sama, dua cacat di aturan validasinya sendiri, dan
19
+ satu cacat di semua jembatan Blazor.
20
+
21
+ ### Added
22
+ - **`required` di `FdyAutocomplete`** (`#114`), Vue · React · Blazor (`Required`). Ini `required`
23
+ **native**, dipasang di input-nya. Input itu dapat disunting, jadi validasi bawaan peramban
24
+ sudah berlaku seperti pada `<input>` lain.
25
+ - **`required` di `FdyCfl`** (`#114`), ketiga stack. Ia merender `data-fdy-required` di grup
26
+ isiannya, dan grup itu kini mencerminkan kunci baris terpilih (`rowKey`, dipisah koma bila
27
+ `multiple`) di `data-value`. Penolakan menandai dan memfokuskan tombol pembuka.
28
+ - **`required` di `FdyDateRange`** (`#114`), ketiga stack, diteruskan ke **kedua** ujung. Prop ini
29
+ tidak ada di daftar §24. Masing-masing datepicker sudah punya `required`, tetapi tidak ada prop
30
+ rentang yang meneruskannya.
31
+ - **Jalur mentah `freeday-cfl.js` mencerminkan `data-value`** di grup isiannya setiap kali baris
32
+ dipilih. Nilainya `data-value` baris itu, atau kunci tampilannya bila baris tidak punya. Dengan
33
+ begitu `data-fdy-required` di grup bekerja tanpa pembungkus.
34
+ - **`setState(root, { required })`** di kelima enhancer yang punya `setState` (combo, datepicker
35
+ termasuk mode bulan, timepicker, cascade, autocomplete).
36
+
37
+ ### Fixed
38
+ - **Dua kontrol dalam satu `.fdy-field` saling menghapus pesan** (`#114`). Slot pesan dicari per
39
+ field, jadi mengisi ujung "dari" pada rentang menghapus pesan yang masih dibutuhkan ujung
40
+ "sampai". Akibatnya ujung itu tetap merah tanpa keterangan. Cacat yang sama mengenai dua input
41
+ native yang berdampingan. Kini slotnya tetap tampil selama masih ada kontrol yang merujuknya dan
42
+ masih invalid.
43
+ - **`Required` di Blazor hanya terbaca saat render pertama** (`#114`), di kelima kontrol 3.12.0.
44
+ Sesudah hidrasi komponennya berhenti merender, dan `setState` tidak membawa `required`. Isian
45
+ yang wajib secara bersyarat (`Required="@isPerusahaan"`) tidak pernah ikut berubah. Kini
46
+ `Required` ikut didorong bersama tiga state lainnya.
47
+ - **Mencabut syarat wajib tidak menghapus galat yang sedang tampil.** `MutationObserver` aturan
48
+ form kini juga mengamati `data-fdy-required`, dan akar yang tak lagi wajib tidak pernah ditolak.
49
+ - **Dorongan `setState` yang tidak mengubah apa pun menghapus tanda merah dari form** (`#114`).
50
+ Blazor mendorong semua state setiap kali induknya merender ulang. Menulis ulang `invalid: false`
51
+ yang tidak berubah mencabut `aria-invalid` yang dipasang `freeday-form.js`, sehingga pesannya
52
+ tertinggal di bawah isian yang tidak lagi merah. Kelima enhancer kini menulis `aria-invalid`
53
+ hanya bila `invalid` dari host benar-benar berubah. Vue dan React tidak terkena: keduanya hanya
54
+ menambal atribut yang ikatannya berubah.
55
+ - **Tombol pembuka `FdyCfl` di Blazor tidak punya `aria-haspopup="dialog"`**, padahal Vue dan
56
+ React memilikinya. Aturan form mencari elemen yang ditandai lewat atribut itu.
57
+
58
+ ### Catatan
59
+ - **Koreksi atas 3.12.0.** Catatan rilis itu menulis bahwa `FdyAutocomplete` dan `FdyCfl`
60
+ "merender `<input>` asli, jadi `required` native yang cocok". Untuk Cfl itu keliru. Input-nya
61
+ `readonly`, dan input readonly dikecualikan dari validasi bawaan peramban (`willValidate`
62
+ bernilai `false`), jadi `required` di sana tidak pernah menolak apa pun. Usulan §24 menyalin
63
+ kekeliruan itu. Seandainya diterapkan apa adanya, Cfl akan tampak wajib tanpa pernah menolak.
64
+ Ujinya kini menegaskan `willValidate === false` di fixture, supaya tidak ada yang mengembalikan
65
+ Cfl ke jalur native.
66
+ - Penimpaan pesan per-kontrol (`data-fdy-msg-required`) pada `FdyDateRange` Vue jatuh ke akar
67
+ `.fdy-daterange`, bukan ke kedua datepicker yang membacanya. Pakai `data-fdy-text-required` di
68
+ `<form>`, seperti di React dan Blazor.
69
+
12
70
  ## [3.17.0] - 2026-11-05
13
71
 
14
72
  **Pengalih tema terang/gelap, siap pakai di semua stack.** Setiap app sebelumnya menulis sendiri
package/COMPONENTS.md CHANGED
@@ -807,8 +807,11 @@ while each line referenced directly would be read even when hidden. Zero JS; wor
807
807
  | `describedby?` | `string` | Id of the help or error text (`aria-describedby`). |
808
808
 
809
809
  Blazor: the same names in `PascalCase`, bound with `@bind-Value` (`Value` / `ValueChanged`).
810
- `FreedayCombo.setState(root, { disabled, readonly, invalid })` pushes a state change onto a combo
811
- whose host has stopped re-rendering.
810
+ `FreedayCombo.setState(root, { disabled, readonly, invalid, required })` pushes a state change onto
811
+ a combo whose host has stopped re-rendering. `invalid` is written only when it changes, so a host
812
+ that pushes every state on every re-render does not erase the mark a
813
+ [`data-fdy-validate`](#form-validation--data-fdy-validate) form painted; the same holds for every
814
+ `setState` below.
812
815
 
813
816
  Fully styleable dropdown, APG combobox+listbox. Needs `freeday-select.js`.
814
817
 
@@ -851,9 +854,10 @@ keeps matching after selection. Do not put a glyph in that span.
851
854
  | `placeholder?` | `string` | |
852
855
  | `id?` · `ariaLabel?` · `ariaLabelledby?` · `describedby?` | `string` | Input id; its accessible name as text or as a reference; the help/error text it points at. |
853
856
  | `disabled?` · `readonly?` · `invalid?` | `boolean` | `readonly` keeps focus and tab order and shows its value, but the input is not editable and the list will not open. Unlike `disabled` it is not greyed. |
857
+ | `required?` | `boolean` | The native `required`, on the input itself. The input is editable, so constraint validation applies to it as to any `<input>`, and a [`data-fdy-validate`](#form-validation--data-fdy-validate) form refuses it empty. Free text counts as filled: the list suggests, it does not constrain. Blazor: `Required`. |
854
858
 
855
859
  Blazor carries all of these. The states live on the input natively, and
856
- `FreedayAutocomplete.setState(root, { disabled, readonly, invalid })` changes them after the first
860
+ `FreedayAutocomplete.setState(root, { disabled, readonly, invalid, required })` changes them after the first
857
861
  render. A `readonly` input no longer opens its suggestion list, which it used to do over a field
858
862
  nobody could edit.
859
863
 
@@ -882,7 +886,7 @@ Editable combobox that filters as you type. Needs `freeday-autocomplete.js`.
882
886
  | `required?` | `boolean` | Lets a [`data-fdy-validate`](#form-validation--data-fdy-validate) form demand this control be filled. Renders `data-fdy-required` on the root. Needed because the trigger is a `<button>`, whose `willValidate` is false, so a plain `required` on it has never meant anything. Blazor: `Required`. |
883
887
 
884
888
  Raw path: `data-disabled` / `data-readonly` / `data-invalid`, `data-id`, `data-describedby`, and
885
- `FreedayCascade.setState(root, { disabled, readonly, invalid })` for a host that rendered once.
889
+ `FreedayCascade.setState(root, { disabled, readonly, invalid, required })` for a host that rendered once.
886
890
  Blazor calls the tree `Nodes`, adds `SubmenuLabel`, and carries everything else except
887
891
  `ariaLabelledby` — the trigger it builds is named by `Label`.
888
892
 
@@ -940,6 +944,7 @@ Four of these are required and carry the whole component: `fetchPage`, `columns`
940
944
  | `clearable?` | `boolean` | A clear button, so an **optional** foreign key can be unset. Without it the value type admits a `null` the component can never produce. |
941
945
  | `clearLabel?` | `string` | Accessible name for that button. Default `Clear selection`. |
942
946
  | `disabled?` · `readonly?` · `invalid?` | `boolean` | `readonly` keeps the picked value visible, focusable and copyable, but the dialog cannot be opened. |
947
+ | `required?` | `boolean` | Lets a [`data-fdy-validate`](#form-validation--data-fdy-validate) form demand a row be picked. Renders `data-fdy-required` on the field group, which mirrors the picked keys (`rowKey`, comma-joined under `multiple`) in `data-value`; the refusal marks and focuses the open button. **Not** a native `required`: the field's input is readonly, and a readonly input is barred from constraint validation, so `required` on it never refuses anything. Ignored with `dialogOnly`. Blazor: `Required`. |
943
948
  | `id?` · `ariaLabelledby?` · `describedby?` | `string` | Field id; the element that labels it; the help/error text it points at. |
944
949
  | `dialogOnly?` | `boolean` | Render the **dialog and no field**, for a caller whose trigger is already its own. See below. |
945
950
 
@@ -976,7 +981,10 @@ A read-only field backed by master data: the button opens a searchable dialog, t
976
981
  the field. The value is always **chosen, never typed**. Needs `freeday-cfl.js`.
977
982
 
978
983
  - Field: `.fdy-input-group` + `data-fdy-cfl="<dialog id>"`, `data-fdy-cfl-display="code"`,
979
- `data-fdy-cfl-summary="{n} selected"` (multi)
984
+ `data-fdy-cfl-summary="{n} selected"` (multi). On pick the group mirrors the row's `data-value`
985
+ (else its display key; comma-joined in multi) into its own `data-value`, so `data-fdy-required`
986
+ on the group lets a `data-fdy-validate` form require it. Give the trigger `aria-haspopup="dialog"`:
987
+ that is the element the refusal marks and focuses.
980
988
  - Dialog: `<dialog class="fdy-modal fdy-modal--cfl">` + `data-fdy-cfl-multiple` for multi-select
981
989
  - Inside: `.fdy-cfl__search` `__results` `__row` `__check` `__empty` `__count` `__actions`
982
990
  - Hooks: `data-fdy-cfl-search` (the search input), `data-fdy-cfl-empty`, `data-fdy-cfl-count`,
@@ -1070,8 +1078,8 @@ them do not: without these, a Spanish calendar would be navigated by English arr
1070
1078
  On the **raw path** these all have hooks now: `data-disabled` / `data-readonly` / `data-invalid`,
1071
1079
  `data-id`, `data-describedby`, and one `data-fdy-text-<key>` per label above
1072
1080
  (`data-fdy-text-prev-month`, …). A host that renders its markup once and cannot re-render it can
1073
- change the three states afterwards with `FreedayDatepicker.setState(root, { disabled, readonly,
1074
- invalid })`.
1081
+ change the states afterwards with `FreedayDatepicker.setState(root, { disabled, readonly,
1082
+ invalid, required })`.
1075
1083
 
1076
1084
  Blazor carries the same surface bar four: `locale` (the enhancer formats through `Intl` from the
1077
1085
  page's `<html lang>`), `clearable` and `clearLabel` (this path builds no clear button), and
@@ -1117,6 +1125,7 @@ grid's own title.
1117
1125
  | `startPlaceholder?` · `endPlaceholder?` | `string` | One per field. |
1118
1126
  | `ariaLabel?` · `ariaLabelledby?` · `describedby?` | `string` | Names the group (`role="group"`), or points at the text that does. |
1119
1127
  | `disabled?` · `readonly?` · `invalid?` | `boolean` | Applied to both pickers together. |
1128
+ | `required?` | `boolean` | Both ends must be filled for a [`data-fdy-validate`](#form-validation--data-fdy-validate) form to submit. Each picker refuses on its own, and the two share the field's one message slot, which stays up while either end is still empty. Blazor: `Required`. |
1120
1129
  | `prevMonthLabel?` · `nextMonthLabel?` · `prevYearLabel?` · `nextYearLabel?` · `prevYearsLabel?` · `nextYearsLabel?` · `chooseMonthLabel?` · `chooseYearLabel?` | `string` | Forwarded verbatim to **both** pickers. Until 3.11.0 this was the one picker in the kit whose calendar nav could not be named in the page's own language: the single picker took these, the range dropped them. Blazor adds `BackToMonthsLabel`, since the raw seed both pickers are built from has that button. |
1121
1130
 
1122
1131
  Blazor splits the value into two scalars, `From` / `FromChanged` and `To` / `ToChanged`, because a
@@ -1214,7 +1223,7 @@ Seed attributes: `data-step` (minutes, default 30), `data-min` (default `00:00`)
1214
1223
  (default `23:59`), `data-value`, `data-label`, `data-placeholder` (default `--:--`), `data-id`,
1215
1224
  `data-describedby`, `data-disabled`, `data-readonly`, `data-invalid`. Emits a bubbling
1216
1225
  `fdy-time-select` (`detail {value}`). `FreedayTimepicker.setState(root, { disabled, readonly,
1217
- invalid })` changes the three states afterwards, which is what a host that renders its seed once
1226
+ invalid, required })` changes the states afterwards, which is what a host that renders its seed once
1218
1227
  and never again (Blazor) needs.
1219
1228
 
1220
1229
  **Use this instead of `<input type="time">`**, and not for theming alone: the native picker is
@@ -1325,18 +1334,21 @@ blur/input. Needs `freeday-form.js`.
1325
1334
  - Emits `fdy-form-valid` / `fdy-form-invalid`.
1326
1335
  - **A kit control can be required too** — `data-fdy-required` on its root. Combo, datepicker,
1327
1336
  monthpicker, timepicker and cascade build a `<button>` trigger, and a button's `willValidate` is
1328
- false, so `form.elements` never offered one and `required` on it meant nothing. The enhancer now
1329
- collects these roots alongside the native controls: empty `data-value` refuses the submit, the
1330
- message lands in the same `.fdy-field` slot, and the focus goes to the trigger. It names no
1331
- component — the value is read from `data-value` and the trigger is found by `aria-haspopup`. In
1332
- the typed stacks pass `required` / `Required` instead of writing the attribute.
1333
- **`FdyAutocomplete` and `FdyCfl` are outside this rule**: they render a real `<input>`, so the
1334
- native `required` is the mechanism that fits them — but no prop exposes it yet, and an unknown
1335
- attribute falls through to a wrapper's ROOT rather than to the input inside it, so today an app
1336
- cannot require either one. Tracked in `NEXT-UP.md`; the rule above deliberately does not cover
1337
- them, because painting a native input through the kit path would give it two sources of truth.
1338
- Re-validation watches the attribute with a `MutationObserver`, so no control has to announce
1339
- itself. The message override is per-control (`data-fdy-msg-required` on the root) wherever
1337
+ false, so `form.elements` never offered one and `required` on it meant nothing. A
1338
+ choose-from-list is in the same position for a different reason: its `<input>` is `readonly`,
1339
+ and a readonly input is barred from constraint validation. The enhancer collects these roots
1340
+ alongside the native controls: empty `data-value` refuses the submit, the message lands in the
1341
+ same `.fdy-field` slot, and the focus goes to the trigger. It names no component — the value is
1342
+ read from `data-value` and the trigger is found by `aria-haspopup`. In the typed stacks pass
1343
+ `required` / `Required` instead of writing the attribute; every value-bearing wrapper has it.
1344
+ **An autocomplete is the one that takes the native `required`**, on its input: the input is
1345
+ editable, so constraint validation already covers it, and routing it through the kit path would
1346
+ give one field two sources of truth.
1347
+ Re-validation watches `data-value` and `data-fdy-required` with a `MutationObserver`, so no
1348
+ control has to announce itself, and lifting the requirement clears an error already on screen.
1349
+ - **Two controls in one `.fdy-field` share its message slot** — a date range's two ends, or two
1350
+ native inputs side by side. The message stays up while any control pointing at it is still
1351
+ invalid, so filling one end does not erase the message the other end still needs. The message override is per-control (`data-fdy-msg-required` on the root) wherever
1340
1352
  attributes reach the root — the raw path, and Vue, where an unknown attribute falls through. In
1341
1353
  React and Blazor they do not, so use the form-level `data-fdy-text-required`, which reads the
1342
1354
  same in every stack.
package/README.id.md CHANGED
@@ -5,7 +5,7 @@
5
5
  > **Lebih banyak _free day_ buat dev. UI kit-nya sudah siap pakai.**
6
6
 
7
7
  [![Live docs](https://img.shields.io/badge/docs-live-2050d8?style=flat-square)](https://cahyo-dimas.github.io/freeday-ui-kit/)
8
- [![Release](https://img.shields.io/badge/release-v3.17.0-0078d4?style=flat-square)](https://github.com/cahyo-dimas/freeday-ui-kit/tree/v3.17.0)
8
+ [![Release](https://img.shields.io/badge/release-v3.18.0-0078d4?style=flat-square)](https://github.com/cahyo-dimas/freeday-ui-kit/tree/v3.18.0)
9
9
 
10
10
  UI KIT yang token-driven & framework-agnostic. Satu sumber kebenaran untuk warna, tipografi,
11
11
  spasi, dan komponen. Blueprint: `docs/superpowers/specs/2026-07-21-freeday-ui-kit-design.md`.
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  > **More free days for devs. The UI kit is ready to use.**
6
6
 
7
7
  [![Live docs](https://img.shields.io/badge/docs-live-2050d8?style=flat-square)](https://cahyo-dimas.github.io/freeday-ui-kit/)
8
- [![Release](https://img.shields.io/badge/release-v3.17.0-0078d4?style=flat-square)](https://github.com/cahyo-dimas/freeday-ui-kit/tree/v3.17.0)
8
+ [![Release](https://img.shields.io/badge/release-v3.18.0-0078d4?style=flat-square)](https://github.com/cahyo-dimas/freeday-ui-kit/tree/v3.18.0)
9
9
 
10
10
  A token-driven, framework-agnostic UI kit. One source of truth for color, typography,
11
11
  spacing, and components. Blueprint: `docs/superpowers/specs/2026-07-21-freeday-ui-kit-design.md`.
@@ -10,7 +10,7 @@
10
10
  aria-controls="@_listId" autocomplete="off" value="@Value"
11
11
  placeholder="@Placeholder" aria-label="@AriaLabel"
12
12
  id="@Id" aria-labelledby="@AriaLabelledby" aria-describedby="@Describedby"
13
- disabled="@Disabled" readonly="@Readonly"
13
+ disabled="@Disabled" readonly="@Readonly" required="@Required"
14
14
  aria-invalid="@(Invalid ? "true" : null)" />
15
15
  <ul class="fdy-autocomplete__listbox" id="@_listId" role="listbox" hidden>
16
16
  @foreach (string item in Options)
@@ -44,13 +44,18 @@ public partial class FdyAutocomplete
44
44
  /// <summary>Marks the field invalid (<c>aria-invalid</c>).</summary>
45
45
  [Parameter] public bool Invalid { get; set; }
46
46
 
47
+ /// <summary>The native <c>required</c>, on the input itself: it is editable, so constraint
48
+ /// validation (and so a <c>data-fdy-validate</c> form) applies to it as to any input. Pushed
49
+ /// with the other states, so a field required only under a condition follows it (#114).</summary>
50
+ [Parameter] public bool Required { get; set; }
51
+
47
52
  protected override bool ShouldRender() => !Hydrated;
48
53
 
49
54
  protected override async Task OnParametersSetAsync()
50
55
  {
51
56
  if (!Hydrated) return;
52
57
  await JS.InvokeVoidAsync("FreedayAutocomplete.setState", Root,
53
- new { disabled = Disabled, @readonly = Readonly, invalid = Invalid });
58
+ new { disabled = Disabled, @readonly = Readonly, invalid = Invalid, required = Required });
54
59
  }
55
60
 
56
61
  /// <summary>Invoked by the bridge when the user picks a suggestion.</summary>
@@ -61,7 +61,7 @@ public partial class FdyCascade
61
61
  {
62
62
  if (!Hydrated) return;
63
63
  await JS.InvokeVoidAsync("FreedayCascade.setState", Root,
64
- new { disabled = Disabled, @readonly = Readonly, invalid = Invalid });
64
+ new { disabled = Disabled, @readonly = Readonly, invalid = Invalid, required = Required });
65
65
  }
66
66
 
67
67
  /// <summary>Invoked by the bridge when the user selects a leaf.</summary>
@@ -12,7 +12,7 @@
12
12
  through @ref: `await picker.OpenAsync()`. The host generates no box. *@
13
13
  @if (!DialogOnly)
14
14
  {
15
- <div class="@FieldGroupClass">
15
+ <div class="@FieldGroupClass" data-value="@ValueAttr" data-fdy-required="@(Required ? "" : null)">
16
16
  <input class="fdy-input" type="text" readonly value="@DisplayValue"
17
17
  placeholder="@Placeholder" aria-labelledby="@AriaLabelledby"
18
18
  aria-invalid="@(Invalid ? "true" : null)" aria-readonly="@(Readonly ? "true" : null)" />
@@ -25,7 +25,7 @@
25
25
  </svg>
26
26
  </button>
27
27
  }
28
- <button class="fdy-input-group__btn" type="button" @onclick="OpenAsync"
28
+ <button class="fdy-input-group__btn" type="button" @onclick="OpenAsync" aria-haspopup="dialog"
29
29
  disabled="@(Disabled || Readonly)" aria-label="@OpenLabel">
30
30
  <svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor"
31
31
  stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
@@ -60,6 +60,15 @@ public partial class FdyCfl<TRow>
60
60
  /// <summary>Locked/view mode: shows the value but the search dialog can't be opened.</summary>
61
61
  [Parameter] public bool Readonly { get; set; }
62
62
  [Parameter] public bool Invalid { get; set; }
63
+
64
+ /// <summary>Let a <c>data-fdy-validate</c> form demand a row be picked. Renders
65
+ /// <c>data-fdy-required</c> on the field group, which mirrors the picked keys in
66
+ /// <c>data-value</c>; <c>freeday-form.js</c> refuses the submit, paints the message in the field
67
+ /// and focuses the open button. Not the native <c>required</c>: the field's input is readonly,
68
+ /// and a readonly input is barred from constraint validation (#114). Ignored with
69
+ /// <see cref="DialogOnly"/>, which has no field.</summary>
70
+ [Parameter] public bool Required { get; set; }
71
+
63
72
  /// <summary>Render a clear button when a row is picked, so an OPTIONAL foreign key can be unset.
64
73
  /// <c>Value</c> is already <c>TRow?</c>; without this the component can never produce null.</summary>
65
74
  [Parameter] public bool Clearable { get; set; }
@@ -90,6 +99,10 @@ public partial class FdyCfl<TRow>
90
99
  private int _debounceSeq; // supersedes stale debounced searches
91
100
 
92
101
  private string DisplayValue => Value is null ? string.Empty : Display(Value);
102
+ /* The live value on the group, as every value-bearing kit control mirrors it: the picked keys. */
103
+ private string ValueAttr => Multiple
104
+ ? string.Join(",", (Values ?? Array.Empty<TRow>()).Select(RowKey))
105
+ : Value is null ? string.Empty : RowKey(Value);
93
106
  private string FieldGroupClass => Invalid ? "fdy-input-group fdy-input-group--error" : "fdy-input-group";
94
107
  private bool IsInitialLoading => _loading && _rows.Count == 0;
95
108
  private bool IsBlockingError => _error is not null && _rows.Count == 0;
@@ -84,7 +84,7 @@ public partial class FdyCombo<TValue>
84
84
  if (_ready)
85
85
  {
86
86
  await JS.InvokeVoidAsync("FreedayCombo.setState", Root,
87
- new { disabled = Disabled, @readonly = Readonly, invalid = Invalid });
87
+ new { disabled = Disabled, @readonly = Readonly, invalid = Invalid, required = Required });
88
88
  }
89
89
  }
90
90
 
@@ -7,7 +7,7 @@
7
7
  so From/To bind separately. Enhancer-owned DOM → render once (ShouldRender => false). *@
8
8
  <div @ref="Root">
9
9
  <div data-fdy-daterange role="group" aria-label="@AriaLabel">
10
- <div data-fdy-datepicker data-role="from"
10
+ <div @ref="_fromEl" data-fdy-datepicker data-role="from" data-fdy-required="@(Required ? "" : null)"
11
11
  data-value="@From" data-placeholder="@FromPlaceholder" data-min="@Min" data-max="@Max"
12
12
  data-fdy-text-prev-month="@PrevMonthLabel"
13
13
  data-fdy-text-next-month="@NextMonthLabel"
@@ -19,7 +19,7 @@
19
19
  data-fdy-text-choose-year="@ChooseYearLabel"
20
20
  data-fdy-text-back-to-months="@BackToMonthsLabel"></div>
21
21
  <span class="fdy-daterange__sep">@Separator</span>
22
- <div data-fdy-datepicker data-role="to"
22
+ <div @ref="_toEl" data-fdy-datepicker data-role="to" data-fdy-required="@(Required ? "" : null)"
23
23
  data-value="@To" data-placeholder="@ToPlaceholder" data-min="@Min" data-max="@Max"
24
24
  data-fdy-text-prev-month="@PrevMonthLabel"
25
25
  data-fdy-text-next-month="@NextMonthLabel"
@@ -43,7 +43,14 @@ public partial class FdyDateRange
43
43
  /// the Vue and React adapters build no such button.</summary>
44
44
  [Parameter] public string? BackToMonthsLabel { get; set; }
45
45
 
46
+ /// <summary>Both ends must be filled for a <c>data-fdy-validate</c> form to submit. Rendered
47
+ /// as <c>data-fdy-required</c> on BOTH pickers, each refusing on its own, and pushed to them
48
+ /// afterwards, so a range required only under a condition follows it (#114).</summary>
49
+ [Parameter] public bool Required { get; set; }
50
+
46
51
  private int _token;
52
+ private ElementReference _fromEl;
53
+ private ElementReference _toEl;
47
54
 
48
55
  // initAll(Root) links the daterange (descendant) and inits both child pickers.
49
56
  protected override ValueTask HydrateAsync() => JS.InvokeVoidAsync("FreedayDatepicker.initAll", Root);
@@ -53,6 +60,13 @@ public partial class FdyDateRange
53
60
 
54
61
  protected override bool ShouldRender() => !Hydrated;
55
62
 
63
+ protected override async Task OnParametersSetAsync()
64
+ {
65
+ if (!Hydrated) return;
66
+ await JS.InvokeVoidAsync("FreedayDatepicker.setState", _fromEl, new { required = Required });
67
+ await JS.InvokeVoidAsync("FreedayDatepicker.setState", _toEl, new { required = Required });
68
+ }
69
+
56
70
  /// <summary>Invoked by the bridge for either child's change; routes by data-role.</summary>
57
71
  [JSInvokable]
58
72
  public async Task OnChange(RangeDetail detail)
@@ -96,7 +96,7 @@ public partial class FdyDatepicker
96
96
  {
97
97
  if (!Hydrated) return;
98
98
  await JS.InvokeVoidAsync("FreedayDatepicker.setState", Root,
99
- new { disabled = Disabled, @readonly = Readonly, invalid = Invalid });
99
+ new { disabled = Disabled, @readonly = Readonly, invalid = Invalid, required = Required });
100
100
  }
101
101
 
102
102
  /// <summary>Invoked by the bridge when the user picks (or clears) a date.</summary>
@@ -93,7 +93,7 @@ public partial class FdyMonthpicker
93
93
  {
94
94
  if (!Hydrated) return;
95
95
  await JS.InvokeVoidAsync("FreedayDatepicker.setState", Root,
96
- new { disabled = Disabled, @readonly = Readonly, invalid = Invalid });
96
+ new { disabled = Disabled, @readonly = Readonly, invalid = Invalid, required = Required });
97
97
  }
98
98
 
99
99
  /// <summary>Invoked by the bridge when the user picks (or clears) a month.</summary>
@@ -70,7 +70,7 @@ public partial class FdyTimepicker
70
70
  {
71
71
  if (!Hydrated) return;
72
72
  await JS.InvokeVoidAsync("FreedayTimepicker.setState", Root,
73
- new { disabled = Disabled, @readonly = Readonly, invalid = Invalid });
73
+ new { disabled = Disabled, @readonly = Readonly, invalid = Invalid, required = Required });
74
74
  }
75
75
 
76
76
  /// <summary>Invoked by the bridge when the reader picks a time (enhancer's fdy-time-select).</summary>
@@ -24,6 +24,10 @@ export interface FdyAutocompleteProps {
24
24
  /** Locked/view mode: the input is not editable and the list won't open, but it stays focusable and shows its value. Unlike `disabled`, it keeps tab order and isn't greyed. */
25
25
  readonly?: boolean;
26
26
  invalid?: boolean;
27
+ /** The native `required`, on the input itself: it is editable, so constraint validation (and so a
28
+ * `data-fdy-validate` form) applies to it as to any input. Not `data-fdy-required`, which is for
29
+ * controls whose trigger is a button (#114). */
30
+ required?: boolean;
27
31
  describedby?: string;
28
32
  }
29
33
 
@@ -132,6 +136,7 @@ export function FdyAutocomplete(props: FdyAutocompleteProps): JSX.Element {
132
136
  placeholder={props.placeholder}
133
137
  disabled={isDisabled}
134
138
  readOnly={isReadonly}
139
+ required={props.required === true}
135
140
  value={props.value}
136
141
  onChange={(e: React.ChangeEvent<HTMLInputElement>): void => { props.onChange(e.target.value); setActive(-1); openList(); }}
137
142
  onFocus={openList}
@@ -63,6 +63,13 @@ export interface FdyCflProps<Row extends Record<string, unknown>> {
63
63
  /** Locked/view mode: shows the picked value (focusable, copyable), but the search dialog can't be opened. Unlike `disabled`, it keeps tab order and isn't greyed. */
64
64
  readonly?: boolean;
65
65
  invalid?: boolean;
66
+ /** Let a `data-fdy-validate` form demand a row be picked. It renders `data-fdy-required` on the
67
+ * field group, which mirrors the picked keys in `data-value`; `freeday-form.js` refuses the
68
+ * submit, paints the message in the field and focuses the open button. Not the native
69
+ * `required`: the field's input is readonly, and a readonly input is barred from constraint
70
+ * validation, so `required` on it never refused anything (#114). Ignored with `dialogOnly`,
71
+ * which has no field to paint. */
72
+ required?: boolean;
66
73
  /** Render a clear button when a row is picked, so an OPTIONAL foreign key can be unset. Without it
67
74
  * `value` accepts `Row | null` but the component can only ever produce a `Row`. */
68
75
  clearable?: boolean;
@@ -142,6 +149,8 @@ function FdyCflInner<Row extends Record<string, unknown>>(
142
149
  : props.value !== null
143
150
  ? [props.value as Row]
144
151
  : [];
152
+ /* The live value on the root, as every value-bearing kit control mirrors it: the picked keys. */
153
+ const valueAttr: string = currentRows.map((r: Row): string => props.rowKey(r)).join(',');
145
154
  const selectedTextFor = (n: number): string => (props.selectedText ?? '{n} selected').replace('{n}', String(n));
146
155
  const isMultiple: boolean = props.multiple === true;
147
156
  const showClear: boolean =
@@ -352,7 +361,8 @@ function FdyCflInner<Row extends Record<string, unknown>>(
352
361
  }, []);
353
362
 
354
363
  return (
355
- <div className={props.dialogOnly === true ? 'fdy-cfl__host' : 'fdy-input-group'}>
364
+ <div className={props.dialogOnly === true ? 'fdy-cfl__host' : 'fdy-input-group'} data-value={valueAttr}
365
+ data-fdy-required={props.required === true && props.dialogOnly !== true ? '' : undefined}>
356
366
  {props.dialogOnly === true ? null : (
357
367
  <>
358
368
  <input
@@ -24,6 +24,9 @@ export interface FdyDateRangeProps {
24
24
  /** Locked/view mode for both pickers, focusable, values shown, but can't be opened or changed. */
25
25
  readonly?: boolean;
26
26
  invalid?: boolean;
27
+ /** Both ends must be filled for a `data-fdy-validate` form to submit. Forwarded to BOTH pickers,
28
+ * each refusing on its own; the two share the field's one message slot (#114). */
29
+ required?: boolean;
27
30
  describedby?: string;
28
31
  startPlaceholder?: string;
29
32
  endPlaceholder?: string;
@@ -68,6 +71,7 @@ export function FdyDateRange(props: FdyDateRangeProps): JSX.Element {
68
71
  disabled={props.disabled}
69
72
  readonly={props.readonly}
70
73
  invalid={props.invalid}
74
+ required={props.required}
71
75
  describedby={props.describedby}
72
76
  placeholder={props.startPlaceholder ?? 'Dari'}
73
77
  prevMonthLabel={props.prevMonthLabel}
@@ -89,6 +93,7 @@ export function FdyDateRange(props: FdyDateRangeProps): JSX.Element {
89
93
  disabled={props.disabled}
90
94
  readonly={props.readonly}
91
95
  invalid={props.invalid}
96
+ required={props.required}
92
97
  describedby={props.describedby}
93
98
  placeholder={props.endPlaceholder ?? 'Sampai'}
94
99
  prevMonthLabel={props.prevMonthLabel}
@@ -21,6 +21,10 @@ const props = defineProps<{
21
21
  /** Locked/view mode: the input is not editable and the list won't open, but it stays focusable and shows its value. Unlike `disabled`, it keeps tab order and isn't greyed. */
22
22
  readonly?: boolean;
23
23
  invalid?: boolean;
24
+ /** The native `required`, on the input itself: it is editable, so constraint validation (and so a
25
+ * `data-fdy-validate` form) applies to it as to any input. Not `data-fdy-required`, which is for
26
+ * controls whose trigger is a button (#114). */
27
+ required?: boolean;
24
28
  describedby?: string;
25
29
  }>();
26
30
 
@@ -148,6 +152,7 @@ watch(active, async (i: number): Promise<void> => {
148
152
  :placeholder="placeholder"
149
153
  :disabled="isDisabled"
150
154
  :readonly="isReadonly"
155
+ :required="required === true"
151
156
  :value="modelValue"
152
157
  @input="onInput"
153
158
  @focus="openList"
@@ -64,6 +64,13 @@ const props = defineProps<{
64
64
  /** Locked/view mode: shows the picked value (focusable, copyable), but the search dialog can't be opened. Unlike `disabled`, it keeps tab order and isn't greyed. */
65
65
  readonly?: boolean;
66
66
  invalid?: boolean;
67
+ /** Let a `data-fdy-validate` form demand a row be picked. It renders `data-fdy-required` on the
68
+ * field group, which mirrors the picked keys in `data-value`; `freeday-form.js` refuses the
69
+ * submit, paints the message in the field and focuses the open button. Not the native
70
+ * `required`: the field's input is readonly, and a readonly input is barred from constraint
71
+ * validation, so `required` on it never refused anything (#114). Ignored with `dialogOnly`,
72
+ * which has no field to paint. */
73
+ required?: boolean;
67
74
  /** Render a clear button when a row is picked, so an OPTIONAL foreign key can be unset. Without it
68
75
  * `modelValue` accepts `Row | null` but the component can only ever produce a `Row`. */
69
76
  clearable?: boolean;
@@ -122,6 +129,8 @@ const isInvalid: ComputedRef<boolean> = computed((): boolean => props.invalid ==
122
129
  const currentRows: ComputedRef<Row[]> = computed((): Row[] =>
123
130
  Array.isArray(props.modelValue) ? props.modelValue : props.modelValue !== null ? [props.modelValue as Row] : [],
124
131
  );
132
+ /* The live value on the root, as every value-bearing kit control mirrors it: the picked keys. */
133
+ const valueAttr: ComputedRef<string> = computed((): string => currentRows.value.map((r: Row): string => props.rowKey(r)).join(','));
125
134
  const selectedTextFor = (n: number): string => (props.selectedText ?? '{n} selected').replace('{n}', String(n));
126
135
  const displayValue: ComputedRef<string> = computed((): string => {
127
136
  if (props.multiple === true) return currentRows.value.length === 0 ? '' : selectedTextFor(currentRows.value.length);
@@ -346,7 +355,8 @@ onBeforeUnmount((): void => {
346
355
  </script>
347
356
 
348
357
  <template>
349
- <div :class="isDialogOnly ? 'fdy-cfl__host' : 'fdy-input-group'">
358
+ <div :class="isDialogOnly ? 'fdy-cfl__host' : 'fdy-input-group'" :data-value="valueAttr"
359
+ :data-fdy-required="required === true && !isDialogOnly ? '' : undefined">
350
360
  <template v-if="!isDialogOnly">
351
361
  <input
352
362
  :id="fieldId"
@@ -24,6 +24,9 @@ const props = defineProps<{
24
24
  /** Locked/view mode for both pickers, focusable, values shown, but can't be opened or changed. */
25
25
  readonly?: boolean;
26
26
  invalid?: boolean;
27
+ /** Both ends must be filled for a `data-fdy-validate` form to submit. Forwarded to BOTH pickers,
28
+ * each refusing on its own; the two share the field's one message slot (#114). */
29
+ required?: boolean;
27
30
  describedby?: string;
28
31
  startPlaceholder?: string;
29
32
  endPlaceholder?: string;
@@ -80,6 +83,7 @@ function setEnd(end: string): void {
80
83
  :disabled="disabled"
81
84
  :readonly="readonly"
82
85
  :invalid="invalid"
86
+ :required="required"
83
87
  :describedby="describedby"
84
88
  :placeholder="startPlaceholder ?? 'Dari'"
85
89
  :prev-month-label="prevMonthLabel"
@@ -101,6 +105,7 @@ function setEnd(end: string): void {
101
105
  :disabled="disabled"
102
106
  :readonly="readonly"
103
107
  :invalid="invalid"
108
+ :required="required"
104
109
  :describedby="describedby"
105
110
  :placeholder="endPlaceholder ?? 'Sampai'"
106
111
  :prev-month-label="prevMonthLabel"
@@ -22,6 +22,7 @@
22
22
  root.dataset.fdyAcReady = '1';
23
23
 
24
24
  var input = root.querySelector('input[role="combobox"]') || root.querySelector('input');
25
+ root._fdyInvalid = !!input && input.getAttribute('aria-invalid') === 'true';
25
26
  var listbox = root.querySelector('[role="listbox"]');
26
27
  if (!input || !listbox) return;
27
28
  var options = Array.prototype.slice.call(listbox.querySelectorAll('[role="option"]'));
@@ -145,10 +146,14 @@
145
146
  if (!input || !state) return;
146
147
  if (state.disabled != null) input.disabled = !!state.disabled;
147
148
  if (state.readonly != null) input.readOnly = !!state.readonly;
148
- if (state.invalid != null) {
149
+ /* Only when the HOST changes it: an unchanged push must not erase what freeday-form.js painted (#114). */
150
+ if (state.invalid != null && !!state.invalid !== root._fdyInvalid) {
151
+ root._fdyInvalid = !!state.invalid;
149
152
  if (state.invalid) input.setAttribute('aria-invalid', 'true');
150
153
  else input.removeAttribute('aria-invalid');
151
154
  }
155
+ /* Native `required` on the input itself: it is editable, so constraint validation applies (#114). */
156
+ if (state.required != null) input.required = !!state.required;
152
157
  }
153
158
 
154
159
  window.FreedayAutocomplete = { init: initAutocomplete, initAll: initAll, setState: setState };
@@ -236,16 +236,26 @@
236
236
  trigger.disabled = stateDisabled;
237
237
  if (stateReadonly) trigger.setAttribute('aria-readonly', 'true');
238
238
  else trigger.removeAttribute('aria-readonly');
239
+ if ((stateDisabled || stateReadonly) && !panel.hidden) close(false);
240
+ }
241
+ /* `invalid` is written only when the HOST changes it. A render-once host (Blazor) pushes every
242
+ state on every parent re-render, and rewriting an unchanged `false` erased the mark
243
+ freeday-form.js had painted, leaving its message under a field no longer red (#114). */
244
+ function applyInvalid() {
239
245
  if (stateInvalid) trigger.setAttribute('aria-invalid', 'true');
240
246
  else trigger.removeAttribute('aria-invalid');
241
247
  wrap.classList.toggle('fdy-cascade--error', stateInvalid);
242
- if ((stateDisabled || stateReadonly) && !panel.hidden) close(false);
243
248
  }
244
249
  function setState(next) {
245
250
  if (!next) return;
246
251
  if (next.disabled != null) stateDisabled = !!next.disabled;
247
252
  if (next.readonly != null) stateReadonly = !!next.readonly;
248
- if (next.invalid != null) stateInvalid = !!next.invalid;
253
+ if (next.invalid != null && !!next.invalid !== stateInvalid) {
254
+ stateInvalid = !!next.invalid;
255
+ applyInvalid();
256
+ }
257
+ /* `required` too: a render-once host (Blazor) has no other way to change it later (#114). */
258
+ if (next.required != null) wrap.toggleAttribute('data-fdy-required', !!next.required);
249
259
  applyState();
250
260
  }
251
261
 
@@ -306,6 +316,7 @@
306
316
  }
307
317
 
308
318
  applyState();
319
+ applyInvalid();
309
320
 
310
321
  var api = {
311
322
  wrap: wrap,
@@ -99,15 +99,26 @@
99
99
  countEl.textContent = textOf(dialog, 'selected', { n: n });
100
100
  }
101
101
 
102
+ /* The row's `data-value`, else the text the field shows: what the group mirrors as its live
103
+ value, so `freeday-form.js` can require a choose-from-list. Its input is readonly, which
104
+ bars it from constraint validation, so a native `required` on it never refuses (#114). */
105
+ function rowValue(row, key) {
106
+ if (row.value != null && row.value !== '') return String(row.value);
107
+ return row[key] != null ? String(row[key]) : '';
108
+ }
109
+
102
110
  function fillGroup(detail) {
103
111
  if (!activeGroup) return;
112
+ var key = activeGroup.getAttribute('data-fdy-cfl-display') || 'value';
113
+ activeGroup.setAttribute('data-value', detail.rows
114
+ ? detail.rows.map(function (r) { return rowValue(r, key); }).join(',')
115
+ : rowValue(detail.row, key));
104
116
  var input = activeGroup.querySelector('.fdy-input');
105
117
  if (input) {
106
118
  if (detail.rows) {
107
119
  var tpl = activeGroup.getAttribute('data-fdy-cfl-summary') || '{n} selected';
108
120
  input.value = detail.rows.length ? tpl.replace('{n}', String(detail.rows.length)) : '';
109
121
  } else {
110
- var key = activeGroup.getAttribute('data-fdy-cfl-display') || 'value';
111
122
  input.value = detail.row[key] != null ? detail.row[key] : (detail.row.value || '');
112
123
  }
113
124
  }
@@ -582,16 +582,26 @@
582
582
  trigger.disabled = stateDisabled;
583
583
  if (stateReadonly) trigger.setAttribute('aria-readonly', 'true');
584
584
  else trigger.removeAttribute('aria-readonly');
585
+ if ((stateDisabled || stateReadonly) && !panel.hidden) close(false);
586
+ }
587
+ /* `invalid` is written only when the HOST changes it. A render-once host (Blazor) pushes every
588
+ state on every parent re-render, and rewriting an unchanged `false` erased the mark
589
+ freeday-form.js had painted, leaving its message under a field no longer red (#114). */
590
+ function applyInvalid() {
585
591
  if (stateInvalid) trigger.setAttribute('aria-invalid', 'true');
586
592
  else trigger.removeAttribute('aria-invalid');
587
593
  wrap.classList.toggle('fdy-datepicker--error', stateInvalid);
588
- if ((stateDisabled || stateReadonly) && !panel.hidden) close(false);
589
594
  }
590
595
  function setState(next) {
591
596
  if (!next) return;
592
597
  if (next.disabled != null) stateDisabled = !!next.disabled;
593
598
  if (next.readonly != null) stateReadonly = !!next.readonly;
594
- if (next.invalid != null) stateInvalid = !!next.invalid;
599
+ if (next.invalid != null && !!next.invalid !== stateInvalid) {
600
+ stateInvalid = !!next.invalid;
601
+ applyInvalid();
602
+ }
603
+ /* `required` too: a render-once host (Blazor) has no other way to change it later (#114). */
604
+ if (next.required != null) wrap.toggleAttribute('data-fdy-required', !!next.required);
595
605
  applyState();
596
606
  }
597
607
 
@@ -628,6 +638,7 @@
628
638
  updateDisplay();
629
639
 
630
640
  applyState();
641
+ applyInvalid();
631
642
 
632
643
  var api = {
633
644
  wrap: wrap,
@@ -82,10 +82,11 @@
82
82
  * data-fdy-required the app asking for it, on the control's ROOT
83
83
  * data-value the live value, which every value-bearing kit control now mirrors
84
84
  * and the element that takes aria-invalid and focus is found by `aria-haspopup`, which every
85
- * popup-style kit trigger already sets. `FdyAutocomplete` and `FdyCfl` are absent on purpose:
86
- * they render a real <input>, so the NATIVE `required` is what fits them, and routing them
87
- * through here would give one field two sources of truth. No prop exposes that yet, which is a
88
- * separate gap and is written down in NEXT-UP.md rather than half-closed here. */
85
+ * popup-style kit trigger already sets. A choose-from-list belongs here too: its <input> is
86
+ * `readonly`, and a readonly input is barred from constraint validation, so a native `required`
87
+ * on it never refuses anything; its open button carries `aria-haspopup="dialog"`. An
88
+ * autocomplete does NOT: its input is editable, so the native `required` is the one that fits,
89
+ * and routing it through here would give one field two sources of truth (#114). */
89
90
  function kitRoots(form) {
90
91
  return Array.prototype.slice.call(form.querySelectorAll('[data-fdy-required]'));
91
92
  }
@@ -97,6 +98,9 @@
97
98
  }
98
99
 
99
100
  function kitMessage(root) {
101
+ /* Read again on every pass, not only when the root was collected: a field required only under
102
+ a condition loses the attribute while its error is still painted (#114). */
103
+ if (!root.hasAttribute('data-fdy-required')) return '';
100
104
  if ((root.getAttribute('data-value') || '') !== '') return '';
101
105
  var form = root.closest('form');
102
106
  return root.getAttribute('data-fdy-msg-required')
@@ -143,6 +147,17 @@
143
147
  return custom || el.getAttribute('data-fdy-msg') || (alias && textOf(form, alias)) || el.validationMessage || textOf(form, 'invalid');
144
148
  }
145
149
 
150
+ /* Two controls can share one `.fdy-field` and so one message slot: a date range's two ends, or two
151
+ native inputs side by side. The slot is found per FIELD, so clearing the end that was filled
152
+ used to erase the message the other end still needed, leaving it red with nothing to say why
153
+ (#114). The slot is kept while any other control that points at it is still invalid. */
154
+ function stillClaimed(errEl, except) {
155
+ var scope = except.closest('form') || document;
156
+ return Array.prototype.some.call(scope.querySelectorAll('[aria-invalid="true"]'), function (other) {
157
+ return other !== except && (other.getAttribute('aria-describedby') || '').split(/\s+/).indexOf(errEl.id) !== -1;
158
+ });
159
+ }
160
+
146
161
  function paint(el, message) {
147
162
  var errEl = ensureErrorEl(el);
148
163
  if (message) {
@@ -151,6 +166,7 @@
151
166
  errEl.hidden = false;
152
167
  } else {
153
168
  el.removeAttribute('aria-invalid');
169
+ if (stillClaimed(errEl, el)) return;
154
170
  errEl.textContent = '';
155
171
  errEl.hidden = true;
156
172
  }
@@ -208,7 +224,7 @@
208
224
  root.dataset.fdyKitBound = '1';
209
225
  new MutationObserver(function () {
210
226
  if (submitted || eager) validateKit(root);
211
- }).observe(root, { attributes: true, attributeFilter: ['data-value'] });
227
+ }).observe(root, { attributes: true, attributeFilter: ['data-value', 'data-fdy-required'] });
212
228
  }
213
229
  function validateOne(el) {
214
230
  var msg = messageFor(el);
@@ -39,6 +39,7 @@
39
39
  var options = Array.prototype.slice.call(root.querySelectorAll('.fdy-combo__option'));
40
40
  if (!button || !listbox || !valueEl || options.length === 0) return;
41
41
  root.dataset.fdyComboReady = '1';
42
+ root._fdyInvalid = button.getAttribute('aria-invalid') === 'true';
42
43
 
43
44
  seq += 1;
44
45
  if (!listbox.id) listbox.id = 'fdy-combo-list-' + seq;
@@ -222,10 +223,16 @@
222
223
  if (state.readonly) button.setAttribute('aria-readonly', 'true');
223
224
  else button.removeAttribute('aria-readonly');
224
225
  }
225
- if (state.invalid != null) {
226
+ /* `invalid` is written only when the HOST changes it. A render-once host (Blazor) pushes every
227
+ state on every parent re-render, and rewriting an unchanged `false` erased the mark
228
+ freeday-form.js had painted, leaving its message under a field no longer red (#114). */
229
+ if (state.invalid != null && !!state.invalid !== root._fdyInvalid) {
230
+ root._fdyInvalid = !!state.invalid;
226
231
  if (state.invalid) button.setAttribute('aria-invalid', 'true');
227
232
  else button.removeAttribute('aria-invalid');
228
233
  }
234
+ /* `required` too: a render-once host (Blazor) has no other way to change it later (#114). */
235
+ if (state.required != null) root.toggleAttribute('data-fdy-required', !!state.required);
229
236
  }
230
237
 
231
238
  window.FreedayCombo = { init: initCombo, initAll: initAll, setValue: setValue, setState: setState };
@@ -117,16 +117,26 @@
117
117
  trigger.disabled = stateDisabled;
118
118
  if (stateReadonly) trigger.setAttribute('aria-readonly', 'true');
119
119
  else trigger.removeAttribute('aria-readonly');
120
+ if ((stateDisabled || stateReadonly) && !panel.hidden) close(false);
121
+ }
122
+ /* `invalid` is written only when the HOST changes it. A render-once host (Blazor) pushes every
123
+ state on every parent re-render, and rewriting an unchanged `false` erased the mark
124
+ freeday-form.js had painted, leaving its message under a field no longer red (#114). */
125
+ function applyInvalid() {
120
126
  if (stateInvalid) trigger.setAttribute('aria-invalid', 'true');
121
127
  else trigger.removeAttribute('aria-invalid');
122
128
  wrap.classList.toggle('fdy-timepicker--error', stateInvalid);
123
- if ((stateDisabled || stateReadonly) && !panel.hidden) close(false);
124
129
  }
125
130
  function setState(next) {
126
131
  if (!next) return;
127
132
  if (next.disabled != null) stateDisabled = !!next.disabled;
128
133
  if (next.readonly != null) stateReadonly = !!next.readonly;
129
- if (next.invalid != null) stateInvalid = !!next.invalid;
134
+ if (next.invalid != null && !!next.invalid !== stateInvalid) {
135
+ stateInvalid = !!next.invalid;
136
+ applyInvalid();
137
+ }
138
+ /* `required` too: a render-once host (Blazor) has no other way to change it later (#114). */
139
+ if (next.required != null) wrap.toggleAttribute('data-fdy-required', !!next.required);
130
140
  applyState();
131
141
  }
132
142
 
@@ -214,6 +224,7 @@
214
224
 
215
225
  updateDisplay();
216
226
  applyState();
227
+ applyInvalid();
217
228
 
218
229
  var api = {
219
230
  wrap: wrap,
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"]'));
@@ -374,10 +375,14 @@
374
375
  if (!input || !state) return;
375
376
  if (state.disabled != null) input.disabled = !!state.disabled;
376
377
  if (state.readonly != null) input.readOnly = !!state.readonly;
377
- if (state.invalid != null) {
378
+ /* Only when the HOST changes it: an unchanged push must not erase what freeday-form.js painted (#114). */
379
+ if (state.invalid != null && !!state.invalid !== root._fdyInvalid) {
380
+ root._fdyInvalid = !!state.invalid;
378
381
  if (state.invalid) input.setAttribute('aria-invalid', 'true');
379
382
  else input.removeAttribute('aria-invalid');
380
383
  }
384
+ /* Native `required` on the input itself: it is editable, so constraint validation applies (#114). */
385
+ if (state.required != null) input.required = !!state.required;
381
386
  }
382
387
 
383
388
  window.FreedayAutocomplete = { init: initAutocomplete, initAll: initAll, setState: setState };
@@ -995,16 +1000,26 @@
995
1000
  trigger.disabled = stateDisabled;
996
1001
  if (stateReadonly) trigger.setAttribute('aria-readonly', 'true');
997
1002
  else trigger.removeAttribute('aria-readonly');
1003
+ if ((stateDisabled || stateReadonly) && !panel.hidden) close(false);
1004
+ }
1005
+ /* `invalid` is written only when the HOST changes it. A render-once host (Blazor) pushes every
1006
+ state on every parent re-render, and rewriting an unchanged `false` erased the mark
1007
+ freeday-form.js had painted, leaving its message under a field no longer red (#114). */
1008
+ function applyInvalid() {
998
1009
  if (stateInvalid) trigger.setAttribute('aria-invalid', 'true');
999
1010
  else trigger.removeAttribute('aria-invalid');
1000
1011
  wrap.classList.toggle('fdy-cascade--error', stateInvalid);
1001
- if ((stateDisabled || stateReadonly) && !panel.hidden) close(false);
1002
1012
  }
1003
1013
  function setState(next) {
1004
1014
  if (!next) return;
1005
1015
  if (next.disabled != null) stateDisabled = !!next.disabled;
1006
1016
  if (next.readonly != null) stateReadonly = !!next.readonly;
1007
- if (next.invalid != null) stateInvalid = !!next.invalid;
1017
+ if (next.invalid != null && !!next.invalid !== stateInvalid) {
1018
+ stateInvalid = !!next.invalid;
1019
+ applyInvalid();
1020
+ }
1021
+ /* `required` too: a render-once host (Blazor) has no other way to change it later (#114). */
1022
+ if (next.required != null) wrap.toggleAttribute('data-fdy-required', !!next.required);
1008
1023
  applyState();
1009
1024
  }
1010
1025
 
@@ -1065,6 +1080,7 @@
1065
1080
  }
1066
1081
 
1067
1082
  applyState();
1083
+ applyInvalid();
1068
1084
 
1069
1085
  var api = {
1070
1086
  wrap: wrap,
@@ -1201,15 +1217,26 @@
1201
1217
  countEl.textContent = textOf(dialog, 'selected', { n: n });
1202
1218
  }
1203
1219
 
1220
+ /* The row's `data-value`, else the text the field shows: what the group mirrors as its live
1221
+ value, so `freeday-form.js` can require a choose-from-list. Its input is readonly, which
1222
+ bars it from constraint validation, so a native `required` on it never refuses (#114). */
1223
+ function rowValue(row, key) {
1224
+ if (row.value != null && row.value !== '') return String(row.value);
1225
+ return row[key] != null ? String(row[key]) : '';
1226
+ }
1227
+
1204
1228
  function fillGroup(detail) {
1205
1229
  if (!activeGroup) return;
1230
+ var key = activeGroup.getAttribute('data-fdy-cfl-display') || 'value';
1231
+ activeGroup.setAttribute('data-value', detail.rows
1232
+ ? detail.rows.map(function (r) { return rowValue(r, key); }).join(',')
1233
+ : rowValue(detail.row, key));
1206
1234
  var input = activeGroup.querySelector('.fdy-input');
1207
1235
  if (input) {
1208
1236
  if (detail.rows) {
1209
1237
  var tpl = activeGroup.getAttribute('data-fdy-cfl-summary') || '{n} selected';
1210
1238
  input.value = detail.rows.length ? tpl.replace('{n}', String(detail.rows.length)) : '';
1211
1239
  } else {
1212
- var key = activeGroup.getAttribute('data-fdy-cfl-display') || 'value';
1213
1240
  input.value = detail.row[key] != null ? detail.row[key] : (detail.row.value || '');
1214
1241
  }
1215
1242
  }
@@ -2701,16 +2728,26 @@
2701
2728
  trigger.disabled = stateDisabled;
2702
2729
  if (stateReadonly) trigger.setAttribute('aria-readonly', 'true');
2703
2730
  else trigger.removeAttribute('aria-readonly');
2731
+ if ((stateDisabled || stateReadonly) && !panel.hidden) close(false);
2732
+ }
2733
+ /* `invalid` is written only when the HOST changes it. A render-once host (Blazor) pushes every
2734
+ state on every parent re-render, and rewriting an unchanged `false` erased the mark
2735
+ freeday-form.js had painted, leaving its message under a field no longer red (#114). */
2736
+ function applyInvalid() {
2704
2737
  if (stateInvalid) trigger.setAttribute('aria-invalid', 'true');
2705
2738
  else trigger.removeAttribute('aria-invalid');
2706
2739
  wrap.classList.toggle('fdy-datepicker--error', stateInvalid);
2707
- if ((stateDisabled || stateReadonly) && !panel.hidden) close(false);
2708
2740
  }
2709
2741
  function setState(next) {
2710
2742
  if (!next) return;
2711
2743
  if (next.disabled != null) stateDisabled = !!next.disabled;
2712
2744
  if (next.readonly != null) stateReadonly = !!next.readonly;
2713
- if (next.invalid != null) stateInvalid = !!next.invalid;
2745
+ if (next.invalid != null && !!next.invalid !== stateInvalid) {
2746
+ stateInvalid = !!next.invalid;
2747
+ applyInvalid();
2748
+ }
2749
+ /* `required` too: a render-once host (Blazor) has no other way to change it later (#114). */
2750
+ if (next.required != null) wrap.toggleAttribute('data-fdy-required', !!next.required);
2714
2751
  applyState();
2715
2752
  }
2716
2753
 
@@ -2747,6 +2784,7 @@
2747
2784
  updateDisplay();
2748
2785
 
2749
2786
  applyState();
2787
+ applyInvalid();
2750
2788
 
2751
2789
  var api = {
2752
2790
  wrap: wrap,
@@ -3061,10 +3099,11 @@
3061
3099
  * data-fdy-required the app asking for it, on the control's ROOT
3062
3100
  * data-value the live value, which every value-bearing kit control now mirrors
3063
3101
  * 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. */
3102
+ * popup-style kit trigger already sets. A choose-from-list belongs here too: its <input> is
3103
+ * `readonly`, and a readonly input is barred from constraint validation, so a native `required`
3104
+ * on it never refuses anything; its open button carries `aria-haspopup="dialog"`. An
3105
+ * autocomplete does NOT: its input is editable, so the native `required` is the one that fits,
3106
+ * and routing it through here would give one field two sources of truth (#114). */
3068
3107
  function kitRoots(form) {
3069
3108
  return Array.prototype.slice.call(form.querySelectorAll('[data-fdy-required]'));
3070
3109
  }
@@ -3076,6 +3115,9 @@
3076
3115
  }
3077
3116
 
3078
3117
  function kitMessage(root) {
3118
+ /* Read again on every pass, not only when the root was collected: a field required only under
3119
+ a condition loses the attribute while its error is still painted (#114). */
3120
+ if (!root.hasAttribute('data-fdy-required')) return '';
3079
3121
  if ((root.getAttribute('data-value') || '') !== '') return '';
3080
3122
  var form = root.closest('form');
3081
3123
  return root.getAttribute('data-fdy-msg-required')
@@ -3122,6 +3164,17 @@
3122
3164
  return custom || el.getAttribute('data-fdy-msg') || (alias && textOf(form, alias)) || el.validationMessage || textOf(form, 'invalid');
3123
3165
  }
3124
3166
 
3167
+ /* Two controls can share one `.fdy-field` and so one message slot: a date range's two ends, or two
3168
+ native inputs side by side. The slot is found per FIELD, so clearing the end that was filled
3169
+ used to erase the message the other end still needed, leaving it red with nothing to say why
3170
+ (#114). The slot is kept while any other control that points at it is still invalid. */
3171
+ function stillClaimed(errEl, except) {
3172
+ var scope = except.closest('form') || document;
3173
+ return Array.prototype.some.call(scope.querySelectorAll('[aria-invalid="true"]'), function (other) {
3174
+ return other !== except && (other.getAttribute('aria-describedby') || '').split(/\s+/).indexOf(errEl.id) !== -1;
3175
+ });
3176
+ }
3177
+
3125
3178
  function paint(el, message) {
3126
3179
  var errEl = ensureErrorEl(el);
3127
3180
  if (message) {
@@ -3130,6 +3183,7 @@
3130
3183
  errEl.hidden = false;
3131
3184
  } else {
3132
3185
  el.removeAttribute('aria-invalid');
3186
+ if (stillClaimed(errEl, el)) return;
3133
3187
  errEl.textContent = '';
3134
3188
  errEl.hidden = true;
3135
3189
  }
@@ -3187,7 +3241,7 @@
3187
3241
  root.dataset.fdyKitBound = '1';
3188
3242
  new MutationObserver(function () {
3189
3243
  if (submitted || eager) validateKit(root);
3190
- }).observe(root, { attributes: true, attributeFilter: ['data-value'] });
3244
+ }).observe(root, { attributes: true, attributeFilter: ['data-value', 'data-fdy-required'] });
3191
3245
  }
3192
3246
  function validateOne(el) {
3193
3247
  var msg = messageFor(el);
@@ -3901,6 +3955,7 @@
3901
3955
  var options = Array.prototype.slice.call(root.querySelectorAll('.fdy-combo__option'));
3902
3956
  if (!button || !listbox || !valueEl || options.length === 0) return;
3903
3957
  root.dataset.fdyComboReady = '1';
3958
+ root._fdyInvalid = button.getAttribute('aria-invalid') === 'true';
3904
3959
 
3905
3960
  seq += 1;
3906
3961
  if (!listbox.id) listbox.id = 'fdy-combo-list-' + seq;
@@ -4084,10 +4139,16 @@
4084
4139
  if (state.readonly) button.setAttribute('aria-readonly', 'true');
4085
4140
  else button.removeAttribute('aria-readonly');
4086
4141
  }
4087
- if (state.invalid != null) {
4142
+ /* `invalid` is written only when the HOST changes it. A render-once host (Blazor) pushes every
4143
+ state on every parent re-render, and rewriting an unchanged `false` erased the mark
4144
+ freeday-form.js had painted, leaving its message under a field no longer red (#114). */
4145
+ if (state.invalid != null && !!state.invalid !== root._fdyInvalid) {
4146
+ root._fdyInvalid = !!state.invalid;
4088
4147
  if (state.invalid) button.setAttribute('aria-invalid', 'true');
4089
4148
  else button.removeAttribute('aria-invalid');
4090
4149
  }
4150
+ /* `required` too: a render-once host (Blazor) has no other way to change it later (#114). */
4151
+ if (state.required != null) root.toggleAttribute('data-fdy-required', !!state.required);
4091
4152
  }
4092
4153
 
4093
4154
  window.FreedayCombo = { init: initCombo, initAll: initAll, setValue: setValue, setState: setState };
@@ -5456,16 +5517,26 @@
5456
5517
  trigger.disabled = stateDisabled;
5457
5518
  if (stateReadonly) trigger.setAttribute('aria-readonly', 'true');
5458
5519
  else trigger.removeAttribute('aria-readonly');
5520
+ if ((stateDisabled || stateReadonly) && !panel.hidden) close(false);
5521
+ }
5522
+ /* `invalid` is written only when the HOST changes it. A render-once host (Blazor) pushes every
5523
+ state on every parent re-render, and rewriting an unchanged `false` erased the mark
5524
+ freeday-form.js had painted, leaving its message under a field no longer red (#114). */
5525
+ function applyInvalid() {
5459
5526
  if (stateInvalid) trigger.setAttribute('aria-invalid', 'true');
5460
5527
  else trigger.removeAttribute('aria-invalid');
5461
5528
  wrap.classList.toggle('fdy-timepicker--error', stateInvalid);
5462
- if ((stateDisabled || stateReadonly) && !panel.hidden) close(false);
5463
5529
  }
5464
5530
  function setState(next) {
5465
5531
  if (!next) return;
5466
5532
  if (next.disabled != null) stateDisabled = !!next.disabled;
5467
5533
  if (next.readonly != null) stateReadonly = !!next.readonly;
5468
- if (next.invalid != null) stateInvalid = !!next.invalid;
5534
+ if (next.invalid != null && !!next.invalid !== stateInvalid) {
5535
+ stateInvalid = !!next.invalid;
5536
+ applyInvalid();
5537
+ }
5538
+ /* `required` too: a render-once host (Blazor) has no other way to change it later (#114). */
5539
+ if (next.required != null) wrap.toggleAttribute('data-fdy-required', !!next.required);
5469
5540
  applyState();
5470
5541
  }
5471
5542
 
@@ -5553,6 +5624,7 @@
5553
5624
 
5554
5625
  updateDisplay();
5555
5626
  applyState();
5627
+ applyInvalid();
5556
5628
 
5557
5629
  var api = {
5558
5630
  wrap: wrap,
@@ -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.18.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.18.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/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",