@f-ewald/components 1.22.2 → 1.23.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.
@@ -5,9 +5,24 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
7
  import { LitElement, css, html, nothing } from "lit";
8
- import { customElement, property } from "lit/decorators.js";
8
+ import { customElement, property, queryAssignedElements, state, } from "lit/decorators.js";
9
9
  import { tokens } from "./tokens.js";
10
+ import { formFieldControl, supportsFormFieldControl, } from "./utils/form-field-control.js";
10
11
  let instanceCount = 0;
12
+ const NATIVE_TEXT_INPUT_TYPES = new Set([
13
+ "date",
14
+ "datetime-local",
15
+ "email",
16
+ "month",
17
+ "number",
18
+ "password",
19
+ "search",
20
+ "tel",
21
+ "text",
22
+ "time",
23
+ "url",
24
+ "week",
25
+ ]);
11
26
  /**
12
27
  * Per-field wrapper for a form control: label, slotted control, and an
13
28
  * optional hint or error message, in one consistent unit repeated across a
@@ -15,6 +30,11 @@ let instanceCount = 0;
15
30
  * (`form-select`, `multi-select`, `autocomplete-input`, `ui-checkbox`, etc.)
16
31
  * without intercepting its events or value.
17
32
  *
33
+ * Set `floating-label` for supported text controls (`input`, `textarea`,
34
+ * `autocomplete-input`, `address-autocomplete`, and `text-area`). The label
35
+ * then rests inside an empty field and moves to a smaller top-left position
36
+ * while focused or non-empty. Other controls keep the external label.
37
+ *
18
38
  * The label wraps the default slot for a best-effort visual/click
19
39
  * association only: every existing value-entry control encapsulates its
20
40
  * real `<input>` inside its own shadow DOM, so there is no light-DOM `id` a
@@ -38,7 +58,32 @@ let FormField = class FormField extends LitElement {
38
58
  this.error = "";
39
59
  /** Shows a required indicator next to the label. */
40
60
  this.required = false;
61
+ /** Moves labels inside supported text controls until they receive focus or content. */
62
+ this.floatingLabel = false;
63
+ this._floatingKind = null;
64
+ this._nativeHasValue = false;
41
65
  this.#messageId = `form-field-message-${++instanceCount}`;
66
+ this.#configuredControls = new Set();
67
+ this.#resetForm = null;
68
+ this.#placeholderControl = null;
69
+ this.#placeholder = "";
70
+ this.#accessibleNameControl = null;
71
+ this.#accessibleName = null;
72
+ this.#nativeEventControl = null;
73
+ this.#nativeFocused = false;
74
+ this.#onNativeValueChange = () => this._onControlValueChange();
75
+ this.#onNativeFocus = () => this._onControlFocusIn();
76
+ this.#onNativeBlur = () => this._onControlFocusOut();
77
+ this.#onNativeAnimation = (event) => {
78
+ if (event instanceof AnimationEvent)
79
+ this._onNativeAnimationStart(event);
80
+ };
81
+ this.#onFormReset = () => {
82
+ window.setTimeout(() => {
83
+ this.#updateNativeValue();
84
+ this.#syncNativePlaceholder();
85
+ });
86
+ };
42
87
  }
