@iyulab/components 2.19.1 → 2.20.1

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
@@ -1,5 +1,36 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.20.1] - 2026-10-12
4
+
5
+ ### Fixed
6
+
7
+ - `u-date-picker` and `u-date-range-picker` in `mode="datetime"` read a value written with another offset as the
8
+ instant it names. A value such as `2026-09-06T22:22:34Z` showed `22:22` on a `+09:00` machine, and editing it wrote
9
+ that wall clock back with the local offset, moving the stored instant by nine hours. The picker now shows the local
10
+ time of that instant, writes edits in the local offset for the same moment, and keeps the given string (no `change`)
11
+ when a pick leaves the instant as it was. `start` and `end` on the range picker still return the halves as written.
12
+
13
+ ## [2.20.0] - 2026-10-10
14
+
15
+ ### Changed
16
+
17
+ - `required` on `u-field` makes the control it labels required. It only drew the marker, so a field shown as required
18
+ submitted empty unless the control also carried `required`. A field wrapping several controls keeps the marker only;
19
+ turning `required` off on the field removes only the `required` the field set.
20
+ - Form controls show their error when a submit attempt or `form.reportValidity()` on the owning `<form>` blocks
21
+ submission. Submission was blocked but no control showed why. To check without showing errors, call the control's
22
+ `validate(false)` — a page-level `form.checkValidity()` fires the same `invalid` event and shows errors too.
23
+ - `u-form.validate()` moves focus to the first invalid control and takes `report` like a control's `validate()`:
24
+ `validate(false)` checks without touching the screen.
25
+
26
+ ### Fixed
27
+
28
+ - `u-form` saw only its direct children, so a control wrapped in `u-field` or a layout element was not validated, synced
29
+ from `model`, or reset — an empty required field reported the form valid. It now covers every control inside it, up
30
+ to a nested `u-form`, and validates all of them instead of stopping at the first invalid one.
31
+ - `validate()` judged the previous value when the value was set in the same tick (`el.value = x; el.validate()`, and
32
+ `form.model = …; form.validate()`), and left the error on. It now completes a pending render first.
33
+
3
34
  ## [2.19.1] - 2026-10-09
4
35
 
5
36
  ### Changed
