@fusion.dev/helix-core 0.142.1 → 0.144.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.
Files changed (112) hide show
  1. package/custom-elements.json +10436 -3804
  2. package/dist/controllers/aria-forward-controller/aria-forward-controller.d.ts +65 -0
  3. package/dist/controllers/aria-forward-controller/aria-forward-controller.js +77 -16
  4. package/dist/controllers/arrival-controller/arrival-controller.d.ts +12 -0
  5. package/dist/controllers/arrival-controller/arrival-controller.js +10 -0
  6. package/dist/controllers/chart-pointer-controller/chart-pointer-controller.d.ts +99 -0
  7. package/dist/controllers/chart-pointer-controller/chart-pointer-controller.js +107 -2
  8. package/dist/controllers/chart-pointer-controller/reading-step.d.ts +57 -0
  9. package/dist/controllers/chart-pointer-controller/reading-step.js +45 -0
  10. package/dist/controllers/copy-controller/copy-controller.d.ts +11 -6
  11. package/dist/controllers/copy-controller/copy-controller.js +16 -9
  12. package/dist/controllers/delay-controller/delay-controller.d.ts +50 -0
  13. package/dist/controllers/delay-controller/delay-controller.js +54 -0
  14. package/dist/controllers/dismiss-controller/dismiss-controller.js +40 -3
  15. package/dist/controllers/focus-scope-controller/focus-scope-controller.d.ts +56 -0
  16. package/dist/controllers/focus-scope-controller/focus-scope-controller.js +71 -0
  17. package/dist/controllers/keyboard-navigation-controller/keyboard-navigation-controller.d.ts +79 -1
  18. package/dist/controllers/keyboard-navigation-controller/keyboard-navigation-controller.js +80 -10
  19. package/dist/controllers/open-phase-controller/open-phase-controller.d.ts +49 -0
  20. package/dist/controllers/open-phase-controller/open-phase-controller.js +41 -0
  21. package/dist/controllers/popover-controller/popover-controller.d.ts +11 -0
  22. package/dist/controllers/popover-controller/popover-controller.js +6 -0
  23. package/dist/controllers/source-controller/source-controller.d.ts +38 -0
  24. package/dist/controllers/source-controller/source-controller.js +71 -2
  25. package/dist/controllers/status-controller/status-controller.d.ts +47 -0
  26. package/dist/controllers/status-controller/status-controller.js +34 -0
  27. package/dist/controllers/swipe-controller/swipe-controller.d.ts +61 -0
  28. package/dist/controllers/swipe-controller/swipe-controller.js +106 -0
  29. package/dist/controllers/virtualize-controller/virtualize-controller.d.ts +16 -0
  30. package/dist/controllers/virtualize-controller/virtualize-controller.js +24 -2
  31. package/dist/events/events.d.ts +137 -4
  32. package/dist/events/events.js +96 -0
  33. package/dist/helix-element/react-bridge.js +6 -4
  34. package/dist/helix-form-element/helix-form-element.d.ts +131 -2
  35. package/dist/helix-form-element/helix-form-element.js +216 -6
  36. package/dist/index.d.ts +30 -9
  37. package/dist/index.js +29 -8
  38. package/dist/mixins/mixin-chart-source/mixin-chart-source.d.ts +15 -2
  39. package/dist/mixins/mixin-chart-source/mixin-chart-source.js +9 -1
  40. package/dist/mixins/mixin-collection/mixin-collection.d.ts +4 -2
  41. package/dist/mixins/mixin-collection/mixin-collection.js +8 -6
  42. package/dist/mixins/mixin-controller-checked/mixin-controller-checked.d.ts +10 -0
  43. package/dist/mixins/mixin-controller-checked/mixin-controller-checked.js +9 -0
  44. package/dist/mixins/mixin-controller-open/mixin-controller-open.js +19 -3
  45. package/dist/mixins/mixin-dismissible/mixin-dismissible.d.ts +2 -0
  46. package/dist/mixins/mixin-dismissible/mixin-dismissible.js +43 -0
  47. package/dist/mixins/mixin-field/mixin-field.d.ts +2 -0
  48. package/dist/mixins/mixin-field/mixin-field.js +46 -8
  49. package/dist/mixins/mixin-picker-editing/mixin-picker-editing.d.ts +23 -8
  50. package/dist/mixins/mixin-picker-editing/mixin-picker-editing.js +25 -1
  51. package/dist/mixins/mixin-picker-field/mixin-picker-field.d.ts +29 -5
  52. package/dist/mixins/mixin-picker-field/mixin-picker-field.js +94 -1
  53. package/dist/mixins/mixin-segmented-field/mixin-segmented-field.d.ts +67 -0
  54. package/dist/mixins/mixin-segmented-field/mixin-segmented-field.js +243 -0
  55. package/dist/utils/arrow/arrow.d.ts +15 -0
  56. package/dist/utils/arrow/arrow.js +2 -0
  57. package/dist/utils/audit-name/audit-name.d.ts +28 -0
  58. package/dist/utils/audit-name/audit-name.js +95 -0
  59. package/dist/utils/calendar/calendar.d.ts +117 -0
  60. package/dist/utils/calendar/calendar.js +96 -0
  61. package/dist/utils/chord/chord.d.ts +43 -0
  62. package/dist/utils/chord/chord.js +53 -0
  63. package/dist/utils/clock/clock.d.ts +87 -0
  64. package/dist/utils/clock/clock.js +68 -0
  65. package/dist/utils/color-name/color-name.d.ts +28 -0
  66. package/dist/utils/color-name/color-name.js +150 -0
  67. package/dist/utils/count-label/count-label.d.ts +13 -0
  68. package/dist/utils/count-label/count-label.js +5 -0
  69. package/dist/utils/css-color/css-color.d.ts +12 -0
  70. package/dist/utils/css-color/css-color.js +2 -2
  71. package/dist/utils/date-segments/date-segments.d.ts +122 -0
  72. package/dist/utils/date-segments/date-segments.js +206 -0
  73. package/dist/utils/draw-dismiss/draw-dismiss.d.ts +30 -0
  74. package/dist/utils/draw-dismiss/draw-dismiss.js +16 -0
  75. package/dist/utils/draw-tooltip/draw-tooltip.d.ts +15 -18
  76. package/dist/utils/draw-tooltip/draw-tooltip.js +16 -5
  77. package/dist/utils/draw-tooltip/spoken-reading.d.ts +10 -0
  78. package/dist/utils/draw-tooltip/spoken-reading.js +10 -0
  79. package/dist/utils/follow-link/follow-link.d.ts +46 -0
  80. package/dist/utils/follow-link/follow-link.js +37 -0
  81. package/dist/utils/heading-in/heading-in.d.ts +19 -0
  82. package/dist/utils/heading-in/heading-in.js +14 -0
  83. package/dist/utils/number-format/number-format.d.ts +23 -0
  84. package/dist/utils/number-format/number-format.js +55 -0
  85. package/dist/utils/platform/platform.d.ts +23 -0
  86. package/dist/utils/platform/platform.js +11 -0
  87. package/dist/utils/read-color/read-color.d.ts +14 -0
  88. package/dist/utils/read-color/read-color.js +13 -0
  89. package/dist/utils/read-series/read-series.d.ts +34 -0
  90. package/dist/utils/read-series/read-series.js +32 -4
  91. package/dist/utils/reflect-elements/reflect-elements.d.ts +37 -0
  92. package/dist/utils/reflect-elements/reflect-elements.js +40 -0
  93. package/dist/utils/relative-time/relative-time.d.ts +13 -1
  94. package/dist/utils/relative-time/relative-time.js +7 -4
  95. package/dist/utils/report-runtime/report-runtime.d.ts +12 -0
  96. package/dist/utils/roving-stop/roving-stop.d.ts +20 -0
  97. package/dist/utils/roving-stop/roving-stop.js +3 -0
  98. package/dist/utils/scroll-lock/scroll-lock.d.ts +16 -0
  99. package/dist/utils/scroll-lock/scroll-lock.js +30 -0
  100. package/dist/utils/swipe/swipe.d.ts +63 -0
  101. package/dist/utils/swipe/swipe.js +48 -0
  102. package/dist/utils/tab-stops/tab-stops.d.ts +16 -0
  103. package/dist/utils/tab-stops/tab-stops.js +22 -0
  104. package/dist/utils/value-as/value-as.d.ts +20 -0
  105. package/dist/utils/value-as/value-as.js +16 -0
  106. package/dist/utils/write-time/write-time.d.ts +11 -1
  107. package/dist/utils/write-time/write-time.js +7 -7
  108. package/dist/utils/written-list/written-list.d.ts +29 -2
  109. package/dist/utils/written-list/written-list.js +11 -1
  110. package/dist/version.d.ts +1 -1
  111. package/dist/version.js +1 -1
  112. package/package.json +4 -4
