@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.
@@ -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}
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { computed, nextTick, onBeforeUnmount, onMounted, ref, useId, watch, type ComputedRef, type Ref } from 'vue';
2
+ import { computed, nextTick, onBeforeUnmount, onMounted, ref, useAttrs, useId, watch, type ComputedRef, type Ref, type StyleValue } from 'vue';
3
3
  import { usePopover } from '../usePopover';
4
4
 
5
5
  // A controlled Vue port of freeday's autocomplete (src/freeday-autocomplete.js +
@@ -9,6 +9,23 @@ import { usePopover } from '../usePopover';
9
9
  // substring on the trimmed query); pass server-filtered `options` and it stays a no-op re-filter.
10
10
  // `select` is emitted only on commit (the enhancer's fdy-autocomplete-select event).
11
11
 
12
+ // Anything not declared below belongs on the <input> (maxlength, inputmode, name, a per-control
13
+ // data-fdy-msg-required), which is what an author of `<input>` expects; on the wrapper <div> it
14
+ // meant nothing and reported nothing (#115). class and style stay on the root, which is what sizes
15
+ // the control. Read at render, not in a computed: useAttrs() is not reactive.
16
+ defineOptions({ inheritAttrs: false });
17
+ const attrs: Record<string, unknown> = useAttrs();
18
+ function rootClass(): string | undefined {
19
+ return attrs.class as string | undefined;
20
+ }
21
+ function rootStyle(): StyleValue {
22
+ return attrs.style as StyleValue;
23
+ }
24
+ function inputAttrs(): Record<string, unknown> {
25
+ const { class: _class, style: _style, ...rest } = attrs;
26
+ return rest;
27
+ }
28
+
12
29
  const props = defineProps<{
13
30
  modelValue: string;
14
31
  options: ReadonlyArray<string>;
@@ -21,6 +38,10 @@ const props = defineProps<{
21
38
  /** 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
39
  readonly?: boolean;
23
40
  invalid?: boolean;
41
+ /** The native `required`, on the input itself: it is editable, so constraint validation (and so a
42
+ * `data-fdy-validate` form) applies to it as to any input. Not `data-fdy-required`, which is for
43
+ * controls whose trigger is a button (#114). */
44
+ required?: boolean;
24
45
  describedby?: string;
25
46
  }>();
26
47
 
@@ -41,6 +62,8 @@ const inputEl: Ref<HTMLInputElement | null> = ref(null);
41
62
  const listboxEl: Ref<HTMLUListElement | null> = ref(null);
42
63
  const open: Ref<boolean> = ref(false);
43
64
  const active: Ref<number> = ref(-1);
65
+ /** Typed since this list opened. Until then the field's value is not a query (#115). */
66
+ const typed: Ref<boolean> = ref(false);
44
67
 
45
68
  // Render the listbox in the top layer so it escapes any ancestor overflow clip.
46
69
  usePopover(listboxEl, inputEl, open);
@@ -50,7 +73,7 @@ const isReadonly: ComputedRef<boolean> = computed((): boolean => props.readonly
50
73
  const isInvalid: ComputedRef<boolean> = computed((): boolean => props.invalid === true);
51
74
 
52
75
  const filtered: ComputedRef<string[]> = computed((): string[] => {
53
- const q: string = props.modelValue.trim().toLowerCase();
76
+ const q: string = typed.value ? props.modelValue.trim().toLowerCase() : '';
54
77
  return q === '' ? props.options.slice() : props.options.filter((o: string): boolean => o.toLowerCase().includes(q));
55
78
  });
56
79
 
@@ -64,6 +87,7 @@ function openList(): void {
64
87
  function closeList(): void {
65
88
  open.value = false;
66
89
  active.value = -1;
90
+ typed.value = false;
67
91
  }
68
92
  function choose(label: string): void {
69
93
  emit('update:modelValue', label);
@@ -74,6 +98,7 @@ function choose(label: string): void {
74
98
  function onInput(e: Event): void {
75
99
  const target: HTMLInputElement = e.target as HTMLInputElement;
76
100
  emit('update:modelValue', target.value);
101
+ typed.value = true;
77
102
  active.value = -1;
78
103
  openList();
79
104
  }
@@ -129,8 +154,9 @@ watch(active, async (i: number): Promise<void> => {
129
154
  </script>
130
155
 
131
156
  <template>
132
- <div ref="rootEl" class="fdy-autocomplete" @keydown="onKeydown">
157
+ <div ref="rootEl" class="fdy-autocomplete" :class="rootClass()" :style="rootStyle()" @keydown="onKeydown">
133
158
  <input
159
+ v-bind="inputAttrs()"
134
160
  :id="inputId"
135
161
  ref="inputEl"
136
162
  :class="isInvalid ? 'fdy-input fdy-input--error' : 'fdy-input'"
@@ -148,6 +174,7 @@ watch(active, async (i: number): Promise<void> => {
148
174
  :placeholder="placeholder"
149
175
  :disabled="isDisabled"
150
176
  :readonly="isReadonly"
177
+ :required="required === true"
151
178
  :value="modelValue"
152
179
  @input="onInput"
153
180
  @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"]'));
@@ -56,6 +57,7 @@
56
57
  input.removeAttribute('aria-activedescendant');
57
58
  active = -1;
58
59
  clearHighlight();
60
+ showAll();
59
61
  document.removeEventListener('click', onDocClick, true);
60
62
  }
61
63
  function onDocClick(e) { if (!root.contains(e.target)) close(); }
@@ -70,6 +72,14 @@
70
72
  vis[i].scrollIntoView({ block: 'nearest' });
71
73
  }
72
74
 
75
+ /* A list opens whole; only typing narrows it. A value that was already in the field (a default,
76
+ a saved record) is not a query, and filtering by it opened a one-item list that looked broken
77
+ (#115). Reset on close, so the arrow keys reopen it whole as well. */
78
+ function showAll() {
79
+ options.forEach(function (o) { o.hidden = false; });
80
+ if (emptyEl) emptyEl.hidden = options.length !== 0;
81
+ }
82
+
73
83
  function applyFilter() {
74
84
  var q = input.value.trim().toLowerCase();
75
85
  var shown = 0;
@@ -93,7 +103,11 @@
93
103
  }
94
104
 
95
105
  input.addEventListener('input', applyFilter);
96
- input.addEventListener('focus', function () { applyFilter(); });
106
+ input.addEventListener('focus', function () {
107
+ if (!listbox.hidden) return;
108
+ showAll();
109
+ open();
110
+ });
97
111
  input.addEventListener('keydown', function (e) {
98
112
  var vis = visible();
99
113
  switch (e.key) {
@@ -145,10 +159,14 @@
145
159
  if (!input || !state) return;
146
160
  if (state.disabled != null) input.disabled = !!state.disabled;
147
161
  if (state.readonly != null) input.readOnly = !!state.readonly;
148
- if (state.invalid != null) {
162
+ /* Only when the HOST changes it: an unchanged push must not erase what freeday-form.js painted (#114). */
163
+ if (state.invalid != null && !!state.invalid !== root._fdyInvalid) {
164
+ root._fdyInvalid = !!state.invalid;
149
165
  if (state.invalid) input.setAttribute('aria-invalid', 'true');
150
166
  else input.removeAttribute('aria-invalid');
151
167
  }
168
+ /* Native `required` on the input itself: it is editable, so constraint validation applies (#114). */
169
+ if (state.required != null) input.required = !!state.required;
152
170
  }
153
171
 
154
172
  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,