@@ -6,6 +6,15 @@ export declare class UElement extends LitElement {
6
6
  private detachedLocaleRevision?;
7
7
  connectedCallback(): void;
8
8
  disconnectedCallback(): void;
9
+ /** `performUpdate()` 안인가 — 렌더 도중에 같은 요소의 렌더를 다시 당기지 않으려고. */
10
+ private updating;
11
+ protected performUpdate(): void;
12
+ /**
13
+ * 대기 중인 렌더를 지금 끝낸다 — **렌더된 상태를 읽는 동기 판정**(검증이 안쪽 네이티브 요소의 `validity` 를
14
+ * 읽는 것 등)이 바로 앞의 속성 변경을 보게 한다. `el.value = x; el.validate()` 가 같은 틱에 바꾸기 전 값으로
15
+ * 판정하던 것을 막는다. 첫 렌더 전이거나 렌더 도중이면 아무것도 하지 않는다.
16
+ */
17
+ protected flushUpdate(): void;
9
18
  /**
10
19
  * 로케일이 바뀌었다(`Locale.set` · `Locale.register`) — 기본은 다시 그린다. 렌더 밖에서 로케일 문장을 담아 둔
11
20
  * 컴포넌트(속성·`ElementInternals`·필드에 적어 둔 이름)는 이것을 재정의해 그 값을 다시 적고 `super` 를 부른다.
@@ -27,6 +27,10 @@ function warnIfTokensMissing() {
27
27
  console.warn("[@iyulab/components] No design-token sheet found in the document — components render with their built-in fallbacks (baked from the light theme). Dark theme and theme variable overrides will not apply.\n Static CSS: import '@iyulab/components/styles/tokens.css'\n At runtime: Theme.init()\n (The @iyulab/modern-app shell calls Theme.init() for you. Screens rendered outside the shell — login, onboarding, embeds — need one of the two.)");
28
28
  }
29
29
  var UElement = class extends LitElement {
30
+ constructor(..._args) {
31
+ super(..._args);
32
+ this.updating = false;
33
+ }
30
34
  static {
31
35
  this.styles = styles;
32
36
  }
@@ -43,6 +47,22 @@ var UElement = class extends LitElement {
43
47
  this.detachedLocaleRevision = Locale.revision;
44
48
  super.disconnectedCallback();
45
49
  }
50
+ performUpdate() {
51
+ this.updating = true;
52
+ try {
53
+ super.performUpdate();
54
+ } finally {
55
+ this.updating = false;
56
+ }
57
+ }
58
+ /**
59
+ * 대기 중인 렌더를 지금 끝낸다 — **렌더된 상태를 읽는 동기 판정**(검증이 안쪽 네이티브 요소의 `validity` 를
60
+ * 읽는 것 등)이 바로 앞의 속성 변경을 보게 한다. `el.value = x; el.validate()` 가 같은 틱에 바꾸기 전 값으로
61
+ * 판정하던 것을 막는다. 첫 렌더 전이거나 렌더 도중이면 아무것도 하지 않는다.
62
+ */
63
+ flushUpdate() {
64
+ if (this.hasUpdated && this.isUpdatePending && !this.updating) this.performUpdate();
65
+ }
46
66
  /**
47
67
  * 로케일이 바뀌었다(`Locale.set` · `Locale.register`) — 기본은 다시 그린다. 렌더 밖에서 로케일 문장을 담아 둔
48
68
  * 컴포넌트(속성·`ElementInternals`·필드에 적어 둔 이름)는 이것을 재정의해 그 값을 다시 적고 `super` 를 부른다.
@@ -74,7 +74,20 @@ export declare abstract class UFormControlElement<T> extends UElement {
74
74
  protected commit(flags: ValidityStateFlags, message: string, anchor?: HTMLElement): void;
75
75
  /** form-associated 표준 콜백 — 조상 fieldset 의 비활성 상태가 바뀔 때 UA 가 부른다. */
76
76
  formDisabledCallback(disabled: boolean): void;
77
+ constructor();
77
78
  connectedCallback(): void;
79
+ /** 자기 `validate()` 가 `internals.checkValidity()` 를 부르는 동안 — 그때 오는 `invalid` 는 보고가 아니다. */
80
+ private quietCheck;
81
+ /**
82
+ * UA 가 보낸 `invalid` 에서 오류를 보인다 — 소속 `<form>` 의 제출 시도(`requestSubmit()`·제출 버튼)와
83
+ * `form.reportValidity()` 가 이 경로다. 그러지 않으면 제출은 막히는데 어느 칸이 틀렸는지 화면에 아무것도
84
+ * 없다. 해제는 종전대로 값이 바뀐 뒤의 `validate()` 가 한다.
85
+ *
86
+ * 자기 `validate()` 의 조용한 확인과 합성 이벤트는 무시한다. ⚠`invalid` 이벤트는 자기를 부른 메서드를
87
+ * 알려 주지 않아(`checkValidity()` 도 같은 이벤트를 낸다) 페이지가 직접 부른 `form.checkValidity()` 도
88
+ * 오류를 보인다 — 플랫폼 한계다. 조용히 확인하려면 컨트롤의 `validate(false)` 나 `u-form.validate(false)` 를 쓴다.
89
+ */
90
+ private handleInvalid;
78
91
  /**
79
92
  * 검증 메시지는 `setValidity()` 가 `internals` 에 적어 둔 문장이다 — 다시 그리기만 하면 옛 언어가 그대로 나온다.
80
93
  * 첫 렌더 뒤라면(검증이 참조하는 안쪽 컨트롤이 있을 때) 다시 계산하고 그린다.
@@ -9,21 +9,6 @@ import { property, state } from "lit/decorators.js";
9
9
  * 사용자 입력을 받는 모든 컴포넌트가 이 클래스를 확장합니다.
10
10
  */
11
11
  var UFormControlElement = class extends UElement {
12
- constructor(..._args) {
13
- super(..._args);
14
- this.disabled = false;
15
- this.formDisabled = false;
16
- this.readonly = false;
17
- this.required = false;
18
- this.invalid = false;
19
- this.novalidate = false;
20
- this.customMessage = "";
21
- this.hasSlottedLabel = false;
22
- this.handleLabelSlotChange = (e) => {
23
- const slot = e.target;
24
- this.hasSlottedLabel = slot.assignedNodes({ flatten: true }).some((n) => n.nodeType === Node.ELEMENT_NODE || !!n.textContent?.trim());
25
- };
26
- }
27
12
  static {
28
13
  this.styles = [super.styles, styles];
29
14
  }
@@ -83,6 +68,28 @@ var UFormControlElement = class extends UElement {
83
68
  this.formDisabled = disabled;
84
69
  this.updateComplete.then(() => this.requestUpdate("formDisabled", old));
85
70
  }
71
+ constructor() {
72
+ super();
73
+ this.disabled = false;
74
+ this.formDisabled = false;
75
+ this.readonly = false;
76
+ this.required = false;
77
+ this.invalid = false;
78
+ this.novalidate = false;
79
+ this.customMessage = "";
80
+ this.quietCheck = false;
81
+ this.handleInvalid = (e) => {
82
+ if (this.quietCheck || !e.isTrusted) return;
83
+ this.invalid = true;
84
+ this.requestUpdate();
85
+ };
86
+ this.hasSlottedLabel = false;
87
+ this.handleLabelSlotChange = (e) => {
88
+ const slot = e.target;
89
+ this.hasSlottedLabel = slot.assignedNodes({ flatten: true }).some((n) => n.nodeType === Node.ELEMENT_NODE || !!n.textContent?.trim());
90
+ };
91
+ this.addEventListener("invalid", this.handleInvalid);
92
+ }
86
93
  connectedCallback() {
87
94
  super.connectedCallback();
88
95
  if (!this.internals && "attachInternals" in this) this.internals = this.attachInternals();
@@ -165,9 +172,18 @@ var UFormControlElement = class extends UElement {
165
172
  * @returns 유효하면 `true`, 아니면 `false`
166
173
  */
167
174
  validate(report = true) {
175
+ this.flushUpdate();
168
176
  this.setValidity();
169
177
  this.requestUpdate();
170
- const valid = this.internals ? this.internals.checkValidity() : true;
178
+ let valid = true;
179
+ if (this.internals) {
180
+ this.quietCheck = true;
181
+ try {
182
+ valid = this.internals.checkValidity();
183
+ } finally {
184
+ this.quietCheck = false;
185
+ }
186
+ }
171
187
  if (report) this.invalid = !valid;
172
188
  return valid;
173
189
  }
@@ -1,3 +1,4 @@
1
+ import { sameDateTime } from "./datetime.js";
1
2
  //#region src/components/calendar/date-text-controller.ts
2
3
  /**
3
4
  * The typed-date text box shared by `u-date-picker` and `u-date-range-picker`: what is being typed
@@ -52,8 +53,8 @@ var DateTextController = class {
52
53
  const next = this.options.toValue(text);
53
54
  this.badText = next === null;
54
55
  const value = next ?? void 0;
55
- const changed = value !== this.host.value;
56
- this.host.value = value;
56
+ const changed = !sameDateTime(value, this.host.value);
57
+ if (changed) this.host.value = value;
57
58
  this.draft = this.badText ? text : null;
58
59
  this.host.requestUpdate();
59
60
  if (changed) this.options.onChange();
@@ -3,8 +3,19 @@
3
3
  export declare function localOffset(date: Date): string;
4
4
  /** ISO day + `HH:mm` or `HH:mm:ss` → `YYYY-MM-DDTHH:mm:ss±HH:mm` (the offset of that local day and time). */
5
5
  export declare function toDateTimeOffset(day: string, time: string): string;
6
+ /** A date-time value as this browser's wall clock — `YYYY-MM-DDTHH:mm:ss±HH:mm` in the local offset.
7
+ * A value with an offset is an instant: `2026-09-06T22:22:34Z` reads `2026-09-07T07:22:34+09:00` in
8
+ * Seoul, the same moment. A value without one is already wall clock and comes back as it is, and so
9
+ * does anything that is not a date-time. Every read of a picker value goes through here, so what
10
+ * the picker shows and what it writes back describe the same instant. */
11
+ export declare function toLocalDateTime(value: string): string;
12
+ /** Whether two picker values are the same — a day, a date-time, or a `start/end` interval of either,
13
+ * compared half by half as instants when they carry offsets. A value written back in the local
14
+ * offset is then not a change from the `…Z` it came from, and the picker keeps the string it was given. */
15
+ export declare function sameDateTime(a: string | undefined, b: string | undefined): boolean;
6
16
  /** Splits a value into its ISO day and its time — `HH:mm`, or `HH:mm:ss` with `seconds`
7
- * (`00:00` when there is no time part). */
17
+ * (`00:00` when there is no time part). A value with an offset is read as this browser's wall clock
18
+ * ({@link toLocalDateTime}). */
8
19
  export declare function splitDateTime(value: string, seconds?: boolean): {
9
20
  day: string;
10
21
  time: string;
@@ -15,10 +15,34 @@ function toDateTimeOffset(day, time) {
15
15
  local.setHours(h, m, s);
16
16
  return `${day}T${normalizeTime(time, true)}${localOffset(local)}`;
17
17
  }
18
+ /** A date-time with a UTC designator or offset after its time (`…Z`, `…+09:00`, `…-0530`). */
19
+ var WITH_OFFSET = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})$/i;
20
+ /** A date-time value as this browser's wall clock — `YYYY-MM-DDTHH:mm:ss±HH:mm` in the local offset.
21
+ * A value with an offset is an instant: `2026-09-06T22:22:34Z` reads `2026-09-07T07:22:34+09:00` in
22
+ * Seoul, the same moment. A value without one is already wall clock and comes back as it is, and so
23
+ * does anything that is not a date-time. Every read of a picker value goes through here, so what
24
+ * the picker shows and what it writes back describe the same instant. */
25
+ function toLocalDateTime(value) {
26
+ if (!WITH_OFFSET.test(value)) return value;
27
+ const instant = new Date(value);
28
+ if (Number.isNaN(instant.getTime())) return value;
29
+ const pad = (n) => String(n).padStart(2, "0");
30
+ return toDateTimeOffset(`${instant.getFullYear()}-${pad(instant.getMonth() + 1)}-${pad(instant.getDate())}`, `${pad(instant.getHours())}:${pad(instant.getMinutes())}:${pad(instant.getSeconds())}`);
31
+ }
32
+ /** Whether two picker values are the same — a day, a date-time, or a `start/end` interval of either,
33
+ * compared half by half as instants when they carry offsets. A value written back in the local
34
+ * offset is then not a change from the `…Z` it came from, and the picker keeps the string it was given. */
35
+ function sameDateTime(a, b) {
36
+ if (a === b) return true;
37
+ if (!a || !b) return false;
38
+ const local = (v) => v.split("/").map(toLocalDateTime).join("/");
39
+ return local(a) === local(b);
40
+ }
18
41
  /** Splits a value into its ISO day and its time — `HH:mm`, or `HH:mm:ss` with `seconds`
19
- * (`00:00` when there is no time part). */
42
+ * (`00:00` when there is no time part). A value with an offset is read as this browser's wall clock
43
+ * ({@link toLocalDateTime}). */
20
44
  function splitDateTime(value, seconds = false) {
21
- const [day, rest] = value.split("T");
45
+ const [day, rest] = toLocalDateTime(value).split("T");
22
46
  const match = rest?.match(/^\d{2}:\d{2}(?::\d{2})?/);
23
47
  return {
24
48
  day,
@@ -32,4 +56,4 @@ function normalizeTime(time, seconds) {
32
56
  return seconds ? `${hm}:${time.slice(6, 8) || "00"}` : hm;
33
57
  }
34
58
  //#endregion
35
- export { localOffset, normalizeTime, splitDateTime, toDateTimeOffset };
59
+ export { localOffset, normalizeTime, sameDateTime, splitDateTime, toDateTimeOffset, toLocalDateTime };
@@ -10,8 +10,8 @@ import { UCalendar } from "../calendar/UCalendar.js";
10
10
  import "../field/UField.js";
11
11
  import { UPopover } from "../popover/UPopover.js";
12
12
  import { CharsWidthController } from "../../utilities/chars.js";
13
+ import { normalizeTime, sameDateTime, splitDateTime, toDateTimeOffset } from "../calendar/datetime.js";
13
14
  import { DateTextController } from "../calendar/date-text-controller.js";
14
- import { normalizeTime, splitDateTime, toDateTimeOffset } from "../calendar/datetime.js";
15
15
  import { styles } from "../calendar/picker.styles.js";
16
16
  import { styles as styles$1 } from "./UDatePicker.styles.js";
17
17
  import { html } from "lit";
@@ -81,9 +81,9 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
81
81
  }
82
82
  if (!this.value) return;
83
83
  const iso = buildValue(splitValue(this.value).date, this.mode, time);
84
- const changed = iso !== this.value;
84
+ const changed = !sameDateTime(iso, this.value);
85
85
  this.textEntry.clear();
86
- this.value = iso;
86
+ if (changed) this.value = iso;
87
87
  if (changed) this.emitChange();
88
88
  };
89
89
  this.handleDaySelect = (e) => {
@@ -124,9 +124,9 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
124
124
  };
125
125
  this.handleApplyClick = () => {
126
126
  const next = this.staged;
127
- const changed = next !== this.value;
127
+ const changed = !sameDateTime(next, this.value);
128
128
  this.textEntry.clear();
129
- this.value = next;
129
+ if (changed) this.value = next;
130
130
  if (changed) this.emitChange();
131
131
  this.popoverEl?.hide();
132
132
  (this.textInputEl ?? this.containerEl)?.focus();
@@ -313,9 +313,9 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
313
313
  this.staged = iso;
314
314
  return;
315
315
  }
316
- const changed = iso !== this.value;
316
+ const changed = !sameDateTime(iso, this.value);
317
317
  this.textEntry.clear();
318
- this.value = iso;
318
+ if (changed) this.value = iso;
319
319
  if (changed) this.emitChange();
320
320
  this.popoverEl?.hide();
321
321
  (this.textInputEl ?? this.containerEl)?.focus();
@@ -11,8 +11,8 @@ import { UCalendar } from "../calendar/UCalendar.js";
11
11
  import "../field/UField.js";
12
12
  import { UPopover } from "../popover/UPopover.js";
13
13
  import { CharsWidthController } from "../../utilities/chars.js";
14
+ import { normalizeTime, sameDateTime, splitDateTime, toDateTimeOffset, toLocalDateTime } from "../calendar/datetime.js";
14
15
  import { DateTextController } from "../calendar/date-text-controller.js";
15
- import { normalizeTime, splitDateTime, toDateTimeOffset } from "../calendar/datetime.js";
16
16
  import { styles } from "../calendar/picker.styles.js";
17
17
  import { resolvePresets } from "./presets.js";
18
18
  import { styles as styles$1 } from "./UDateRangePicker.styles.js";
@@ -22,14 +22,18 @@ import { ifDefined } from "lit/directives/if-defined.js";
22
22
  //#region src/components/date-range-picker/UDateRangePicker.ts
23
23
  var ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
24
24
  var ISO_DATE_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/;
25
- /** Splits `"start/end"` into its two halves — ISO dates, or in `mode="datetime"` ISO date-times;
26
- * `undefined` unless both halves have that shape. */
27
- function parseInterval(value, mode) {
25
+ /** Splits `"start/end"` into its two halves — ISO dates, or in `mode="datetime"` ISO date-times read
26
+ * as this browser's wall clock (a half with an offset is an instant — `toLocalDateTime`), or as
27
+ * written with `local` off; `undefined` unless both halves have that shape. */
28
+ function parseInterval(value, mode, local = true) {
28
29
  if (!value) return void 0;
29
30
  const [start, end, ...rest] = value.split("/");
30
31
  const shape = mode === "datetime" ? ISO_DATE_TIME : ISO_DATE;
31
32
  if (rest.length || !shape.test(start ?? "") || !shape.test(end ?? "")) return void 0;
32
- return {
33
+ return mode === "datetime" && local ? {
34
+ start: toLocalDateTime(start),
35
+ end: toLocalDateTime(end)
36
+ } : {
33
37
  start,
34
38
  end
35
39
  };
@@ -38,8 +42,8 @@ function parseInterval(value, mode) {
38
42
  function reversed(start, end, mode) {
39
43
  return mode === "datetime" ? new Date(start).getTime() > new Date(end).getTime() : start > end;
40
44
  }
41
- /** The ISO day of a half (`YYYY-MM-DD` either way). */
42
- var dayPart = (half) => half.slice(0, 10);
45
+ /** The ISO day of a half (`YYYY-MM-DD` either way) — a half with an offset on this browser's wall clock. */
46
+ var dayPart = (half) => splitDateTime(half).day;
43
47
  var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
44
48
  constructor(..._args) {
45
49
  super(..._args);
@@ -139,12 +143,12 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
139
143
  /** Start of the range — the ISO day, or in `mode="datetime"` the ISO date-time; `undefined` when
140
144
  * there is no complete range. */
141
145
  get start() {
142
- return parseInterval(this.value, this.mode)?.start;
146
+ return parseInterval(this.value, this.mode, false)?.start;
143
147
  }
144
148
  /** End of the range — the ISO day, or in `mode="datetime"` the ISO date-time; `undefined` when
145
149
  * there is no complete range. */
146
150
  get end() {
147
- return parseInterval(this.value, this.mode)?.end;
151
+ return parseInterval(this.value, this.mode, false)?.end;
148
152
  }
149
153
  /** Times a whole-day range takes in `mode="datetime"` — a preset or a first calendar pick: from
150
154
  * the first minute (or second, with `seconds`) to the last. */
@@ -360,9 +364,9 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
360
364
  this.staged = next;
361
365
  return;
362
366
  }
363
- const changed = next !== this.value;
367
+ const changed = !sameDateTime(next, this.value);
364
368
  this.textEntry.clear();
365
- this.value = next;
369
+ if (changed) this.value = next;
366
370
  if (changed) this.emitChange();
367
371
  }
368
372
  renderPresets(presets) {
@@ -370,7 +374,7 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
370
374
  <div class="presets" part="presets" role="group" aria-label=${Locale.getValue("quickRanges")}>
371
375
  ${presets.map((p) => html`
372
376
  <button type="button" class="preset" part="preset"
373
- aria-pressed=${this.build(p.start, p.end, this.wholeDay) === this.working}
377
+ aria-pressed=${sameDateTime(this.build(p.start, p.end, this.wholeDay), this.working)}
374
378
  ?disabled=${this.unavailable(p)}
375
379
  @click=${() => this.commitRange(p.start, p.end, this.wholeDay)}
376
380
  >${p.label}</button>
@@ -401,9 +405,9 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
401
405
  /** Commits `next` as the value (firing `change` when it differs), closes the calendar and
402
406
  * returns focus to the text box. */
403
407
  commitValue(next) {
404
- const changed = next !== this.value;
408
+ const changed = !sameDateTime(next, this.value);
405
409
  this.textEntry.clear();
406
- this.value = next;
410
+ if (changed) this.value = next;
407
411
  if (changed) this.emitChange();
408
412
  this.popoverEl?.hide();
409
413
  this.textInputEl?.focus();
@@ -90,6 +90,15 @@ export declare class UField extends UElement {
90
90
  private get hasControlInSubtree();
91
91
  protected firstUpdated(changed: PropertyValues): void;
92
92
  protected updated(changed: PropertyValues): void;
93
+ /** 이 필드가 `required` 를 켠 컨트롤 — 끌 때는 우리가 켠 것만 끈다(소비자가 단 `required` 는 그대로). */
94
+ private requiredApplied?;
95
+ /**
96
+ * 필드의 `required` 를 그 컨트롤의 **제약**으로 넘긴다. 종전에는 별표만 그리고 컨트롤은 선택 입력으로 남아,
97
+ * `<u-field label="이메일" required><u-input></u-input></u-field>` 가 빈 채로 제출됐다 — 문서 예제가 전부 그
98
+ * 형태였다. 라벨처럼 «이 필드가 가리키는 컨트롤 하나» 에만 넘긴다 — 컨트롤이 여럿인 묶음에서는 어느 것이 필수인지
99
+ * 필드가 알 수 없어 넘기지 않는다(별표만 그린다).
100
+ */
101
+ private syncRequired;
93
102
  /**
94
103
  * 🔴**이 컴포넌트의 존재 이유가 «라벨과 컨트롤을 한 칸으로 짝짓는 것»인데, 오랫동안
95
104
  * 라벨을 «그리기만» 하고 연결하지 않았다** — 섀도의 `label` 에 `for` 가 없고 슬롯된
@@ -153,11 +153,33 @@ var UField = class UField extends UElement {
153
153
  }
154
154
  firstUpdated(changed) {
155
155
  super.firstUpdated(changed);
156
- (this.shadowRoot?.querySelector("slot:not([name])"))?.addEventListener("slotchange", () => this.nameSlottedControl());
156
+ (this.shadowRoot?.querySelector("slot:not([name])"))?.addEventListener("slotchange", () => {
157
+ this.nameSlottedControl();
158
+ this.syncRequired();
159
+ });
157
160
  }
158
161
  updated(changed) {
159
162
  super.updated(changed);
160
163
  if (changed.has("label") || changed.has("description")) this.nameSlottedControl();
164
+ if (changed.has("required")) this.syncRequired();
165
+ }
166
+ /**
167
+ * 필드의 `required` 를 그 컨트롤의 **제약**으로 넘긴다. 종전에는 별표만 그리고 컨트롤은 선택 입력으로 남아,
168
+ * `<u-field label="이메일" required><u-input></u-input></u-field>` 가 빈 채로 제출됐다 — 문서 예제가 전부 그
169
+ * 형태였다. 라벨처럼 «이 필드가 가리키는 컨트롤 하나» 에만 넘긴다 — 컨트롤이 여럿인 묶음에서는 어느 것이 필수인지
170
+ * 필드가 알 수 없어 넘기지 않는다(별표만 그린다).
171
+ */
172
+ syncRequired() {
173
+ const control = this.labelsAGroup ? null : this.controlToName;
174
+ const target = control && "required" in control ? control : null;
175
+ if (this.requiredApplied && (this.requiredApplied !== target || !this.required)) {
176
+ this.requiredApplied.required = false;
177
+ this.requiredApplied = void 0;
178
+ }
179
+ if (this.required && target && !target.required) {
180
+ target.required = true;
181
+ this.requiredApplied = target;
182
+ }
161
183
  }
162
184
  /**
163
185
  * 🔴**이 컴포넌트의 존재 이유가 «라벨과 컨트롤을 한 칸으로 짝짓는 것»인데, 오랫동안
@@ -22,15 +22,23 @@ export declare class UForm extends UElement {
22
22
  protected updated(changedProperties: PropertyValues): void;
23
23
  render(): import('lit-html').TemplateResult<1>;
24
24
  /**
25
- * 폼 내의 모든 포함된 컨트롤을 검증합니다.
25
+ * 폼 안의 포함된 컨트롤을 **전부** 검증합니다 — 첫 오류에서 멈추지 않아 모든 무효 컨트롤이 오류를 보입니다.
26
+ * 컨트롤은 위치와 무관하게 대상입니다(`u-field`·배치용 요소 안의 것 포함 — 네이티브 `form.elements` 와 같다).
27
+ *
28
+ * @param report `true`(기본값)면 각 컨트롤의 오류 표시를 갱신하고 첫 무효 컨트롤로 포커스를 옮긴다
29
+ * (네이티브 `reportValidity()`). `false`면 화면에 영향 없이 유효 여부만 확인한다(`checkValidity()`).
26
30
  * @returns 모든 컨트롤이 유효하면 true, 아니면 false
27
31
  */
28
- validate(): boolean;
32
+ validate(report?: boolean): boolean;
29
33
  /**
30
34
  * 폼 내의 모든 포함된 컨트롤을 스냅샷 값으로 리셋합니다.
31
35
  */
32
36
  reset(): void;
33
37
  private sync;
38
+ /**
39
+ * 포함된 컨트롤을 문서 순서로 모은다 — 슬롯에 배정된 요소 **와 그 자손**이 대상이다. 감싸개(`u-field` 등) 안의
40
+ * 컨트롤도 이 폼의 것이다. 안쪽 `u-form` 의 컨트롤은 그 폼의 것이라 넘지 않는다.
41
+ */
34
42
  private getControls;
35
43
  private isIncluded;
36
44
  private handleSlotChange;
@@ -53,11 +53,19 @@ var UForm = class UForm extends UElement {
53
53
  return html`<slot @slotchange=${this.handleSlotChange}></slot>`;
54
54
  }
55
55
  /**
56
- * 폼 내의 모든 포함된 컨트롤을 검증합니다.
56
+ * 폼 안의 포함된 컨트롤을 **전부** 검증합니다 — 첫 오류에서 멈추지 않아 모든 무효 컨트롤이 오류를 보입니다.
57
+ * 컨트롤은 위치와 무관하게 대상입니다(`u-field`·배치용 요소 안의 것 포함 — 네이티브 `form.elements` 와 같다).
58
+ *
59
+ * @param report `true`(기본값)면 각 컨트롤의 오류 표시를 갱신하고 첫 무효 컨트롤로 포커스를 옮긴다
60
+ * (네이티브 `reportValidity()`). `false`면 화면에 영향 없이 유효 여부만 확인한다(`checkValidity()`).
57
61
  * @returns 모든 컨트롤이 유효하면 true, 아니면 false
58
62
  */
59
- validate() {
60
- return this.getControls().every((control) => control.validate());
63
+ validate(report = true) {
64
+ this.flushUpdate();
65
+ const controls = this.getControls();
66
+ const firstInvalid = controls[controls.map((control) => control.validate(report)).indexOf(false)];
67
+ if (report && firstInvalid) firstInvalid.focus();
68
+ return firstInvalid === void 0;
61
69
  }
62
70
  /**
63
71
  * 폼 내의 모든 포함된 컨트롤을 스냅샷 값으로 리셋합니다.
@@ -75,10 +83,14 @@ var UForm = class UForm extends UElement {
75
83
  if (!this.model) return;
76
84
  for (const control of this.getControls()) if (control.name && control.name in this.model) control.value = this.model[control.name];
77
85
  }
86
+ /**
87
+ * 포함된 컨트롤을 문서 순서로 모은다 — 슬롯에 배정된 요소 **와 그 자손**이 대상이다. 감싸개(`u-field` 등) 안의
88
+ * 컨트롤도 이 폼의 것이다. 안쪽 `u-form` 의 컨트롤은 그 폼의 것이라 넘지 않는다.
89
+ */
78
90
  getControls() {
79
91
  const slot = this.renderRoot.querySelector("slot");
80
92
  if (!slot) return [];
81
- return slot.assignedElements({ flatten: true }).filter((el) => el instanceof UFormControlElement).filter((el) => this.isIncluded(el));
93
+ return slot.assignedElements({ flatten: true }).flatMap((el) => [el, ...el.querySelectorAll("*")]).filter((el) => el instanceof UFormControlElement).filter((el) => el.parentElement?.closest("u-form") === this).filter((el) => this.isIncluded(el));
82
94
  }
83
95
  isIncluded(el) {
84
96
  const name = el.name;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@iyulab/components",
3
3
  "description": "web-components library based on lit-element made by iyulab",
4
- "version": "2.19.1",
4
+ "version": "2.20.1",
5
5
  "keywords": [
6
6
  "iyulab",
7
7
  "components",
@@ -10,7 +10,11 @@ Single-date(-time) selection with a popover calendar. `mode="date"` (default) fo
10
10
  convention as the native `input[type=date]`: an ISO `YYYY-MM-DD` string. `mode="datetime"` adds
11
11
  a time-of-day input and the value becomes a complete ISO-8601 `DateTimeOffset` string
12
12
  (`YYYY-MM-DDTHH:mm:ss±HH:mm`, seconds and the browser's local UTC offset always filled in — the
13
- value is unconditionally valid regardless of how coarse the time input was). Form-associated.
13
+ value is unconditionally valid regardless of how coarse the time input was). A value set with any
14
+ other offset — a server's UTC `…Z` — is read as the instant it names and shown in the browser's local
15
+ time, so `2026-09-06T22:22:34Z` shows `2026-09-07 07:22` in Seoul and picking the next day writes the
16
+ same moment one day later. The value keeps the string it was given until the person changes it.
17
+ Form-associated.
14
18
 
15
19
  > The calendar week always starts on Sunday, regardless of locale.
16
20
 
@@ -45,7 +45,9 @@ exported as `parseDateRange` and `formatDateRangeText`.
45
45
 
46
46
  `mode="datetime"` adds a start time and an end time under the calendar (labelled inputs). Each half of
47
47
  the value is then a complete ISO-8601 `DateTimeOffset` — seconds and the browser's local offset are
48
- always filled in — and `start`/`end` return those halves:
48
+ always filled in — and `start`/`end` return those halves. A half written with another offset (a
49
+ server's UTC `…Z`) is read as an instant and shown in the browser's local time, the same as
50
+ `u-date-picker`:
49
51
 
50
52
  ```html
51
53
  <u-date-range-picker name="shift" label="Shift" mode="datetime"
@@ -85,7 +85,7 @@ because their name normally comes from their own content:
85
85
  | `label` | `string` | — | — | Label text |
86
86
  | `description` | `string` | — | — | Helper text shown below the control |
87
87
  | `validationMessage` | `string` | — | — | Error message shown when `invalid` |
88
- | `required` | `boolean` | `false` | ✓ | Show required marker |
88
+ | `required` | `boolean` | `false` | ✓ | Show the required marker and make the slotted control required (a single control — with several controls the field only shows the marker). Turning it off removes only the `required` the field set |
89
89
  | `invalid` | `boolean` | `false` | ✓ | Show validation error state |
90
90
  | `disabled` | `boolean` | `false` | ✓ | Disable state forwarding |
91
91
 
@@ -7,6 +7,8 @@ import '@iyulab/components/dist/components/form/UForm.js';
7
7
  **Tag:** `u-form`
8
8
 
9
9
  Form group with two-way model binding. Wraps `UFormControlElement`-based controls and observes value changes.
10
+ Controls belong to the form wherever they sit inside it — wrapped in `u-field` or a layout element counts; a nested
11
+ `u-form` keeps its own controls.
10
12
 
11
13
  ```html
12
14
  <u-form id="form">
@@ -29,7 +31,7 @@ form.addEventListener('change', () => {
29
31
  console.log(form.model); // { email: '...', role: '...' }
30
32
  });
31
33
 
32
- // Validate all controls
34
+ // Validate every control: each invalid one shows its error, focus moves to the first
33
35
  if (form.validate()) {
34
36
  submitData(form.model);
35
37
  }
@@ -64,5 +66,5 @@ form.reset();
64
66
 
65
67
  | Method | Returns | Description |
66
68
  |--------|---------|-------------|
67
- | `validate()` | `boolean` | Validate all child controls |
68
- | `reset()` | `void` | Reset all child controls |
69
+ | `validate(report?)` | `boolean` | Validate every control in the form. With `report` (default `true`) each invalid control shows its error and focus moves to the first one, like `form.reportValidity()`; `validate(false)` only checks, like `checkValidity()` |
70
+ | `reset()` | `void` | Restore every control in the form to the model snapshot |