@@ -13,6 +13,12 @@ export const MixinControllerChecked = (Base) => {
13
13
  super(...arguments);
14
14
  this.defaultChecked = false;
15
15
  this.checkedState = undefined;
16
+ this.readOnly = false;
17
+ this.holdReadOnly = (event) => {
18
+ if (this.readOnly) {
19
+ event.preventDefault();
20
+ }
21
+ };
16
22
  }
17
23
  get checked() {
18
24
  return this.checkedState ?? this.defaultChecked;
@@ -63,5 +69,8 @@ export const MixinControllerChecked = (Base) => {
63
69
  __decorate([
64
70
  property({ attribute: 'default-checked', type: Boolean })
65
71
  ], CheckedElement.prototype, "defaultChecked", void 0);
72
+ __decorate([
73
+ property({ attribute: 'readonly', reflect: true, type: Boolean })
74
+ ], CheckedElement.prototype, "readOnly", void 0);
66
75
  return CheckedElement;
67
76
  };
@@ -13,6 +13,7 @@ export const MixinControllerOpen = (Base) => {
13
13
  super(...arguments);
14
14
  this.defaultOpen = false;
15
15
  this.openState = undefined;
16
+ this.announcedOpen = undefined;
16
17
  }
17
18
  get open() {
18
19
  return this.openState ?? this.defaultOpen;
@@ -26,6 +27,15 @@ export const MixinControllerOpen = (Base) => {
26
27
  super.willUpdate(changed);
27
28
  this.toggleState('open', this.open);
28
29
  }
30
+ updated(changed) {
31
+ super.updated(changed);
32
+ if (this.announcedOpen === undefined) {
33
+ this.announcedOpen = this.open;
34
+ }
35
+ else if (this.announcedOpen !== this.open) {
36
+ this.announceToggle(this.open);
37
+ }
38
+ }
29
39
  requestOpen(next) {
30
40
  if (this.open === next) {
31
41
  return true;
@@ -46,11 +56,17 @@ export const MixinControllerOpen = (Base) => {
46
56
  return applied;
47
57
  }
48
58
  announceToggle(open) {
49
- const event = new Event('toggle', { bubbles: false, cancelable: false, composed: false });
50
- Object.assign(event, {
59
+ this.announcedOpen = open;
60
+ const states = {
51
61
  newState: open ? 'open' : 'closed',
52
62
  oldState: open ? 'closed' : 'open',
53
- });
63
+ };
64
+ if (typeof ToggleEvent === 'function') {
65
+ this.dispatchEvent(new ToggleEvent('toggle', states));
66
+ return;
67
+ }
68
+ const event = new Event('toggle', { bubbles: false, cancelable: false, composed: false });
69
+ Object.assign(event, states);
54
70
  this.dispatchEvent(event);
55
71
  }
56
72
  toggleOpen() {
@@ -13,6 +13,8 @@ export declare class DismissibleElement {
13
13
  dismiss(): boolean;
14
14
  /** The event, built but not dispatched, for a caller that owns the timing. */
15
15
  protected dismissEvent(): HelixDismissEvent;
16
+ /** Where focus lands when a neighbor that held it is removed: the dismiss control. */
17
+ protected get returnFocusTo(): HTMLElement | null;
16
18
  }
17
19
  /**
18
20
  * Grafts `dismissible`, its label, and the event that says so.
@@ -6,6 +6,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  };
7
7
  import { property } from 'lit/decorators.js';
8
8
  import { HelixDismissEvent } from '../../events/events.js';
9
+ import { deepActiveElement, deepContains, } from '../../utils/focusable-elements/focusable-elements.js';
9
10
  export const MixinDismissible = (Base) => {
10
11
  class Dismissible extends Base {
11
12
  constructor() {
@@ -20,11 +21,53 @@ export const MixinDismissible = (Base) => {
20
21
  .join('');
21
22
  return new HelixDismissEvent({ label: own.trim() });
22
23
  }
24
+ get returnFocusTo() {
25
+ return this.shadowRoot?.querySelector('[part~="dismiss"]') ?? null;
26
+ }
23
27
  dismiss() {
28
+ const neighbors = deepContains(this, deepActiveElement()) ? this.neighbors() : [];
24
29
  const event = this.dismissEvent();
25
30
  this.dispatchEvent(event);
31
+ if (neighbors.length > 0 && !event.defaultPrevented) {
32
+ this.keepFocus(neighbors);
33
+ }
26
34
  return !event.defaultPrevented;
27
35
  }
36
+ neighbors() {
37
+ const same = (node) => node instanceof HTMLElement && node.localName === this.localName;
38
+ const after = [];
39
+ for (let node = this.nextElementSibling; node; node = node.nextElementSibling) {
40
+ if (same(node)) {
41
+ after.push(node);
42
+ }
43
+ }
44
+ const before = [];
45
+ for (let node = this.previousElementSibling; node; node = node.previousElementSibling) {
46
+ if (same(node)) {
47
+ before.push(node);
48
+ }
49
+ }
50
+ return [...after, ...before];
51
+ }
52
+ keepFocus(neighbors) {
53
+ const settle = () => {
54
+ const active = document.activeElement;
55
+ if (this.isConnected || (active !== null && active !== document.body)) {
56
+ return;
57
+ }
58
+ for (const neighbor of neighbors) {
59
+ const control = neighbor.isConnected && neighbor.returnFocusTo;
60
+ if (control) {
61
+ control.focus();
62
+ if (deepContains(neighbor, deepActiveElement())) {
63
+ return;
64
+ }
65
+ }
66
+ }
67
+ };
68
+ settle();
69
+ requestAnimationFrame(settle);
70
+ }
28
71
  }
29
72
  __decorate([
30
73
  property({ reflect: true, type: Boolean })
@@ -20,6 +20,8 @@ export declare class MixinFieldInterface {
20
20
  protected labelId: string;
21
21
  /** Whether a label is drawn at all, in either shape. */
22
22
  protected get labeled(): boolean;
23
+ /** The element in the shadow root a reader lands on and hears the name of. */
24
+ protected get namedControl(): HTMLElement | null;
23
25
  /**
24
26
  * Help text shown under the control. A validation message replaces it.
25
27
  *
@@ -6,6 +6,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  };
7
7
  import { html, nothing } from 'lit';
8
8
  import { property, state } from 'lit/decorators.js';
9
+ import { auditName } from '../../utils/audit-name/audit-name.js';
9
10
  import { hostAria } from '../../utils/host-aria/host-aria.js';
10
11
  const HINT_ID = 'helix-hint';
11
12
  const FEEDBACK_ID = 'helix-feedback';
@@ -16,6 +17,19 @@ export const MixinField = (Base) => {
16
17
  this.controlId = 'control';
17
18
  this.labelId = 'label';
18
19
  this.namedBy = null;
20
+ this.filledSlots = new Set();
21
+ this.noteSlotted = (event) => {
22
+ const slot = event.target;
23
+ if (slot.name !== 'label' && slot.name !== 'hint') {
24
+ return;
25
+ }
26
+ const filled = slot.assignedNodes().length > 0;
27
+ if (filled !== this.filledSlots.has(slot.name)) {
28
+ const next = new Set(this.filledSlots);
29
+ next[filled ? 'add' : 'delete'](slot.name);
30
+ this.filledSlots = next;
31
+ }
32
+ };
19
33
  this.feedback = '';
20
34
  this.hint = '';
21
35
  this.label = '';
@@ -23,8 +37,21 @@ export const MixinField = (Base) => {
23
37
  this.touched = false;
24
38
  this.shownFeedback = '';
25
39
  }
40
+ get namedControl() {
41
+ return (this.renderRoot?.querySelector(`#${this.controlId}`) ??
42
+ this.renderRoot?.querySelector('input, button, select, textarea') ??
43
+ null);
44
+ }
26
45
  get labeled() {
27
- return this.label !== '' || Boolean(this.getAttribute('aria-label'));
46
+ return (this.label !== '' ||
47
+ Boolean(this.getAttribute('aria-label')) ||
48
+ this.filledSlots.has('label'));
49
+ }
50
+ bareSlot(name) {
51
+ return name === 'label' ? html `<slot name="label"></slot>` : html `<slot name="hint"></slot>`;
52
+ }
53
+ get validityFeedback() {
54
+ return this.validates ? this.feedback : '';
28
55
  }
29
56
  get validates() {
30
57
  return this.constructor.formAssociated === true;
@@ -42,15 +69,15 @@ export const MixinField = (Base) => {
42
69
  if (this.resolvedFeedback !== '') {
43
70
  return FEEDBACK_ID;
44
71
  }
45
- return this.hint === '' ? undefined : HINT_ID;
72
+ return this.hint === '' && !this.filledSlots.has('hint') ? undefined : HINT_ID;
46
73
  }
47
74
  get invalidity() {
48
75
  return this.resolvedFeedback === '' ? undefined : 'true';
49
76
  }
50
77
  renderGroupLabel() {
51
78
  const hidden = this.label === '' ? this.getAttribute('aria-label') : null;
52
- if (this.label === '' && !hidden) {
53
- return nothing;
79
+ if (this.label === '' && !hidden && !this.filledSlots.has('label')) {
80
+ return this.bareSlot('label');
54
81
  }
55
82
  return html `<span part="label" id=${this.labelId} ?data-hidden=${hidden !== null}
56
83
  ><slot name="label">${this.label || hidden}</slot></span
@@ -58,8 +85,8 @@ export const MixinField = (Base) => {
58
85
  }
59
86
  renderLabel() {
60
87
  const hidden = this.label === '' ? this.getAttribute('aria-label') : null;
61
- if (this.label === '' && !hidden) {
62
- return nothing;
88
+ if (this.label === '' && !hidden && !this.filledSlots.has('label')) {
89
+ return this.bareSlot('label');
63
90
  }
64
91
  return html `<label
65
92
  part="label"
@@ -70,10 +97,15 @@ export const MixinField = (Base) => {
70
97
  >`;
71
98
  }
72
99
  renderHint() {
73
- if (this.hint === '' || this.resolvedFeedback !== '') {
100
+ if (this.resolvedFeedback !== '') {
74
101
  return nothing;
75
102
  }
76
- return html `<p part="hint" id=${HINT_ID}><slot name="hint">${this.hint}</slot></p>`;
103
+ if (this.hint === '' && !this.filledSlots.has('hint')) {
104
+ return this.bareSlot('hint');
105
+ }
106
+ return html `<p part="hint" id=${HINT_ID}
107
+ ><slot name="hint">${this.hint}</slot></p
108
+ >`;
77
109
  }
78
110
  renderFeedback() {
79
111
  const message = this.resolvedFeedback;
@@ -133,11 +165,17 @@ export const MixinField = (Base) => {
133
165
  };
134
166
  this.addEventListener('invalid', touch);
135
167
  this.addEventListener('change', touch);
168
+ this.renderRoot.addEventListener('slotchange', this.noteSlotted);
169
+ auditName(this, () => this.namedControl, 'Give it a `label`, an `aria-label`, words in its label, or a `<label for>` that names it.', () => this.labeled ||
170
+ [...this.children].some((child) => child.slot === 'label' && (child.textContent ?? '').trim() !== ''));
136
171
  }
137
172
  }
138
173
  __decorate([
139
174
  property({ attribute: 'aria-label' })
140
175
  ], FieldElement.prototype, "namedBy", void 0);
176
+ __decorate([
177
+ state()
178
+ ], FieldElement.prototype, "filledSlots", void 0);
141
179
  __decorate([
142
180
  property()
143
181
  ], FieldElement.prototype, "feedback", void 0);
@@ -19,7 +19,10 @@ export declare class MixinPickerEditingInterface {
19
19
  protected editing: boolean;
20
20
  /** The caret has left, so the field renders again. */
21
21
  protected readonly handleBlur: () => void;
22
- /** Focusing the field opens the picker, and only from outside the element. */
22
+ /**
23
+ * A press that focuses the field opens the picker, and only from outside the
24
+ * element. Focus that arrives by Tab or from a script opens nothing.
25
+ */
23
26
  protected readonly handleFocus: (event: FocusEvent) => void;
24
27
  /**
25
28
  * Whether the value is locked. A read-only control still submits its value.
@@ -30,10 +33,15 @@ export declare class MixinPickerEditingInterface {
30
33
  * returns `false`.
31
34
  */
32
35
  requestValue(next: string): boolean;
36
+ /**
37
+ * Requests the panel open or closed. While `readOnly` is set, it does not
38
+ * open, and it returns `false`.
39
+ */
40
+ requestOpen(next: boolean): boolean;
33
41
  }
34
42
  /**
35
- * Grafts the typing half of a picker field: it opens on arrival, holds the
36
- * value while the caret is in it, and refuses while read-only.
43
+ * Grafts the typing half of a picker field: a press into it opens the picker,
44
+ * it holds the value while the caret is in it, and it refuses while read-only.
37
45
  *
38
46
  * **Over `MixinPickerField` and not part of it, because Color Input takes the
39
47
  * one and not the other.** Date Input and Time Input show a rendering while
@@ -41,11 +49,18 @@ export declare class MixinPickerEditingInterface {
41
49
  * while somebody is, because `Intl` formats and does not parse and a document
42
50
  * being edited must not be a rendering of something else. That split needs to
43
51
  * know when the caret is in the field, which is `editing`; and a reader who
44
- * reaches such a field is choosing, so arriving opens the picker. A color has
45
- * neither: `#ff0000` is what is typed and what is shown, and a reader who has
46
- * the hex pastes it and never opens anything. `readOnly` is the third thing
47
- * Color Input does not have, and a mixin cannot give it one without changing
48
- * its API.
52
+ * presses into such a field is choosing, so the press opens the picker. A color
53
+ * has neither: `#ff0000` is what is typed and what is shown, and a reader who
54
+ * has the hex pastes it and never opens anything.
55
+ *
56
+ * **Tab into the field opens nothing.** It did, and a reader moving through a
57
+ * form with a screen reader heard a dialog appear at every date and every
58
+ * time they passed. React Aria's DatePicker opens on its button alone and the
59
+ * APG date picker combobox opens on its button or Down; here the trigger and
60
+ * ArrowDown open it from the keyboard, and a press into the text opens it for
61
+ * a pointer, which is where the reader has already shown what they came for. `readOnly` comes along here for
62
+ * the two that take this mixin; Color Input declares its own, the same
63
+ * property refusing the same two requests.
49
64
  */
50
65
  export declare const MixinPickerEditing: <T extends Constructor<EditingBase>>(Base: T) => Constructor<MixinPickerEditingInterface> & T;
51
66
  export {};
@@ -14,10 +14,16 @@ export const MixinPickerEditing = (Base) => {
14
14
  this.handleBlur = () => {
15
15
  this.editing = false;
16
16
  };
17
+ this.pressing = false;
18
+ this.handlePress = (event) => {
19
+ this.pressing = event.type === 'pointerdown' && event.composedPath()[0] === this.control;
20
+ };
17
21
  this.handleFocus = (event) => {
18
22
  this.editing = !this.returning;
23
+ const pressed = this.pressing;
24
+ this.pressing = false;
19
25
  const from = event.relatedTarget;
20
- if (this.open || this.isDisabled || this.returning) {
26
+ if (!pressed || this.open || this.isDisabled || this.returning) {
21
27
  return;
22
28
  }
23
29
  if (from instanceof Node && this.renderRoot?.contains?.(from)) {
@@ -32,6 +38,24 @@ export const MixinPickerEditing = (Base) => {
32
38
  }
33
39
  return super.requestValue(next);
34
40
  }
41
+ requestOpen(next) {
42
+ if (next && this.readOnly) {
43
+ return false;
44
+ }
45
+ return super.requestOpen(next);
46
+ }
47
+ connectedCallback() {
48
+ super.connectedCallback();
49
+ this.addEventListener('pointerdown', this.handlePress);
50
+ this.addEventListener('pointercancel', this.handlePress);
51
+ this.addEventListener('click', this.handlePress);
52
+ }
53
+ disconnectedCallback() {
54
+ super.disconnectedCallback();
55
+ this.removeEventListener('pointerdown', this.handlePress);
56
+ this.removeEventListener('pointercancel', this.handlePress);
57
+ this.removeEventListener('click', this.handlePress);
58
+ }
35
59
  }
36
60
  __decorate([
37
61
  property({ attribute: 'readonly', reflect: true, type: Boolean })
@@ -45,7 +45,22 @@ export declare class MixinPickerFieldInterface {
45
45
  protected get display(): string;
46
46
  /** Puts the caret in the field, as clicking its label does. */
47
47
  focus(options?: FocusOptions): void;
48
- /** Escape shuts the panel without moving the value. */
48
+ /**
49
+ * The text control's own `change`, which a reader's edit ends with, said
50
+ * under the host's name.
51
+ */
52
+ protected readonly handleCommit: (event: Event) => void;
53
+ /**
54
+ * The trigger's press: opens the panel with focus in the picker, or closes
55
+ * it.
56
+ */
57
+ protected readonly handleTriggerClick: () => void;
58
+ /** Enter in the text submits the form, as it does in a native text field. */
59
+ protected readonly handleKeypress: (event: KeyboardEvent) => void;
60
+ /**
61
+ * Escape shuts the panel without moving the value, Tab out of the text shuts
62
+ * a panel the reader is passing, and ArrowDown in the text moves into it.
63
+ */
49
64
  protected readonly handleKeydown: (event: KeyboardEvent) => void;
50
65
  /** The overlay, placed against the field rather than the trigger. */
51
66
  protected readonly panel: PopoverController;
@@ -56,6 +71,14 @@ export declare class MixinPickerFieldInterface {
56
71
  * Nothing, unless a family fits what its panel holds to the room it has.
57
72
  */
58
73
  protected placed(room: number | undefined): void;
74
+ /**
75
+ * Takes a value the reader picked in the panel, and says it is settled.
76
+ *
77
+ * Returns whether it was taken. A family whose typing announces `input`
78
+ * alone sends `change` from here for a pick, since a pick is a finished
79
+ * choice.
80
+ */
81
+ protected requestPicked(next: string): boolean;
59
82
  /** Puts the field back where the answer differs from what was typed. */
60
83
  protected restore(): void;
61
84
  /** Puts the caret back in the field without the field reopening the panel. */
@@ -102,10 +125,11 @@ export declare class MixinPickerFieldInterface {
102
125
  * same way, and for the same reason: a mixin reads a part out of whatever host
103
126
  * applies it.
104
127
  *
105
- * **Opening on focus, `readOnly` and the idle rendering are not here.** They
106
- * are `MixinPickerEditing`'s, because Color Input has none of the three: a hex
107
- * is pasted and read at a glance, so its field neither renders nor opens on
108
- * arrival, and giving it `readOnly` would be a property its API does not have.
128
+ * **Opening on a press into the text, `readOnly` and the idle rendering are
129
+ * not here.** They are `MixinPickerEditing`'s, because Color Input takes
130
+ * neither of the first and last: a hex is pasted and read at a glance, so its
131
+ * field neither renders nor opens when pressed. Color Input declares its own
132
+ * `readOnly`.
109
133
  *
110
134
  * **Three things the two typed families share stay with them.** `renderTrigger`
111
135
  * differs only by its icon and would still be the wrong thing to lift: a part a
@@ -7,6 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  import { property } from 'lit/decorators.js';
8
8
  import { PopoverController } from '../../controllers/popover-controller/popover-controller.js';
9
9
  import { reportValues } from '../../utils/report-values/report-values.js';
10
+ import { tabStops } from '../../utils/tab-stops/tab-stops.js';
10
11
  export const MixinPickerField = (Base) => {
11
12
  class PickerFieldElement extends Base {
12
13
  constructor() {
@@ -29,7 +30,73 @@ export const MixinPickerField = (Base) => {
29
30
  event.stopPropagation();
30
31
  this.requestOpen(false);
31
32
  this.returnFocus();
33
+ return;
32
34
  }
35
+ const fromText = event.composedPath()[0] === this.control;
36
+ if (event.key === 'Tab' && this.open && fromText) {
37
+ this.requestOpen(false);
38
+ return;
39
+ }
40
+ if (event.key === 'ArrowDown' && fromText && !this.isDisabled) {
41
+ event.preventDefault();
42
+ if (this.open) {
43
+ this.partNamed('picker')?.focus();
44
+ }
45
+ else {
46
+ this.fromTrigger = true;
47
+ if (!this.requestOpen(true)) {
48
+ this.fromTrigger = false;
49
+ }
50
+ }
51
+ }
52
+ };
53
+ this.handleSurfaceKeydown = (event) => {
54
+ const surface = this.partNamed('surface');
55
+ if ((event.key !== 'Escape' && event.key !== 'Tab') ||
56
+ !this.open ||
57
+ event.defaultPrevented ||
58
+ !surface ||
59
+ !event.composedPath().includes(surface)) {
60
+ return;
61
+ }
62
+ if (event.key === 'Tab') {
63
+ const stops = tabStops(surface);
64
+ const at = event.composedPath()[0];
65
+ const edge = event.shiftKey ? stops[0] : stops.at(-1);
66
+ if (edge !== undefined && at === edge) {
67
+ event.preventDefault();
68
+ (event.shiftKey ? stops.at(-1) : stops[0])?.focus();
69
+ }
70
+ return;
71
+ }
72
+ event.stopPropagation();
73
+ event.preventDefault();
74
+ this.requestOpen(false);
75
+ this.returnFocus();
76
+ };
77
+ this.handleFocusOut = (event) => {
78
+ const to = event.relatedTarget;
79
+ if (!this.open || !(to instanceof Node)) {
80
+ return;
81
+ }
82
+ if (this.contains(to) || this.renderRoot?.contains?.(to)) {
83
+ return;
84
+ }
85
+ this.requestOpen(false);
86
+ };
87
+ this.handleCommit = (event) => {
88
+ event.stopPropagation();
89
+ this.announceChange();
90
+ };
91
+ this.fromTrigger = false;
92
+ this.handleKeypress = (event) => {
93
+ if (event.key === 'Enter' && !event.defaultPrevented) {
94
+ this.submitImplicitly();
95
+ }
96
+ };
97
+ this.handleTriggerClick = () => {
98
+ this.fromTrigger = !this.open;
99
+ this.toggleOpen();
33
100
  };
34
101
  this.returning = false;
35
102
  }
@@ -78,9 +145,29 @@ export const MixinPickerField = (Base) => {
78
145
  }
79
146
  this.refreshFeedback();
80
147
  }
148
+ get blocksImplicitSubmission() {
149
+ return this.control !== null;
150
+ }
151
+ requestPicked(next) {
152
+ const taken = this.requestValue(next);
153
+ if (taken && this.announcesInput) {
154
+ this.announceChange();
155
+ }
156
+ return taken;
157
+ }
158
+ connectedCallback() {
159
+ super.connectedCallback();
160
+ this.addEventListener('keydown', this.handleSurfaceKeydown);
161
+ this.addEventListener('focusout', this.handleFocusOut);
162
+ }
163
+ disconnectedCallback() {
164
+ super.disconnectedCallback();
165
+ this.removeEventListener('keydown', this.handleSurfaceKeydown);
166
+ this.removeEventListener('focusout', this.handleFocusOut);
167
+ }
81
168
  returnFocus() {
82
169
  this.returning = true;
83
- this.control?.focus();
170
+ this.anchor?.focus();
84
171
  this.returning = false;
85
172
  }
86
173
  focus(options) {
@@ -92,6 +179,12 @@ export const MixinPickerField = (Base) => {
92
179
  }
93
180
  updated(changed) {
94
181
  super.updated(changed);
182
+ if (changed.has('open')) {
183
+ if (this.open && this.fromTrigger) {
184
+ this.partNamed('picker')?.focus();
185
+ }
186
+ this.fromTrigger = false;
187
+ }
95
188
  this.sync();
96
189
  }
97
190
  }
@@ -0,0 +1,67 @@
1
+ import { type TemplateResult } from 'lit';
2
+ import type { HelixFormElement } from '../../helix-form-element/helix-form-element.js';
3
+ import { type SegmentedKind, type SegmentOptions } from '../../utils/date-segments/date-segments.js';
4
+ import type { MixinControllerOpenInterface } from '../mixin-controller-open/mixin-controller-open.js';
5
+ import type { MixinControllerValueInterface } from '../mixin-controller-value/mixin-controller-value.js';
6
+ import type { MixinFieldInterface } from '../mixin-field/mixin-field.js';
7
+ import type { MixinPickerFieldInterface } from '../mixin-picker-field/mixin-picker-field.js';
8
+ type Constructor<T> = new (...args: any[]) => T;
9
+ /** What this is applied over: a picker field, which `MixinPickerField` makes. */
10
+ type SegmentedBase = HelixFormElement & MixinControllerOpenInterface & MixinControllerValueInterface & MixinFieldInterface & MixinPickerFieldInterface;
11
+ /**
12
+ * The public surface `MixinSegmentedField` adds.
13
+ *
14
+ * Declared separately because TypeScript cannot emit declarations for an
15
+ * anonymous class that has private members (TS4094).
16
+ */
17
+ export declare class MixinSegmentedFieldInterface {
18
+ /** What a screen reader hears for a segment with nothing in it. */
19
+ emptySegmentLabel: string;
20
+ /**
21
+ * Whether the field is a row of segments, one for each part of the date or
22
+ * time, in place of a line of text.
23
+ */
24
+ segmented: boolean;
25
+ /** Whether the segments are drawn: `segmented`, where the family can hold them. */
26
+ protected get segmentsShown(): boolean;
27
+ /** The row of segments, the group a description is carried to, or `null` while none is drawn. */
28
+ protected get segmentGroup(): HTMLElement | null;
29
+ /** Whether this family can show segments in its current shape. */
30
+ protected get segmentable(): boolean;
31
+ /** A date or a time. */
32
+ protected get segmentedKind(): SegmentedKind;
33
+ /** The locale the segments are laid out and named in. */
34
+ protected get segmentLocale(): string;
35
+ /** The clock and the seconds a time is laid out with. */
36
+ protected get segmentOptions(): SegmentOptions;
37
+ /** The row of segments, in the locale's order, with what it writes between them. */
38
+ protected renderSegments(): TemplateResult;
39
+ }
40
+ /**
41
+ * Grafts the segmented field React Aria's DateField and TimeField are, and Web
42
+ * Awesome's time input has, onto a picker field: one `spinbutton` for each part
43
+ * of the date or the time, in the order the locale writes them.
44
+ *
45
+ * **Typing into a text field asks the reader to know the format.** Date Input
46
+ * and Time Input read ISO, `2026-08-04` and `14:30`, because `Intl` formats and
47
+ * does not parse, and a reader in Germany who types `4.8.2026` is refused. A
48
+ * segment needs no format: the month is a month, set with digits or the arrow
49
+ * keys, and the layout puts it where the locale does, so the field reads
50
+ * `04.08.2026` in German and `08/04/2026` in English with nothing to parse.
51
+ *
52
+ * **What a segment does with a key**, which is React Aria's: digits fill it and
53
+ * move on once it cannot take another, Up and Down step it and wrap, Home and
54
+ * End go to its ends, Backspace and Delete empty it, Left and Right move between
55
+ * segments along the line of text, and Alt+Down opens the picker. Each segment
56
+ * is a tab stop, as each is in React Aria.
57
+ *
58
+ * **The value is whole or empty.** A date with no year is no date, so the value
59
+ * stays empty while any segment is, and the field reports `badInput` as a
60
+ * native date input does with a half-typed date. The arithmetic is
61
+ * `date-segments`, so this draws and listens and nothing else.
62
+ *
63
+ * **Opt-in, with `segmented`**, because the text field is what every example and
64
+ * every form already holds, and a row of segments draws differently.
65
+ */
66
+ export declare const MixinSegmentedField: <T extends Constructor<SegmentedBase>>(Base: T) => Constructor<MixinSegmentedFieldInterface> & T;
67
+ export {};