43
88
  static { this.styles = [
44
89
  tokens,
@@ -75,6 +120,94 @@ let FormField = class FormField extends LitElement {
75
120
  line-height: var(--ui-line-height-tight, 1.25);
76
121
  color: var(--ui-text, #0f172a);
77
122
  }
123
+ .control-label.floating-native {
124
+ position: relative;
125
+ display: block;
126
+ border-radius: var(--ui-radius-sm, 0.25rem);
127
+ background: var(--ui-surface, #ffffff);
128
+ box-shadow: inset 0 0 0 1px var(--ui-border, #e2e8f0);
129
+ }
130
+ .control-label.floating-native:focus-within {
131
+ box-shadow:
132
+ inset 0 0 0 1px var(--ui-primary, #4f46e5),
133
+ var(--ui-focus-ring, 0 0 0 3px rgb(79 70 229 / 0.35));
134
+ }
135
+ .control-label.floating-native .label-text {
136
+ position: absolute;
137
+ top: 50%;
138
+ left: 0.75rem;
139
+ right: 0.75rem;
140
+ z-index: 1;
141
+ overflow: hidden;
142
+ transform: translateY(-50%);
143
+ color: var(--ui-text-muted, #64748b);
144
+ font-weight: var(--ui-font-weight-regular, 400);
145
+ white-space: nowrap;
146
+ text-overflow: ellipsis;
147
+ cursor: text;
148
+ transition:
149
+ top 150ms ease,
150
+ transform 150ms ease,
151
+ font-size 150ms ease;
152
+ }
153
+ .control-label.floating-native.multiline .label-text {
154
+ top: 0.5rem;
155
+ transform: none;
156
+ }
157
+ .control-label.floating-native.has-value .label-text,
158
+ .control-label.floating-native:focus-within .label-text {
159
+ top: 0.25rem;
160
+ transform: none;
161
+ font-size: var(--ui-font-size-xs, 0.6875rem);
162
+ }
163
+ .control-label.floating-native ::slotted(input),
164
+ .control-label.floating-native ::slotted(textarea) {
165
+ display: block;
166
+ box-sizing: border-box;
167
+ width: 100%;
168
+ min-height: 3rem;
169
+ margin: 0;
170
+ padding: 1.25rem 0.75rem 0.25rem;
171
+ border: 0;
172
+ border-radius: var(--ui-radius-sm, 0.25rem);
173
+ color: var(--ui-text, #0f172a);
174
+ background: transparent;
175
+ font-family: var(
176
+ --ui-font,
177
+ ui-sans-serif,
178
+ system-ui,
179
+ sans-serif,
180
+ "Apple Color Emoji",
181
+ "Segoe UI Emoji",
182
+ "Segoe UI Symbol",
183
+ "Noto Color Emoji"
184
+ );
185
+ font-size: var(--ui-font-size-sm, 0.75rem);
186
+ line-height: var(--ui-line-height-tight, 1.25);
187
+ }
188
+ .control-label.floating-native ::slotted(input) {
189
+ height: 3rem;
190
+ }
191
+ .control-label.floating-native ::slotted(textarea) {
192
+ padding-bottom: 0.5rem;
193
+ resize: vertical;
194
+ }
195
+ .control-label.floating-native ::slotted(input:focus-visible),
196
+ .control-label.floating-native ::slotted(textarea:focus-visible) {
197
+ outline: none;
198
+ }
199
+ .control-label.floating-native ::slotted(input:disabled),
200
+ .control-label.floating-native ::slotted(textarea:disabled) {
201
+ cursor: not-allowed;
202
+ opacity: 0.6;
203
+ }
204
+ .control-label.floating-native:has(:disabled) .label-text {
205
+ cursor: not-allowed;
206
+ opacity: 0.6;
207
+ }
208
+ .control-label.floating-native ::slotted(input:-webkit-autofill) {
209
+ animation: form-field-autofill 0.001s;
210
+ }
78
211
  .required-mark {
79
212
  color: var(--ui-danger, #dc2626);
80
213
  }
@@ -98,15 +231,242 @@ let FormField = class FormField extends LitElement {
98
231
  white-space: nowrap;
99
232
  border: 0;
100
233
  }
234
+ @media (prefers-reduced-motion: reduce) {
235
+ .control-label.floating-native .label-text {
236
+ transition: none;
237
+ }
238
+ }
239
+ @keyframes form-field-autofill {
240
+ from {
241
+ opacity: 1;
242
+ }
243
+ to {
244
+ opacity: 1;
245
+ }
246
+ }
247
+ @media (forced-colors: active) {
248
+ .control-label.floating-native {
249
+ border: 1px solid CanvasText;
250
+ box-shadow: none;
251
+ }
252
+ .control-label.floating-native:focus-within {
253
+ outline: 2px solid CanvasText;
254
+ outline-offset: 2px;
255
+ box-shadow: none;
256
+ }
257
+ .control-label.floating-native ::slotted(input:disabled),
258
+ .control-label.floating-native ::slotted(textarea:disabled),
259
+ .control-label.floating-native:has(:disabled) .label-text {
260
+ color: GrayText;
261
+ opacity: 1;
262
+ }
263
+ }
101
264
  `,
102
265
  ]; }
103
266
  #messageId;
267
+ #configuredControls;
268
+ #resetForm;
269
+ #placeholderControl;
270
+ #placeholder;
271
+ #accessibleNameControl;
272
+ #accessibleName;
273
+ #nativeEventControl;
274
+ #nativeFocused;
275
+ #onNativeValueChange;
276
+ #onNativeFocus;
277
+ #onNativeBlur;
278
+ #onNativeAnimation;
279
+ #onFormReset;
280
+ /** Synchronizes label configuration after the component first renders. */
281
+ firstUpdated() {
282
+ this.#syncControls();
283
+ }
284
+ /** Resynchronizes delegated controls when public label configuration changes. */
285
+ updated(changed) {
286
+ if (changed.has("label") ||
287
+ changed.has("required") ||
288
+ changed.has("floatingLabel")) {
289
+ this.#syncControls();
290
+ }
291
+ }
292
+ /** Removes delegated configuration and form listeners when disconnected. */
293
+ disconnectedCallback() {
294
+ super.disconnectedCallback();
295
+ for (const control of this.#configuredControls)
296
+ control[formFieldControl](null);
297
+ this.#configuredControls.clear();
298
+ this.#bindNativePlaceholder(null);
299
+ this.#bindNativeAccessibleName(null);
300
+ this.#bindNativeEvents(null);
301
+ this.#bindResetForm(null);
302
+ }
303
+ /** Handles assigned-control changes and updates the floating-label strategy. */
304
+ _onSlotChange() {
305
+ this.#syncControls();
306
+ }
307
+ /** Tracks native input/textarea content after user edits. */
308
+ _onControlValueChange() {
309
+ if (this._floatingKind !== "native")
310
+ return;
311
+ this.#updateNativeValue();
312
+ this.#syncNativePlaceholder();
313
+ }
314
+ /** Reveals the native placeholder once focus floats the label. */
315
+ _onControlFocusIn() {
316
+ if (this._floatingKind !== "native")
317
+ return;
318
+ this.#nativeFocused = true;
319
+ this.#syncNativePlaceholder();
320
+ }
321
+ /** Hides the native placeholder again when an empty field loses focus. */
322
+ _onControlFocusOut() {
323
+ if (this._floatingKind !== "native")
324
+ return;
325
+ this.#nativeFocused = false;
326
+ this.#syncNativePlaceholder();
327
+ }
328
+ /** Focuses a native control when its shadow-rendered floating label is clicked. */
329
+ _onControlLabelClick(event) {
330
+ if (this._floatingKind !== "native")
331
+ return;
332
+ const control = this.#nativeControl();
333
+ if (!control || event.composedPath().includes(control))
334
+ return;
335
+ control.focus();
336
+ }
337
+ /** Synchronizes native value state when WebKit applies autofill without input events. */
338
+ _onNativeAnimationStart(event) {
339
+ if (this._floatingKind !== "native" ||
340
+ event.animationName !== "form-field-autofill") {
341
+ return;
342
+ }
343
+ this.#updateNativeValue();
344
+ this.#syncNativePlaceholder();
345
+ }
346
+ /** Finds the sole assigned native text control, if present. */
347
+ #nativeControl() {
348
+ if (this._assignedElements?.length !== 1)
349
+ return null;
350
+ const [element] = this._assignedElements;
351
+ if (element instanceof HTMLTextAreaElement)
352
+ return element;
353
+ if (!(element instanceof HTMLInputElement))
354
+ return null;
355
+ return NATIVE_TEXT_INPUT_TYPES.has(element.type) ? element : null;
356
+ }
357
+ /** Pushes current label configuration into a supported slotted control. */
358
+ #syncControls() {
359
+ const assigned = this._assignedElements ?? [];
360
+ const delegated = this.floatingLabel &&
361
+ Boolean(this.label) &&
362
+ assigned.length === 1 &&
363
+ supportsFormFieldControl(assigned[0])
364
+ ? assigned[0]
365
+ : null;
366
+ const native = this.floatingLabel && Boolean(this.label) && !delegated
367
+ ? this.#nativeControl()
368
+ : null;
369
+ const nextConfigured = new Set();
370
+ if (delegated) {
371
+ delegated[formFieldControl]({
372
+ label: this.label,
373
+ required: this.required,
374
+ floating: true,
375
+ });
376
+ nextConfigured.add(delegated);
377
+ }
378
+ for (const control of this.#configuredControls) {
379
+ if (!nextConfigured.has(control))
380
+ control[formFieldControl](null);
381
+ }
382
+ this.#configuredControls = nextConfigured;
383
+ this._floatingKind = delegated ? "delegated" : native ? "native" : null;
384
+ this.#updateNativeValue();
385
+ this.#bindNativePlaceholder(native);
386
+ this.#bindNativeAccessibleName(native);
387
+ this.#bindNativeEvents(native);
388
+ this.#bindResetForm(native?.form ?? null);
389
+ }
390
+ /** Updates whether a native control currently contains a value. */
391
+ #updateNativeValue() {
392
+ this._nativeHasValue = Boolean(this.#nativeControl()?.value);
393
+ }
394
+ /** Preserves the consumer placeholder while floating mode temporarily hides it. */
395
+ #bindNativePlaceholder(control) {
396
+ if (control === this.#placeholderControl) {
397
+ this.#syncNativePlaceholder();
398
+ return;
399
+ }
400
+ if (this.#placeholderControl)
401
+ this.#placeholderControl.placeholder = this.#placeholder;
402
+ this.#placeholderControl = control;
403
+ this.#placeholder = control?.placeholder ?? "";
404
+ this.#nativeFocused = control === document.activeElement;
405
+ this.#syncNativePlaceholder();
406
+ }
407
+ /** Applies the correct placeholder for the native label's focus/value state. */
408
+ #syncNativePlaceholder() {
409
+ if (!this.#placeholderControl)
410
+ return;
411
+ this.#placeholderControl.placeholder =
412
+ this.#nativeFocused || this._nativeHasValue ? this.#placeholder : "";
413
+ }
414
+ /** Applies a shadow-boundary-safe accessible name and restores any prior value. */
415
+ #bindNativeAccessibleName(control) {
416
+ if (control !== this.#accessibleNameControl) {
417
+ if (this.#accessibleNameControl) {
418
+ if (this.#accessibleName == null) {
419
+ this.#accessibleNameControl.removeAttribute("aria-label");
420
+ }
421
+ else {
422
+ this.#accessibleNameControl.setAttribute("aria-label", this.#accessibleName);
423
+ }
424
+ }
425
+ this.#accessibleNameControl = control;
426
+ this.#accessibleName = control?.getAttribute("aria-label") ?? null;
427
+ }
428
+ if (!control)
429
+ return;
430
+ control.setAttribute("aria-label", this.required ? `${this.label} (required)` : this.label);
431
+ }
432
+ /** Moves native field listeners directly between assigned controls. */
433
+ #bindNativeEvents(control) {
434
+ if (control === this.#nativeEventControl)
435
+ return;
436
+ this.#nativeEventControl?.removeEventListener("input", this.#onNativeValueChange);
437
+ this.#nativeEventControl?.removeEventListener("change", this.#onNativeValueChange);
438
+ this.#nativeEventControl?.removeEventListener("focus", this.#onNativeFocus);
439
+ this.#nativeEventControl?.removeEventListener("blur", this.#onNativeBlur);
440
+ this.#nativeEventControl?.removeEventListener("animationstart", this.#onNativeAnimation);
441
+ this.#nativeEventControl = control;
442
+ this.#nativeEventControl?.addEventListener("input", this.#onNativeValueChange);
443
+ this.#nativeEventControl?.addEventListener("change", this.#onNativeValueChange);
444
+ this.#nativeEventControl?.addEventListener("focus", this.#onNativeFocus);
445
+ this.#nativeEventControl?.addEventListener("blur", this.#onNativeBlur);
446
+ this.#nativeEventControl?.addEventListener("animationstart", this.#onNativeAnimation);
447
+ }
448
+ /** Moves the reset listener to the native control's current owner form. */
449
+ #bindResetForm(form) {
450
+ if (form === this.#resetForm)
451
+ return;
452
+ this.#resetForm?.removeEventListener("reset", this.#onFormReset);
453
+ this.#resetForm = form;
454
+ this.#resetForm?.addEventListener("reset", this.#onFormReset);
455
+ }
104
456
  render() {
105
457
  const message = this.error || this.hint;
458
+ const delegatedFloating = this._floatingKind === "delegated";
459
+ const nativeFloating = this._floatingKind === "native";
460
+ const nativeMultiline = nativeFloating && this.#nativeControl() instanceof HTMLTextAreaElement;
106
461
  return html `
107
462
  <div class="field">
108
- <label class="control-label">
109
- ${this.label
463
+ <label
464
+ class="control-label ${nativeFloating ? "floating-native" : ""} ${nativeMultiline
465
+ ? "multiline"
466
+ : ""} ${this._nativeHasValue ? "has-value" : ""}"
467
+ @click=${this._onControlLabelClick}
468
+ >
469
+ ${this.label && !delegatedFloating
110
470
  ? html `<span class="label-text">
111
471
  <span>${this.label}</span>
112
472
  ${this.required
@@ -115,7 +475,7 @@ let FormField = class FormField extends LitElement {
115
475
  : nothing}
116
476
  </span>`
117
477
  : nothing}
118
- <slot></slot>
478
+ <slot @slotchange=${this._onSlotChange}></slot>
119
479
  </label>
120
480
  ${message
121
481
  ? html `<span id=${this.#messageId} class="message ${this.error ? "error" : ""}" role=${this.error ? "alert" : nothing}
@@ -138,6 +498,18 @@ __decorate([
138
498
  __decorate([
139
499
  property({ type: Boolean })
140
500
  ], FormField.prototype, "required", void 0);
501
+ __decorate([
502
+ property({ type: Boolean, reflect: true, attribute: "floating-label" })
503
+ ], FormField.prototype, "floatingLabel", void 0);
504
+ __decorate([
505
+ queryAssignedElements()
506
+ ], FormField.prototype, "_assignedElements", void 0);
507
+ __decorate([
508
+ state()
509
+ ], FormField.prototype, "_floatingKind", void 0);
510
+ __decorate([
511
+ state()
512
+ ], FormField.prototype, "_nativeHasValue", void 0);
141
513
  FormField = __decorate([
142
514
  customElement("form-field")
143
515
  ], FormField);
@@ -1 +1 @@
1
- {"version":3,"file":"form-field.js","sourceRoot":"","sources":["../src/form-field.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,IAAI,aAAa,GAAG,CAAC,CAAC;AAEtB;;;;;;;;;;;;;;;;;;GAkBG;AAEI,IAAM,SAAS,GAAf,MAAM,SAAU,SAAQ,UAAU;IAAlC;;QA8DL,wBAAwB;QACZ,UAAK,GAAG,EAAE,CAAC;QACvB,4EAA4E;QAChE,SAAI,GAAG,EAAE,CAAC;QACtB,uEAAuE;QAC3D,UAAK,GAAG,EAAE,CAAC;QACvB,oDAAoD;QACvB,aAAQ,GAAG,KAAK,CAAC;QAErC,eAAU,GAAG,sBAAsB,EAAE,aAAa,EAAE,CAAC;IA0BhE,CAAC;aAhGiB,WAAM,GAAG;QACvB,MAAM;QACN,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAwDF;KACF,AA3DqB,CA2DpB;IAWO,UAAU,CAA2C;IAErD,MAAM;QACb,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC;QACxC,OAAO,IAAI,CAAA;;;YAGH,IAAI,CAAC,KAAK;YACV,CAAC,CAAC,IAAI,CAAA;wBACM,IAAI,CAAC,KAAK;kBAChB,IAAI,CAAC,QAAQ;gBACb,CAAC,CAAC,IAAI,CAAA;gEACwC;gBAC9C,CAAC,CAAC,OAAO;sBACL;YACV,CAAC,CAAC,OAAO;;;UAGX,OAAO;YACP,CAAC,CAAC,IAAI,CAAA,YAAY,IAAI,CAAC,UAAU,mBAAmB,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,UAAU,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO;iBAC9G,OAAO;cACV;YACJ,CAAC,CAAC,OAAO;;KAEd,CAAC;IACJ,CAAC;CACF,CAAA;AAlCa;IAAX,QAAQ,EAAE;wCAAY;AAEX;IAAX,QAAQ,EAAE;uCAAW;AAEV;IAAX,QAAQ,EAAE;wCAAY;AAEM;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;2CAAkB;AArEnC,SAAS;IADrB,aAAa,CAAC,YAAY,CAAC;GACf,SAAS,CAiGrB","sourcesContent":["import { LitElement, css, html, nothing } from \"lit\";\nimport { customElement, property } from \"lit/decorators.js\";\nimport { tokens } from \"./tokens.js\";\n\nlet instanceCount = 0;\n\n/**\n * Per-field wrapper for a form control: label, slotted control, and an\n * optional hint or error message, in one consistent unit repeated across a\n * form. Purely presentational — composes whatever control is slotted\n * (`form-select`, `multi-select`, `autocomplete-input`, `ui-checkbox`, etc.)\n * without intercepting its events or value.\n *\n * The label wraps the default slot for a best-effort visual/click\n * association only: every existing value-entry control encapsulates its\n * real `<input>` inside its own shadow DOM, so there is no light-DOM `id` a\n * `for` attribute could target from outside, and this component cannot set\n * `aria-describedby`/`aria-invalid` on an arbitrary slotted control's\n * shadow-encapsulated input for the same reason. The error message uses\n * `role=\"alert\"` as the practical accessibility mitigation instead of true\n * `aria-describedby` association.\n *\n * @element form-field\n * @slot - The wrapped form control.\n */\n@customElement(\"form-field\")\nexport class FormField extends LitElement {\n static override styles = [\n tokens,\n css`\n :host {\n display: block;\n }\n .field {\n display: flex;\n flex-direction: column;\n gap: 0.25rem;\n }\n .control-label {\n display: flex;\n flex-direction: column;\n gap: 0.25rem;\n }\n .label-text {\n display: flex;\n align-items: baseline;\n gap: 0.25rem;\n font-family: var(\n --ui-font,\n ui-sans-serif,\n system-ui,\n sans-serif,\n \"Apple Color Emoji\",\n \"Segoe UI Emoji\",\n \"Segoe UI Symbol\",\n \"Noto Color Emoji\"\n );\n font-size: var(--ui-font-size-sm, 0.75rem);\n font-weight: var(--ui-font-weight-medium, 500);\n line-height: var(--ui-line-height-tight, 1.25);\n color: var(--ui-text, #0f172a);\n }\n .required-mark {\n color: var(--ui-danger, #dc2626);\n }\n .message {\n font-size: var(--ui-font-size-xs, 0.6875rem);\n line-height: var(--ui-line-height-tight, 1.25);\n color: var(--ui-text-muted, #64748b);\n }\n .message.error {\n color: var(--ui-danger, #dc2626);\n }\n .sr-only {\n position: absolute;\n width: 1px;\n height: 1px;\n margin: -1px;\n padding: 0;\n overflow: hidden;\n clip: rect(0 0 0 0);\n clip-path: inset(50%);\n white-space: nowrap;\n border: 0;\n }\n `,\n ];\n\n /** Field label text. */\n @property() label = \"\";\n /** Optional helper text shown below the control when there's no `error`. */\n @property() hint = \"\";\n /** Optional error text; replaces the `hint` display when non-empty. */\n @property() error = \"\";\n /** Shows a required indicator next to the label. */\n @property({ type: Boolean }) required = false;\n\n readonly #messageId = `form-field-message-${++instanceCount}`;\n\n override render() {\n const message = this.error || this.hint;\n return html`\n <div class=\"field\">\n <label class=\"control-label\">\n ${this.label\n ? html`<span class=\"label-text\">\n <span>${this.label}</span>\n ${this.required\n ? html`<span class=\"required-mark\" aria-hidden=\"true\">*</span\n ><span class=\"sr-only\"> (required)</span>`\n : nothing}\n </span>`\n : nothing}\n <slot></slot>\n </label>\n ${message\n ? html`<span id=${this.#messageId} class=\"message ${this.error ? \"error\" : \"\"}\" role=${this.error ? \"alert\" : nothing}\n >${message}</span\n >`\n : nothing}\n </div>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"form-field\": FormField;\n }\n}\n"]}
1
+ {"version":3,"file":"form-field.js","sourceRoot":"","sources":["../src/form-field.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAuB,MAAM,KAAK,CAAC;AAC1E,OAAO,EACL,aAAa,EACb,QAAQ,EACR,qBAAqB,EACrB,KAAK,GACN,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EACL,gBAAgB,EAChB,wBAAwB,GAEzB,MAAM,+BAA+B,CAAC;AAEvC,IAAI,aAAa,GAAG,CAAC,CAAC;AACtB,MAAM,uBAAuB,GAAG,IAAI,GAAG,CAAC;IACtC,MAAM;IACN,gBAAgB;IAChB,OAAO;IACP,OAAO;IACP,QAAQ;IACR,UAAU;IACV,QAAQ;IACR,KAAK;IACL,MAAM;IACN,MAAM;IACN,KAAK;IACL,MAAM;CACP,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEI,IAAM,SAAS,GAAf,MAAM,SAAU,SAAQ,UAAU;IAAlC;;QAoLL,wBAAwB;QACZ,UAAK,GAAG,EA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AAS,EAAE,gBAAgB,EAAE,CAAC;gDAClD;AAGL;IADhB,qBAAqB,EAAE;oDAC2B;AAElC;IAAhB,KAAK,EAAE;gDAA6D;AACpD;IAAhB,KAAK,EAAE;kDAAiC;AApM9B,SAAS;IADrB,aAAa,CAAC,YAAY,CAAC;GACf,SAAS,CAmcrB","sourcesContent":["import { LitElement, css, html, nothing, type PropertyValues } from \"lit\";\nimport {\n customElement,\n property,\n queryAssignedElements,\n state,\n} from \"lit/decorators.js\";\nimport { tokens } from \"./tokens.js\";\nimport {\n formFieldControl,\n supportsFormFieldControl,\n type FormFieldControl,\n} from \"./utils/form-field-control.js\";\n\nlet instanceCount = 0;\nconst NATIVE_TEXT_INPUT_TYPES = new Set([\n \"date\",\n \"datetime-local\",\n \"email\",\n \"month\",\n \"number\",\n \"password\",\n \"search\",\n \"tel\",\n \"text\",\n \"time\",\n \"url\",\n \"week\",\n]);\n\n/**\n * Per-field wrapper for a form control: label, slotted control, and an\n * optional hint or error message, in one consistent unit repeated across a\n * form. Purely presentational — composes whatever control is slotted\n * (`form-select`, `multi-select`, `autocomplete-input`, `ui-checkbox`, etc.)\n * without intercepting its events or value.\n *\n * Set `floating-label` for supported text controls (`input`, `textarea`,\n * `autocomplete-input`, `address-autocomplete`, and `text-area`). The label\n * then rests inside an empty field and moves to a smaller top-left position\n * while focused or non-empty. Other controls keep the external label.\n *\n * The label wraps the default slot for a best-effort visual/click\n * association only: every existing value-entry control encapsulates its\n * real `<input>` inside its own shadow DOM, so there is no light-DOM `id` a\n * `for` attribute could target from outside, and this component cannot set\n * `aria-describedby`/`aria-invalid` on an arbitrary slotted control's\n * shadow-encapsulated input for the same reason. The error message uses\n * `role=\"alert\"` as the practical accessibility mitigation instead of true\n * `aria-describedby` association.\n *\n * @element form-field\n * @slot - The wrapped form control.\n */\n@customElement(\"form-field\")\nexport class FormField extends LitElement {\n static override styles = [\n tokens,\n css`\n :host {\n display: block;\n }\n .field {\n display: flex;\n flex-direction: column;\n gap: 0.25rem;\n }\n .control-label {\n display: flex;\n flex-direction: column;\n gap: 0.25rem;\n }\n .label-text {\n display: flex;\n align-items: baseline;\n gap: 0.25rem;\n font-family: var(\n --ui-font,\n ui-sans-serif,\n system-ui,\n sans-serif,\n \"Apple Color Emoji\",\n \"Segoe UI Emoji\",\n \"Segoe UI Symbol\",\n \"Noto Color Emoji\"\n );\n font-size: var(--ui-font-size-sm, 0.75rem);\n font-weight: var(--ui-font-weight-medium, 500);\n line-height: var(--ui-line-height-tight, 1.25);\n color: var(--ui-text, #0f172a);\n }\n .control-label.floating-native {\n position: relative;\n display: block;\n border-radius: var(--ui-radius-sm, 0.25rem);\n background: var(--ui-surface, #ffffff);\n box-shadow: inset 0 0 0 1px var(--ui-border, #e2e8f0);\n }\n .control-label.floating-native:focus-within {\n box-shadow:\n inset 0 0 0 1px var(--ui-primary, #4f46e5),\n var(--ui-focus-ring, 0 0 0 3px rgb(79 70 229 / 0.35));\n }\n .control-label.floating-native .label-text {\n position: absolute;\n top: 50%;\n left: 0.75rem;\n right: 0.75rem;\n z-index: 1;\n overflow: hidden;\n transform: translateY(-50%);\n color: var(--ui-text-muted, #64748b);\n font-weight: var(--ui-font-weight-regular, 400);\n white-space: nowrap;\n text-overflow: ellipsis;\n cursor: text;\n transition:\n top 150ms ease,\n transform 150ms ease,\n font-size 150ms ease;\n }\n .control-label.floating-native.multiline .label-text {\n top: 0.5rem;\n transform: none;\n }\n .control-label.floating-native.has-value .label-text,\n .control-label.floating-native:focus-within .label-text {\n top: 0.25rem;\n transform: none;\n font-size: var(--ui-font-size-xs, 0.6875rem);\n }\n .control-label.floating-native ::slotted(input),\n .control-label.floating-native ::slotted(textarea) {\n display: block;\n box-sizing: border-box;\n width: 100%;\n min-height: 3rem;\n margin: 0;\n padding: 1.25rem 0.75rem 0.25rem;\n border: 0;\n border-radius: var(--ui-radius-sm, 0.25rem);\n color: var(--ui-text, #0f172a);\n background: transparent;\n font-family: var(\n --ui-font,\n ui-sans-serif,\n system-ui,\n sans-serif,\n \"Apple Color Emoji\",\n \"Segoe UI Emoji\",\n \"Segoe UI Symbol\",\n \"Noto Color Emoji\"\n );\n font-size: var(--ui-font-size-sm, 0.75rem);\n line-height: var(--ui-line-height-tight, 1.25);\n }\n .control-label.floating-native ::slotted(input) {\n height: 3rem;\n }\n .control-label.floating-native ::slotted(textarea) {\n padding-bottom: 0.5rem;\n resize: vertical;\n }\n .control-label.floating-native ::slotted(input:focus-visible),\n .control-label.floating-native ::slotted(textarea:focus-visible) {\n outline: none;\n }\n .control-label.floating-native ::slotted(input:disabled),\n .control-label.floating-native ::slotted(textarea:disabled) {\n cursor: not-allowed;\n opacity: 0.6;\n }\n .control-label.floating-native:has(:disabled) .label-text {\n cursor: not-allowed;\n opacity: 0.6;\n }\n .control-label.floating-native ::slotted(input:-webkit-autofill) {\n animation: form-field-autofill 0.001s;\n }\n .required-mark {\n color: var(--ui-danger, #dc2626);\n }\n .message {\n font-size: var(--ui-font-size-xs, 0.6875rem);\n line-height: var(--ui-line-height-tight, 1.25);\n color: var(--ui-text-muted, #64748b);\n }\n .message.error {\n color: var(--ui-danger, #dc2626);\n }\n .sr-only {\n position: absolute;\n width: 1px;\n height: 1px;\n margin: -1px;\n padding: 0;\n overflow: hidden;\n clip: rect(0 0 0 0);\n clip-path: inset(50%);\n white-space: nowrap;\n border: 0;\n }\n @media (prefers-reduced-motion: reduce) {\n .control-label.floating-native .label-text {\n transition: none;\n }\n }\n @keyframes form-field-autofill {\n from {\n opacity: 1;\n }\n to {\n opacity: 1;\n }\n }\n @media (forced-colors: active) {\n .control-label.floating-native {\n border: 1px solid CanvasText;\n box-shadow: none;\n }\n .control-label.floating-native:focus-within {\n outline: 2px solid CanvasText;\n outline-offset: 2px;\n box-shadow: none;\n }\n .control-label.floating-native ::slotted(input:disabled),\n .control-label.floating-native ::slotted(textarea:disabled),\n .control-label.floating-native:has(:disabled) .label-text {\n color: GrayText;\n opacity: 1;\n }\n }\n `,\n ];\n\n /** Field label text. */\n @property() label = \"\";\n /** Optional helper text shown below the control when there's no `error`. */\n @property() hint = \"\";\n /** Optional error text; replaces the `hint` display when non-empty. */\n @property() error = \"\";\n /** Shows a required indicator next to the label. */\n @property({ type: Boolean }) required = false;\n /** Moves labels inside supported text controls until they receive focus or content. */\n @property({ type: Boolean, reflect: true, attribute: \"floating-label\" })\n floatingLabel = false;\n\n @queryAssignedElements()\n private readonly _assignedElements!: HTMLElement[];\n\n @state() private _floatingKind: \"delegated\" | \"native\" | null = null;\n @state() private _nativeHasValue = false;\n\n readonly #messageId = `form-field-message-${++instanceCount}`;\n #configuredControls = new Set<FormFieldControl>();\n #resetForm: HTMLFormElement | null = null;\n #placeholderControl: HTMLInputElement | HTMLTextAreaElement | null = null;\n #placeholder = \"\";\n #accessibleNameControl: HTMLInputElement | HTMLTextAreaElement | null = null;\n #accessibleName: string | null = null;\n #nativeEventControl: HTMLInputElement | HTMLTextAreaElement | null = null;\n #nativeFocused = false;\n readonly #onNativeValueChange = () => this._onControlValueChange();\n readonly #onNativeFocus = () => this._onControlFocusIn();\n readonly #onNativeBlur = () => this._onControlFocusOut();\n readonly #onNativeAnimation = (event: Event) => {\n if (event instanceof AnimationEvent) this._onNativeAnimationStart(event);\n };\n readonly #onFormReset = () => {\n window.setTimeout(() => {\n this.#updateNativeValue();\n this.#syncNativePlaceholder();\n });\n };\n\n /** Synchronizes label configuration after the component first renders. */\n protected override firstUpdated(): void {\n this.#syncControls();\n }\n\n /** Resynchronizes delegated controls when public label configuration changes. */\n protected override updated(changed: PropertyValues<this>): void {\n if (\n changed.has(\"label\") ||\n changed.has(\"required\") ||\n changed.has(\"floatingLabel\")\n ) {\n this.#syncControls();\n }\n }\n\n /** Removes delegated configuration and form listeners when disconnected. */\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n for (const control of this.#configuredControls) control[formFieldControl](null);\n this.#configuredControls.clear();\n this.#bindNativePlaceholder(null);\n this.#bindNativeAccessibleName(null);\n this.#bindNativeEvents(null);\n this.#bindResetForm(null);\n }\n\n /** Handles assigned-control changes and updates the floating-label strategy. */\n private _onSlotChange(): void {\n this.#syncControls();\n }\n\n /** Tracks native input/textarea content after user edits. */\n private _onControlValueChange(): void {\n if (this._floatingKind !== \"native\") return;\n this.#updateNativeValue();\n this.#syncNativePlaceholder();\n }\n\n /** Reveals the native placeholder once focus floats the label. */\n private _onControlFocusIn(): void {\n if (this._floatingKind !== \"native\") return;\n this.#nativeFocused = true;\n this.#syncNativePlaceholder();\n }\n\n /** Hides the native placeholder again when an empty field loses focus. */\n private _onControlFocusOut(): void {\n if (this._floatingKind !== \"native\") return;\n this.#nativeFocused = false;\n this.#syncNativePlaceholder();\n }\n\n /** Focuses a native control when its shadow-rendered floating label is clicked. */\n private _onControlLabelClick(event: MouseEvent): void {\n if (this._floatingKind !== \"native\") return;\n const control = this.#nativeControl();\n if (!control || event.composedPath().includes(control)) return;\n control.focus();\n }\n\n /** Synchronizes native value state when WebKit applies autofill without input events. */\n private _onNativeAnimationStart(event: AnimationEvent): void {\n if (\n this._floatingKind !== \"native\" ||\n event.animationName !== \"form-field-autofill\"\n ) {\n return;\n }\n this.#updateNativeValue();\n this.#syncNativePlaceholder();\n }\n\n /** Finds the sole assigned native text control, if present. */\n #nativeControl(): HTMLInputElement | HTMLTextAreaElement | null {\n if (this._assignedElements?.length !== 1) return null;\n const [element] = this._assignedElements;\n if (element instanceof HTMLTextAreaElement) return element;\n if (!(element instanceof HTMLInputElement)) return null;\n return NATIVE_TEXT_INPUT_TYPES.has(element.type) ? element : null;\n }\n\n /** Pushes current label configuration into a supported slotted control. */\n #syncControls(): void {\n const assigned = this._assignedElements ?? [];\n const delegated =\n this.floatingLabel &&\n Boolean(this.label) &&\n assigned.length === 1 &&\n supportsFormFieldControl(assigned[0])\n ? assigned[0]\n : null;\n const native =\n this.floatingLabel && Boolean(this.label) && !delegated\n ? this.#nativeControl()\n : null;\n const nextConfigured = new Set<FormFieldControl>();\n\n if (delegated) {\n delegated[formFieldControl]({\n label: this.label,\n required: this.required,\n floating: true,\n });\n nextConfigured.add(delegated);\n }\n for (const control of this.#configuredControls) {\n if (!nextConfigured.has(control)) control[formFieldControl](null);\n }\n this.#configuredControls = nextConfigured;\n\n this._floatingKind = delegated ? \"delegated\" : native ? \"native\" : null;\n this.#updateNativeValue();\n this.#bindNativePlaceholder(native);\n this.#bindNativeAccessibleName(native);\n this.#bindNativeEvents(native);\n this.#bindResetForm(native?.form ?? null);\n }\n\n /** Updates whether a native control currently contains a value. */\n #updateNativeValue(): void {\n this._nativeHasValue = Boolean(this.#nativeControl()?.value);\n }\n\n /** Preserves the consumer placeholder while floating mode temporarily hides it. */\n #bindNativePlaceholder(\n control: HTMLInputElement | HTMLTextAreaElement | null,\n ): void {\n if (control === this.#placeholderControl) {\n this.#syncNativePlaceholder();\n return;\n }\n if (this.#placeholderControl) this.#placeholderControl.placeholder = this.#placeholder;\n this.#placeholderControl = control;\n this.#placeholder = control?.placeholder ?? \"\";\n this.#nativeFocused = control === document.activeElement;\n this.#syncNativePlaceholder();\n }\n\n /** Applies the correct placeholder for the native label's focus/value state. */\n #syncNativePlaceholder(): void {\n if (!this.#placeholderControl) return;\n this.#placeholderControl.placeholder =\n this.#nativeFocused || this._nativeHasValue ? this.#placeholder : \"\";\n }\n\n /** Applies a shadow-boundary-safe accessible name and restores any prior value. */\n #bindNativeAccessibleName(\n control: HTMLInputElement | HTMLTextAreaElement | null,\n ): void {\n if (control !== this.#accessibleNameControl) {\n if (this.#accessibleNameControl) {\n if (this.#accessibleName == null) {\n this.#accessibleNameControl.removeAttribute(\"aria-label\");\n } else {\n this.#accessibleNameControl.setAttribute(\"aria-label\", this.#accessibleName);\n }\n }\n this.#accessibleNameControl = control;\n this.#accessibleName = control?.getAttribute(\"aria-label\") ?? null;\n }\n if (!control) return;\n control.setAttribute(\n \"aria-label\",\n this.required ? `${this.label} (required)` : this.label,\n );\n }\n\n /** Moves native field listeners directly between assigned controls. */\n #bindNativeEvents(control: HTMLInputElement | HTMLTextAreaElement | null): void {\n if (control === this.#nativeEventControl) return;\n this.#nativeEventControl?.removeEventListener(\"input\", this.#onNativeValueChange);\n this.#nativeEventControl?.removeEventListener(\"change\", this.#onNativeValueChange);\n this.#nativeEventControl?.removeEventListener(\"focus\", this.#onNativeFocus);\n this.#nativeEventControl?.removeEventListener(\"blur\", this.#onNativeBlur);\n this.#nativeEventControl?.removeEventListener(\n \"animationstart\",\n this.#onNativeAnimation,\n );\n this.#nativeEventControl = control;\n this.#nativeEventControl?.addEventListener(\"input\", this.#onNativeValueChange);\n this.#nativeEventControl?.addEventListener(\"change\", this.#onNativeValueChange);\n this.#nativeEventControl?.addEventListener(\"focus\", this.#onNativeFocus);\n this.#nativeEventControl?.addEventListener(\"blur\", this.#onNativeBlur);\n this.#nativeEventControl?.addEventListener(\n \"animationstart\",\n this.#onNativeAnimation,\n );\n }\n\n /** Moves the reset listener to the native control's current owner form. */\n #bindResetForm(form: HTMLFormElement | null): void {\n if (form === this.#resetForm) return;\n this.#resetForm?.removeEventListener(\"reset\", this.#onFormReset);\n this.#resetForm = form;\n this.#resetForm?.addEventListener(\"reset\", this.#onFormReset);\n }\n\n override render() {\n const message = this.error || this.hint;\n const delegatedFloating = this._floatingKind === \"delegated\";\n const nativeFloating = this._floatingKind === \"native\";\n const nativeMultiline =\n nativeFloating && this.#nativeControl() instanceof HTMLTextAreaElement;\n return html`\n <div class=\"field\">\n <label\n class=\"control-label ${nativeFloating ? \"floating-native\" : \"\"} ${nativeMultiline\n ? \"multiline\"\n : \"\"} ${this._nativeHasValue ? \"has-value\" : \"\"}\"\n @click=${this._onControlLabelClick}\n >\n ${this.label && !delegatedFloating\n ? html`<span class=\"label-text\">\n <span>${this.label}</span>\n ${this.required\n ? html`<span class=\"required-mark\" aria-hidden=\"true\">*</span\n ><span class=\"sr-only\"> (required)</span>`\n : nothing}\n </span>`\n : nothing}\n <slot @slotchange=${this._onSlotChange}></slot>\n </label>\n ${message\n ? html`<span id=${this.#messageId} class=\"message ${this.error ? \"error\" : \"\"}\" role=${this.error ? \"alert\" : nothing}\n >${message}</span\n >`\n : nothing}\n </div>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"form-field\": FormField;\n }\n}\n"]}
@@ -1,16 +1,19 @@
1
1
  import { LitElement } from "lit";
2
+ import { formFieldControl, type FormFieldControlConfig } from "./utils/form-field-control.js";
2
3
  /**
3
4
  * Plain multi-line text field — a thin, tokenized wrapper around a native
4
5
  * `<textarea>`, styled to match the other value-entry form fields
5
6
  * (autocomplete-input, form-select, ...). Not a rich editor; use `readonly`
6
7
  * to display pre-formatted text (e.g. an error message) that the user can
7
8
  * still select and copy, typically paired with `<copy-link-button>`.
9
+ * Supports `form-field`'s opt-in floating-label mode when slotted inside it.
8
10
  *
9
11
  * @element text-area
10
12
  * @fires input - Fires on every keystroke; detail: { value: string }.
11
13
  * @fires change - Native change semantics (on blur, if the value changed); detail: { value: string }.
12
14
  */
13
15
  export declare class TextArea extends LitElement {
16
+ #private;
14
17
  /** Current text content. */
15
18
  value: string;
16
19
  /** Visible row count (native `<textarea rows>`). */
@@ -21,6 +24,12 @@ export declare class TextArea extends LitElement {
21
24
  readonly: boolean;
22
25
  /** Disables the field entirely (no interaction, dimmed). */
23
26
  disabled: boolean;
27
+ private _formFieldConfig;
28
+ /**
29
+ * Applies or clears label configuration supplied by a wrapping `form-field`.
30
+ * @private
31
+ */
32
+ [formFieldControl](config: FormFieldControlConfig | null): void;
24
33
  static styles: import("lit").CSSResult[];
25
34
  private _onInput;
26
35
  private _onChange;
@@ -1 +1 @@
1
- {"version":3,"file":"text-area.d.ts","sourceRoot":"","sources":["../src/text-area.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,KAAK,CAAC;AAI5C;;;;;;;;;;GAUG;AACH,qBACa,QAAS,SAAQ,UAAU;IACtC,4BAA4B;IAChB,KAAK,SAAM;IACvB,oDAAoD;IACxB,IAAI,SAAK;IACrC,yCAAyC;IAC7B,W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