@human-kit/ui 1.0.0-beta.0 → 1.0.0-beta.2

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 (159) hide show
  1. package/README.md +2 -0
  2. package/dist/FOCUS_STATE_CONTRACT.md +1 -0
  3. package/dist/accordion/root/accordion-root.svelte +15 -3
  4. package/dist/accordion/root/context.svelte.js +4 -4
  5. package/dist/accordion/types.d.ts +9 -2
  6. package/dist/autocomplete/list/autocomplete-list.svelte.d.ts +6 -0
  7. package/dist/calendar/root/context.svelte.js +8 -2
  8. package/dist/checkbox/root/checkbox-root.svelte +28 -11
  9. package/dist/checkbox/root/checkbox-root.svelte.d.ts +13 -0
  10. package/dist/clock/root/create-time-selection-state.svelte.d.ts +5 -0
  11. package/dist/clock/root/create-time-selection-state.svelte.js +113 -10
  12. package/dist/clock/root/wheel-options.d.ts +7 -3
  13. package/dist/clock/root/wheel-options.js +7 -15
  14. package/dist/clock/wheel-column/clock-wheel-column.svelte +10 -2
  15. package/dist/clock/wheel-column/clock-wheel-column.svelte.d.ts +2 -1
  16. package/dist/collapsible/root/collapsible-root.svelte +9 -4
  17. package/dist/collapsible/types.d.ts +9 -0
  18. package/dist/combobox/input/combobox-input.svelte +12 -1
  19. package/dist/combobox/list/combobox-listbox.svelte +93 -1
  20. package/dist/combobox/list/combobox-listbox.svelte.d.ts +20 -0
  21. package/dist/combobox/root/combobox.svelte +118 -45
  22. package/dist/combobox/root/combobox.svelte.d.ts +11 -0
  23. package/dist/combobox/root/context.d.ts +12 -0
  24. package/dist/combobox/status/README.md +2 -2
  25. package/dist/combobox/tag-remove/combobox-tag-remove.svelte +14 -2
  26. package/dist/combobox/tag-remove/combobox-tag-remove.svelte.d.ts +7 -0
  27. package/dist/combobox/tags/combobox-tags.svelte +5 -2
  28. package/dist/combobox/tags/combobox-tags.svelte.d.ts +2 -0
  29. package/dist/combobox/trigger/combobox-trigger.svelte +4 -1
  30. package/dist/datepicker/README.md +3 -2
  31. package/dist/datepicker/root/date-picker-root.svelte +38 -2
  32. package/dist/datepicker/root/date-picker-root.svelte.d.ts +2 -0
  33. package/dist/datepicker/root/draft-evaluation.d.ts +7 -0
  34. package/dist/datepicker/root/draft-evaluation.js +2 -2
  35. package/dist/daterangepicker/root/date-range-picker-root.svelte +19 -1
  36. package/dist/daterangepicker/root/date-range-picker-root.svelte.d.ts +2 -0
  37. package/dist/dialog/README.md +9 -1
  38. package/dist/dialog/close/dialog-close.svelte +57 -0
  39. package/dist/dialog/close/dialog-close.svelte.d.ts +19 -0
  40. package/dist/dialog/content/dialog-content.svelte +2 -0
  41. package/dist/dialog/description/dialog-description.svelte +46 -0
  42. package/dist/dialog/description/dialog-description.svelte.d.ts +20 -0
  43. package/dist/dialog/index.d.ts +9 -0
  44. package/dist/dialog/index.js +3 -0
  45. package/dist/dialog/index.parts.d.ts +3 -0
  46. package/dist/dialog/index.parts.js +3 -0
  47. package/dist/dialog/root/context.d.ts +8 -0
  48. package/dist/dialog/root/dialog-root.svelte +58 -16
  49. package/dist/dialog/root/dialog-root.svelte.d.ts +10 -3
  50. package/dist/dialog/root/dialog-stack.d.ts +6 -22
  51. package/dist/dialog/root/dialog-stack.js +4 -33
  52. package/dist/dialog/title/dialog-title.svelte +43 -0
  53. package/dist/dialog/title/dialog-title.svelte.d.ts +21 -0
  54. package/dist/drawer/README.md +111 -0
  55. package/dist/drawer/body/drawer-body.svelte +47 -0
  56. package/dist/drawer/body/drawer-body.svelte.d.ts +32 -0
  57. package/dist/drawer/close/drawer-close.svelte +52 -0
  58. package/dist/drawer/close/drawer-close.svelte.d.ts +20 -0
  59. package/dist/drawer/content/drawer-content.svelte +597 -0
  60. package/dist/drawer/content/drawer-content.svelte.d.ts +28 -0
  61. package/dist/drawer/description/drawer-description.svelte +40 -0
  62. package/dist/drawer/description/drawer-description.svelte.d.ts +20 -0
  63. package/dist/drawer/indent/drawer-indent-background.svelte +36 -0
  64. package/dist/drawer/indent/drawer-indent-background.svelte.d.ts +17 -0
  65. package/dist/drawer/indent/drawer-indent.svelte +59 -0
  66. package/dist/drawer/indent/drawer-indent.svelte.d.ts +32 -0
  67. package/dist/drawer/index.d.ts +49 -0
  68. package/dist/drawer/index.js +25 -0
  69. package/dist/drawer/index.parts.d.ts +14 -0
  70. package/dist/drawer/index.parts.js +15 -0
  71. package/dist/drawer/overlay/drawer-overlay.svelte +67 -0
  72. package/dist/drawer/overlay/drawer-overlay.svelte.d.ts +12 -0
  73. package/dist/drawer/portal/drawer-portal.svelte +57 -0
  74. package/dist/drawer/portal/drawer-portal.svelte.d.ts +13 -0
  75. package/dist/drawer/root/context.d.ts +81 -0
  76. package/dist/drawer/root/context.js +20 -0
  77. package/dist/drawer/root/drawer-root.svelte +333 -0
  78. package/dist/drawer/root/drawer-root.svelte.d.ts +77 -0
  79. package/dist/drawer/root/drawer-stack.svelte.d.ts +73 -0
  80. package/dist/drawer/root/drawer-stack.svelte.js +113 -0
  81. package/dist/drawer/root/handle.svelte.d.ts +39 -0
  82. package/dist/drawer/root/handle.svelte.js +64 -0
  83. package/dist/drawer/root/keyboard-context.d.ts +13 -0
  84. package/dist/drawer/root/keyboard-context.js +8 -0
  85. package/dist/drawer/root/presence-context.d.ts +22 -0
  86. package/dist/drawer/root/presence-context.js +8 -0
  87. package/dist/drawer/root/snap-points.d.ts +68 -0
  88. package/dist/drawer/root/snap-points.js +120 -0
  89. package/dist/drawer/root/starting-style.svelte.d.ts +18 -0
  90. package/dist/drawer/root/starting-style.svelte.js +38 -0
  91. package/dist/drawer/root/types.d.ts +36 -0
  92. package/dist/drawer/root/types.js +1 -0
  93. package/dist/drawer/root/viewport-context.d.ts +2 -0
  94. package/dist/drawer/root/viewport-context.js +16 -0
  95. package/dist/drawer/swipe-area/drawer-swipe-area.svelte +143 -0
  96. package/dist/drawer/swipe-area/drawer-swipe-area.svelte.d.ts +22 -0
  97. package/dist/drawer/title/drawer-title.svelte +37 -0
  98. package/dist/drawer/title/drawer-title.svelte.d.ts +21 -0
  99. package/dist/drawer/trigger/drawer-trigger.svelte +90 -0
  100. package/dist/drawer/trigger/drawer-trigger.svelte.d.ts +41 -0
  101. package/dist/drawer/viewport/drawer-viewport.svelte +69 -0
  102. package/dist/drawer/viewport/drawer-viewport.svelte.d.ts +15 -0
  103. package/dist/drawer/virtual-keyboard/drawer-virtual-keyboard-provider.svelte +88 -0
  104. package/dist/drawer/virtual-keyboard/drawer-virtual-keyboard-provider.svelte.d.ts +29 -0
  105. package/dist/hooks/use-virtual-focus.svelte.d.ts +9 -0
  106. package/dist/hooks/use-virtual-focus.svelte.js +7 -1
  107. package/dist/index.d.ts +2 -0
  108. package/dist/index.js +2 -0
  109. package/dist/listbox/item/listbox-item.svelte +8 -1
  110. package/dist/listbox/root/context.d.ts +30 -0
  111. package/dist/listbox/root/context.js +10 -0
  112. package/dist/listbox/root/listbox.svelte +291 -8
  113. package/dist/listbox/root/listbox.svelte.d.ts +35 -2
  114. package/dist/menu/content/menu-content.svelte +3 -1
  115. package/dist/menu/overlay/menu-overlay.svelte +1 -1
  116. package/dist/numberfield/root/number-field-root.svelte +2 -1
  117. package/dist/popover/content/popover-content.svelte +1 -1
  118. package/dist/popover/overlay/popover-overlay.svelte +1 -1
  119. package/dist/popover/root/popover-root.svelte +23 -11
  120. package/dist/popover/root/popover-root.svelte.d.ts +10 -2
  121. package/dist/primitives/floating.d.ts +7 -0
  122. package/dist/primitives/floating.js +6 -2
  123. package/dist/primitives/index.d.ts +1 -0
  124. package/dist/primitives/index.js +1 -0
  125. package/dist/primitives/keyboard-navigation.js +3 -1
  126. package/dist/primitives/layer-stack.d.ts +29 -0
  127. package/dist/primitives/layer-stack.js +35 -0
  128. package/dist/primitives/list-virtualizer.d.ts +75 -0
  129. package/dist/primitives/list-virtualizer.js +59 -0
  130. package/dist/primitives/scroll-lock.d.ts +23 -3
  131. package/dist/primitives/scroll-lock.js +122 -9
  132. package/dist/primitives/swipe-gesture.d.ts +126 -0
  133. package/dist/primitives/swipe-gesture.js +351 -0
  134. package/dist/primitives/text.d.ts +8 -0
  135. package/dist/primitives/text.js +13 -0
  136. package/dist/switch/root/switch-root.svelte +23 -9
  137. package/dist/switch/root/switch-root.svelte.d.ts +9 -2
  138. package/dist/table/body/table-body.svelte +84 -9
  139. package/dist/table/cell/table-cell.svelte +1 -3
  140. package/dist/table/column/table-column.svelte +5 -1
  141. package/dist/table/column-resizer/table-column-resizer.svelte +1 -5
  142. package/dist/table/index.d.ts +1 -1
  143. package/dist/table/index.js +1 -1
  144. package/dist/table/interactive-cell/table-interactive-cell.svelte +1 -3
  145. package/dist/table/root/context.svelte.js +99 -49
  146. package/dist/table/row/table-row.svelte +7 -7
  147. package/dist/table/sort-trigger/table-sort-trigger.svelte +5 -1
  148. package/dist/table/types.d.ts +6 -0
  149. package/dist/tabs/root/tabs-root.svelte +20 -6
  150. package/dist/tabs/types.d.ts +9 -0
  151. package/dist/timepicker/root/time-picker-root.svelte +11 -0
  152. package/dist/timepicker/root/time-picker-root.svelte.d.ts +2 -0
  153. package/dist/toggle-group/root/context.svelte.js +11 -4
  154. package/dist/toggle-group/root/toggle-group-root.svelte +19 -4
  155. package/dist/toggle-group/types.d.ts +9 -0
  156. package/dist/tree/root/context.svelte.js +6 -0
  157. package/dist/tree/root/tree-root.svelte +22 -8
  158. package/dist/tree/types.d.ts +13 -0
  159. package/package.json +227 -224
package/README.md CHANGED
@@ -5,6 +5,8 @@ Accessible, reusable UI components for **Svelte 5**.
5
5
  Built with Svelte 5 runes, typed end to end, and shipped as native ESM with
6
6
  per-component subpath exports so bundlers only include what you import.
7
7
 
8
+ **[Documentation and live demos → ui.human-kit.com](https://ui.human-kit.com)**
9
+
8
10
  ## Installation
9
11
 
10
12
  ```bash
@@ -56,6 +56,7 @@ The following components implement this contract:
56
56
 
57
57
  - **Popover** — trigger + content, restore focus on close.
58
58
  - **Dialog** — trigger + overlay/content, nested stack support.
59
+ - **Drawer** — trigger + overlay/content, shares the modal layer stack with Dialog. Restore also covers the `swipe` close reason (resolves to `pointer`), and retries the trigger focus after `ariaHideOutside` lifts `inert`.
59
60
  - **DatePicker** — segment spinbuttons, trigger, popover (calendar).
60
61
  - **TimePicker** — segment spinbuttons, trigger, popover (scrollable columns). Follows the same contract as DatePicker.
61
62
  - **Calendar** — grid cells with roving tabindex.
@@ -9,6 +9,7 @@
9
9
  id,
10
10
  value = $bindable(),
11
11
  defaultValue,
12
+ controlledValue = false,
12
13
  onChange,
13
14
  selectionMode = 'single',
14
15
  disabled: disabledProp = false,
@@ -22,7 +23,10 @@
22
23
  ...restProps
23
24
  }: AccordionRootProps = $props();
24
25
 
25
- const isControlled = untrack(() => value !== undefined);
26
+ // Controlled-ness is NOT inferred from `value` being defined: `bind:value={items}` and
27
+ // `value={items}` are indistinguishable at runtime, so inferring it silently broke
28
+ // every `bind:value`. It is opt-in via `controlledValue` instead.
29
+ const isControlled = untrack(() => controlledValue);
26
30
  const instanceId = untrack(() => id) ?? generatedId;
27
31
 
28
32
  let rootRef: HTMLDivElement | null = $state(null);
@@ -31,7 +35,8 @@
31
35
  createAccordionContext({
32
36
  instanceId,
33
37
  isControlled,
34
- initialValue: isControlled ? untrack(() => value) : untrack(() => defaultValue),
38
+ // `value` seeds the initial state whenever it is supplied, bound or not.
39
+ initialValue: untrack(() => value) ?? untrack(() => defaultValue),
35
40
  selectionMode: (() => selectionMode)(),
36
41
  isDisabled: (() => disabledProp)(),
37
42
  orientation: (() => orientation)(),
@@ -75,8 +80,15 @@
75
80
  accordion.setLoop(loop);
76
81
  });
77
82
 
83
+ // Whether to adopt an incoming `value` is a separate question from who owns the state,
84
+ // so it is latched at init off the prop rather than off `controlledValue`: a parent
85
+ // that supplies `value` drives the accordion, bound or not. Latched, not reactive —
86
+ // re-checking `value !== undefined` would switch this on the moment our own write-back
87
+ // defines it, and the component would then re-adopt the echo of its own change.
88
+ const adoptsValueProp = untrack(() => value !== undefined);
89
+
78
90
  $effect(() => {
79
- if (!isControlled) return;
91
+ if (!adoptsValueProp) return;
80
92
  accordion.setOpenValues(value);
81
93
  });
82
94
  </script>
@@ -1,5 +1,5 @@
1
1
  import { getContext, setContext } from 'svelte';
2
- import { SvelteMap } from 'svelte/reactivity';
2
+ import { SvelteMap, SvelteSet } from 'svelte/reactivity';
3
3
  import { asCommand } from '../../internal/as-command.js';
4
4
  const ACCORDION_CONTEXT_KEY = Symbol('accordion');
5
5
  function normalizeIdSegment(value) {
@@ -9,7 +9,7 @@ function valuesMatch(left, right) {
9
9
  return Object.is(left, right);
10
10
  }
11
11
  function normalizeValues(values, selectionMode, order = []) {
12
- const normalized = new Set();
12
+ const normalized = new SvelteSet();
13
13
  if (selectionMode === 'single') {
14
14
  const orderedValue = order.find((orderedItem) => (values ?? []).some((candidate) => valuesMatch(candidate, orderedItem)));
15
15
  const fallbackValue = (values ?? []).find((candidate) => !order.some((orderedItem) => valuesMatch(candidate, orderedItem)));
@@ -138,7 +138,7 @@ export function createAccordionContext(options) {
138
138
  function reconcileOpen(changedValue, changeOptions) {
139
139
  if (isControlled)
140
140
  return;
141
- const nextValues = new Set(openValues);
141
+ const nextValues = new SvelteSet(openValues);
142
142
  let removedValue;
143
143
  for (const openValue of openValues) {
144
144
  const registeredItem = items.get(openValue);
@@ -228,7 +228,7 @@ export function createAccordionContext(options) {
228
228
  if (isItemDisabled(value))
229
229
  return null;
230
230
  const isValueOpen = openValues.has(value);
231
- const nextValues = new Set(openValues);
231
+ const nextValues = new SvelteSet(openValues);
232
232
  if (selectionMode === 'single') {
233
233
  if (isValueOpen) {
234
234
  if (disallowEmptySelection)
@@ -3,10 +3,17 @@ import type { HTMLAttributes, HTMLButtonAttributes } from 'svelte/elements';
3
3
  import type { AccordionContext, AccordionOrientation, AccordionSelectionMode, AccordionValue } from './root/context.svelte';
4
4
  export type { AccordionContext, AccordionOrientation, AccordionSelectionMode, AccordionValue } from './root/context.svelte';
5
5
  export type AccordionRootProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class'> & {
6
- /** Controlled list of open item values. */
6
+ /** List of open item values. Two-way by default — use `bind:value`. */
7
7
  value?: AccordionValue[];
8
- /** Initially open item values when uncontrolled. */
8
+ /** Initially open item values, for when `value` is not supplied. */
9
9
  defaultValue?: AccordionValue[];
10
+ /**
11
+ * Opt into fully controlled state: the component stops writing back to `value` and
12
+ * only reports through `onChange`, so the parent can reject a change by not flowing
13
+ * the new value back down. Off by default, because `bind:value` — the common case —
14
+ * needs the write-back to work at all.
15
+ */
16
+ controlledValue?: boolean;
10
17
  /** Called with the new list of open item values after a user toggle. */
11
18
  onChange?: (value: AccordionValue[]) => void;
12
19
  /** Whether one (`'single'`) or several (`'multiple'`) panels can be open at once. */
@@ -9,7 +9,9 @@ declare function $$render<T extends object = object>(): {
9
9
  selectionMode?: "single" | "multiple";
10
10
  value?: Iterable<string | number>;
11
11
  defaultValue?: Iterable<string | number>;
12
+ controlledValue?: boolean;
12
13
  children?: Snippet<[]> | Snippet<[object]> | undefined;
14
+ header?: Snippet;
13
15
  class?: string;
14
16
  id?: string;
15
17
  'aria-label'?: string;
@@ -17,6 +19,10 @@ declare function $$render<T extends object = object>(): {
17
19
  disableFocusHandling?: boolean;
18
20
  loop?: boolean;
19
21
  typeahead?: boolean;
22
+ virtualizer?: {
23
+ rowHeight?: number;
24
+ overscan?: number;
25
+ } | undefined;
20
26
  } & {
21
27
  context?: ListBoxContext;
22
28
  element?: HTMLElement;
@@ -1,3 +1,9 @@
1
+ /* eslint-disable svelte/prefer-svelte-reactivity --
2
+ * The Map/Set instances below are transient collections rebuilt inside `$derived`
3
+ * getters. Svelte forbids mutating a reactive collection (SvelteMap/SvelteSet)
4
+ * inside a derived (state_unsafe_mutation), and reactivity here is already driven
5
+ * by a version signal + reassignment — so plain Map/Set is intentional and correct.
6
+ */
1
7
  import { getContext, setContext } from 'svelte';
2
8
  import { asCommand } from '../../internal/as-command.js';
3
9
  import { addDays, addMonths, buildMonthGrid, compareDates, formatCalendarDate, formatMonthHeading, getTodayUtcDate, getWeekdayLabels, isValidCalendarDateValue, parseCalendarDate, resolveFirstDayOfWeek, startOfMonth } from './date-utils';
@@ -745,9 +751,9 @@ export function createCalendarContext(options) {
745
751
  break;
746
752
  case 'Enter':
747
753
  case ' ':
748
- // Legacy key value emitted by some older browsers/IMEs; kept in sync
749
- // with the body-cell press-state handling, which accepts it too.
750
754
  case 'Spacebar':
755
+ // 'Spacebar' is a legacy key value emitted by some older browsers/IMEs;
756
+ // kept in sync with the body-cell press-state handling, which accepts it too.
751
757
  event.preventDefault();
752
758
  setFocusVisible(true);
753
759
  if (selectionMode === 'range' &&
@@ -27,10 +27,23 @@
27
27
  value?: string;
28
28
  /** Associates the hidden input with a form by id. */
29
29
  form?: string;
30
+ /** Checked state. Two-way by default — use `bind:checked`. */
30
31
  checked?: boolean;
32
+ /** Initial checked state, for when `checked` is not supplied. */
31
33
  defaultChecked?: boolean;
34
+ /**
35
+ * Opt into fully controlled `checked`: the component stops writing back to the prop
36
+ * and only reports through `onCheckedChange`, so the parent can reject a change by
37
+ * not flowing the new value back down. Off by default, because `bind:checked` —
38
+ * the common case — needs the write-back to work at all.
39
+ */
40
+ controlledChecked?: boolean;
41
+ /** Indeterminate state. Two-way by default — use `bind:indeterminate`. */
32
42
  indeterminate?: boolean;
43
+ /** Initial indeterminate state, for when `indeterminate` is not supplied. */
33
44
  defaultIndeterminate?: boolean;
45
+ /** Opt into fully controlled `indeterminate`. See `controlledChecked`. */
46
+ controlledIndeterminate?: boolean;
34
47
  onCheckedChange?: (checked: boolean) => void;
35
48
  onIndeterminateChange?: (indeterminate: boolean) => void;
36
49
  disabled?: boolean;
@@ -88,8 +101,10 @@
88
101
  form,
89
102
  checked = $bindable(),
90
103
  defaultChecked = false,
104
+ controlledChecked = false,
91
105
  indeterminate = $bindable(),
92
106
  defaultIndeterminate = false,
107
+ controlledIndeterminate = false,
93
108
  onCheckedChange,
94
109
  onIndeterminateChange,
95
110
  disabled = false,
@@ -149,23 +164,25 @@
149
164
  }
150
165
  });
151
166
 
152
- // Controlled-ness is decided once, from whether the prop was provided at init.
153
- const isCheckedControlled = untrack(() => checked) !== undefined;
154
- const isIndeterminateControlled = untrack(() => indeterminate) !== undefined;
155
-
156
- // In uncontrolled mode, write the initial state back so `bind:` parents see the default.
157
- if (!isCheckedControlled) {
167
+ // Controlled-ness is NOT inferred from the props being defined: `bind:checked={value}`
168
+ // and `checked={value}` are indistinguishable at runtime, so inferring it silently
169
+ // broke every `bind:checked` seeded with `false`. It is opt-in per prop instead.
170
+ // Write the initial state back so `bind:` parents see the resolved default. Read
171
+ // untracked: this is a deliberate one-time seed at init, not a reactive mirror.
172
+ if (!untrack(() => controlledChecked)) {
158
173
  checked = initialState === 'checked';
159
174
  }
160
175
 
161
- if (!isIndeterminateControlled) {
176
+ if (!untrack(() => controlledIndeterminate)) {
162
177
  indeterminate = initialState === 'indeterminate';
163
178
  }
164
179
 
180
+ // The prop wins whenever it is supplied — that covers both `bind:` and a plain
181
+ // value — and the internal state only carries the fully uncontrolled case.
165
182
  const currentState = $derived.by(() =>
166
183
  resolveState(
167
- isCheckedControlled ? Boolean(checked) : checkedInternal,
168
- isIndeterminateControlled ? Boolean(indeterminate) : indeterminateInternal
184
+ controlledChecked ? Boolean(checked) : (checked ?? checkedInternal),
185
+ controlledIndeterminate ? Boolean(indeterminate) : (indeterminate ?? indeterminateInternal)
169
186
  )
170
187
  );
171
188
 
@@ -184,12 +201,12 @@
184
201
  const previousChecked = currentChecked;
185
202
  const previousIndeterminate = currentIndeterminate;
186
203
 
187
- if (!isCheckedControlled) {
204
+ if (!controlledChecked) {
188
205
  checkedInternal = nextChecked;
189
206
  checked = nextChecked;
190
207
  }
191
208
 
192
- if (!isIndeterminateControlled) {
209
+ if (!controlledIndeterminate) {
193
210
  indeterminateInternal = nextIndeterminate;
194
211
  indeterminate = nextIndeterminate;
195
212
  }
@@ -7,10 +7,23 @@ type CheckboxRootProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children' | 'cla
7
7
  value?: string;
8
8
  /** Associates the hidden input with a form by id. */
9
9
  form?: string;
10
+ /** Checked state. Two-way by default — use `bind:checked`. */
10
11
  checked?: boolean;
12
+ /** Initial checked state, for when `checked` is not supplied. */
11
13
  defaultChecked?: boolean;
14
+ /**
15
+ * Opt into fully controlled `checked`: the component stops writing back to the prop
16
+ * and only reports through `onCheckedChange`, so the parent can reject a change by
17
+ * not flowing the new value back down. Off by default, because `bind:checked` —
18
+ * the common case — needs the write-back to work at all.
19
+ */
20
+ controlledChecked?: boolean;
21
+ /** Indeterminate state. Two-way by default — use `bind:indeterminate`. */
12
22
  indeterminate?: boolean;
23
+ /** Initial indeterminate state, for when `indeterminate` is not supplied. */
13
24
  defaultIndeterminate?: boolean;
25
+ /** Opt into fully controlled `indeterminate`. See `controlledChecked`. */
26
+ controlledIndeterminate?: boolean;
14
27
  onCheckedChange?: (checked: boolean) => void;
15
28
  onIndeterminateChange?: (indeterminate: boolean) => void;
16
29
  disabled?: boolean;
@@ -90,6 +90,11 @@ export type TimeSelectionState = {
90
90
  * values entirely (TimePicker's historical policy, now applied to both); and
91
91
  * externally provided values (controlled `value` prop or `defaultValue`) are
92
92
  * normalized to `null` when malformed or out of range before being adopted.
93
+ * - Wheel selection is the one path that adjusts rather than rejects: a wheel
94
+ * option is offered whenever *some* in-range time still fits it, and picking
95
+ * it clamps the less significant segments onto the boundary (hour `17` under
96
+ * a `17:00` max commits `17:00`, not `null`). Without this the boundary hour
97
+ * was unreachable unless the minute already happened to be low enough.
93
98
  * - `isEditable` differs: TimePicker also blocks mutations while `readonly`;
94
99
  * Clock has no readonly concept and only checks `disabled`.
95
100
  * - TimePicker layers a multi-digit typing buffer on top of this state via the
@@ -2,7 +2,24 @@ import { untrack } from 'svelte';
2
2
  import { fromStore } from 'svelte/store';
3
3
  import { useLocaleContextOptional } from '../../locale-provider/context';
4
4
  import { buildWheelOptions } from './wheel-options';
5
- import { buildTimePartsFromDraft, clampToStep, createEmptyTimePickerDraft, formatTimePickerValue, getRequiredSegments, getSegmentLabel, isSegmentValueEmpty, isTimeOutOfRange, isValidTimePickerValue, normalizeSegmentNumberInput, normalizeTimePickerValue, toDraftFromTimeValue } from './time-utils';
5
+ import { buildTimePartsFromDraft, clampToStep, createEmptyTimePickerDraft, formatTimePickerValue, getRequiredSegments, getSegmentLabel, isSegmentValueEmpty, isTimeOutOfRange, isValidTimePickerValue, normalizeSegmentNumberInput, normalizeTimePickerValue, parseTimePickerValue, toDraftFromTimeValue } from './time-utils';
6
+ /**
7
+ * Editable segments ordered from most to least significant. Range checks and
8
+ * boundary clamping both need to know which segments a given column is free to
9
+ * move: picking an hour may rewrite the minute, never the other way around.
10
+ */
11
+ const SEGMENT_SIGNIFICANCE = [
12
+ 'dayPeriod',
13
+ 'hour',
14
+ 'minute',
15
+ 'second'
16
+ ];
17
+ function getLessSignificantSegments(type) {
18
+ const index = SEGMENT_SIGNIFICANCE.indexOf(type);
19
+ if (index < 0)
20
+ return [];
21
+ return SEGMENT_SIGNIFICANCE.slice(index + 1);
22
+ }
6
23
  /**
7
24
  * Shared time-selection state used by both `Clock.Root` and `TimePicker.Root`.
8
25
  *
@@ -20,6 +37,11 @@ import { buildTimePartsFromDraft, clampToStep, createEmptyTimePickerDraft, forma
20
37
  * values entirely (TimePicker's historical policy, now applied to both); and
21
38
  * externally provided values (controlled `value` prop or `defaultValue`) are
22
39
  * normalized to `null` when malformed or out of range before being adopted.
40
+ * - Wheel selection is the one path that adjusts rather than rejects: a wheel
41
+ * option is offered whenever *some* in-range time still fits it, and picking
42
+ * it clamps the less significant segments onto the boundary (hour `17` under
43
+ * a `17:00` max commits `17:00`, not `null`). Without this the boundary hour
44
+ * was unreachable unless the minute already happened to be low enough.
23
45
  * - `isEditable` differs: TimePicker also blocks mutations while `readonly`;
24
46
  * Clock has no readonly concept and only checks `disabled`.
25
47
  * - TimePicker layers a multi-digit typing buffer on top of this state via the
@@ -147,6 +169,11 @@ export function createTimeSelectionState(options) {
147
169
  function setSegmentValue(type, nextValue) {
148
170
  if (!options.isEditable())
149
171
  return;
172
+ writeSegmentValue(type, nextValue);
173
+ commitFromDraft();
174
+ }
175
+ /** Normalizes and writes a segment into the draft without committing it. */
176
+ function writeSegmentValue(type, nextValue) {
150
177
  options.onBeforeSegmentMutation?.(type);
151
178
  if (type === 'dayPeriod') {
152
179
  const normalized = nextValue.trim().toUpperCase();
@@ -187,7 +214,6 @@ export function createTimeSelectionState(options) {
187
214
  segmentDraft.dayPeriod = 'AM';
188
215
  }
189
216
  }
190
- commitFromDraft();
191
217
  }
192
218
  function commitFromDraft() {
193
219
  const granularity = options.granularity();
@@ -219,15 +245,50 @@ export function createTimeSelectionState(options) {
219
245
  : createEmptyTimePickerDraft();
220
246
  options.onDraftReplaced?.();
221
247
  }
248
+ /**
249
+ * Pulls the segments below `changedType` onto the range boundary when the
250
+ * draft overshot it. Picking hour `17` under a `17:00` max leaves the minute
251
+ * on whatever it was (`17:30`); rather than refusing the commit, the minute
252
+ * moves to the boundary's own (`17:00`). Only runs when the boundary shares
253
+ * the segments at or above `changedType`, so it can never rewrite the
254
+ * selection the user just made.
255
+ */
256
+ function clampDraftToRangeBoundary(changedType) {
257
+ const granularity = options.granularity();
258
+ const parts = buildTimePartsFromDraft(segmentDraft, granularity, resolvedHourCycle);
259
+ if (!parts)
260
+ return;
261
+ const candidate = formatTimePickerValue(parts, granularity);
262
+ const overshootsMax = isTimeOutOfRange(candidate, undefined, normalizedMaxValue, granularity);
263
+ const undershootsMin = isTimeOutOfRange(candidate, normalizedMinValue, undefined, granularity);
264
+ if (!overshootsMax && !undershootsMin)
265
+ return;
266
+ const boundary = overshootsMax ? normalizedMaxValue : normalizedMinValue;
267
+ if (!boundary)
268
+ return;
269
+ const boundaryParts = parseTimePickerValue(boundary);
270
+ if (!boundaryParts)
271
+ return;
272
+ // The hour is the only segment above `minute`/`second` that can differ here;
273
+ // if it does, the boundary belongs to another hour and its minutes say
274
+ // nothing about this one.
275
+ const lessSignificant = getLessSignificantSegments(changedType);
276
+ if (lessSignificant.includes('minute') && boundaryParts.hour !== parts.hour)
277
+ return;
278
+ for (const segment of lessSignificant) {
279
+ if (segment === 'minute')
280
+ segmentDraft.minute = String(boundaryParts.minute);
281
+ if (segment === 'second')
282
+ segmentDraft.second = String(boundaryParts.second);
283
+ }
284
+ }
222
285
  function selectWheelValue(type, optionValue) {
223
286
  if (!options.isEditable())
224
287
  return;
225
- if (type === 'dayPeriod') {
226
- setSegmentValue(type, optionValue.toUpperCase());
227
- }
228
- else {
229
- setSegmentValue(type, optionValue);
230
- }
288
+ const nextValue = type === 'dayPeriod' ? optionValue.toUpperCase() : optionValue;
289
+ writeSegmentValue(type, nextValue);
290
+ clampDraftToRangeBoundary(type);
291
+ commitFromDraft();
231
292
  }
232
293
  function getSelectedWheelValue(type) {
233
294
  const selected = getSegmentValue(type);
@@ -248,6 +309,22 @@ export function createTimeSelectionState(options) {
248
309
  return null;
249
310
  return formatTimePickerValue(parts, granularity);
250
311
  };
312
+ // An option is out of range only when EVERY time it can still produce is out
313
+ // of range. Testing the single candidate built from the current draft would
314
+ // disable the boundary option whenever a less significant segment happens to
315
+ // overshoot — with max `17:00` and the minute sitting on `30`, hour `17` would
316
+ // read as `17:30` and never become selectable. Comparing the earliest/latest
317
+ // time the option spans keeps the boundary reachable; `selectWheelValue`
318
+ // clamps the less significant segments when the option is committed.
319
+ const isOptionOutOfRange = (partial) => {
320
+ const earliest = getCandidateFromPartial(fillLessSignificant(type, partial, 'earliest'));
321
+ const latest = getCandidateFromPartial(fillLessSignificant(type, partial, 'latest'));
322
+ if (!earliest || !latest)
323
+ return false;
324
+ const startsAfterMax = isTimeOutOfRange(earliest, undefined, normalizedMaxValue, granularity);
325
+ const endsBeforeMin = isTimeOutOfRange(latest, normalizedMinValue, undefined, granularity);
326
+ return startsAfterMax || endsBeforeMin;
327
+ };
251
328
  return buildWheelOptions({
252
329
  type,
253
330
  granularity,
@@ -256,11 +333,37 @@ export function createTimeSelectionState(options) {
256
333
  minuteStep: options.minuteStep(),
257
334
  secondStep: options.secondStep(),
258
335
  hasRangeBounds,
259
- getCandidateFromPartial,
260
- isOutOfRange: (candidate) => isTimeOutOfRange(candidate, normalizedMinValue, normalizedMaxValue, granularity),
336
+ isPartialOutOfRange: isOptionOutOfRange,
261
337
  locale: resolvedLocale
262
338
  });
263
339
  }
340
+ /**
341
+ * Fills the segments below `type` with the lowest / highest value they can
342
+ * take, so the caller can measure the whole span an option covers. In the
343
+ * 12-hour cycle the lowest hour is `12` (midnight / noon), not `1`.
344
+ */
345
+ function fillLessSignificant(type, partial, edge) {
346
+ const filled = { ...partial };
347
+ for (const segment of getLessSignificantSegments(type)) {
348
+ if (segment === 'hour') {
349
+ filled.hour =
350
+ edge === 'earliest'
351
+ ? resolvedHourCycle === 12
352
+ ? '12'
353
+ : '0'
354
+ : resolvedHourCycle === 12
355
+ ? '11'
356
+ : '23';
357
+ }
358
+ else if (segment === 'minute') {
359
+ filled.minute = edge === 'earliest' ? '0' : '59';
360
+ }
361
+ else if (segment === 'second') {
362
+ filled.second = edge === 'earliest' ? '0' : '59';
363
+ }
364
+ }
365
+ return filled;
366
+ }
264
367
  function getSegmentLabelByType(type) {
265
368
  return getSegmentLabel(type, resolvedLocale);
266
369
  }
@@ -1,4 +1,4 @@
1
- import { type TimePickerDraft, type TimePickerEditableSegmentType, type TimePickerGranularity, type TimePickerHourCycle, type TimePickerTimeValue } from './time-utils';
1
+ import { type TimePickerDraft, type TimePickerEditableSegmentType, type TimePickerGranularity, type TimePickerHourCycle } from './time-utils';
2
2
  export type WheelOption = {
3
3
  value: string;
4
4
  label: string;
@@ -12,7 +12,11 @@ export declare function buildWheelOptions(params: {
12
12
  minuteStep: number;
13
13
  secondStep: number;
14
14
  hasRangeBounds: boolean;
15
- getCandidateFromPartial: (partial: Partial<TimePickerDraft>) => TimePickerTimeValue | null;
16
- isOutOfRange: (value: TimePickerTimeValue) => boolean;
15
+ /**
16
+ * Whether fixing this one segment leaves no in-range time at all. Receives the
17
+ * partial draft for the option; the caller decides how much freedom the
18
+ * remaining segments have (see `create-time-selection-state`).
19
+ */
20
+ isPartialOutOfRange: (partial: Partial<TimePickerDraft>) => boolean;
17
21
  locale?: string;
18
22
  }): WheelOption[];
@@ -1,15 +1,10 @@
1
1
  import { getLocalizedDayPeriod } from './time-utils';
2
2
  export function buildWheelOptions(params) {
3
- const { type, hourCycle, hourStep, minuteStep, secondStep, hasRangeBounds, getCandidateFromPartial, isOutOfRange, locale } = params;
3
+ const { type, hourCycle, hourStep, minuteStep, secondStep, hasRangeBounds, isPartialOutOfRange, locale } = params;
4
4
  const options = [];
5
5
  if (type === 'dayPeriod') {
6
6
  for (const option of ['AM', 'PM']) {
7
- const disabled = hasRangeBounds
8
- ? (() => {
9
- const candidate = getCandidateFromPartial({ dayPeriod: option });
10
- return candidate ? isOutOfRange(candidate) : false;
11
- })()
12
- : false;
7
+ const disabled = hasRangeBounds ? isPartialOutOfRange({ dayPeriod: option }) : false;
13
8
  options.push({
14
9
  value: option,
15
10
  label: locale ? getLocalizedDayPeriod(locale, option) : option,
@@ -45,14 +40,11 @@ export function buildWheelOptions(params) {
45
40
  for (let current = min; current <= max; current += step) {
46
41
  const valueString = String(current);
47
42
  const disabled = hasRangeBounds
48
- ? (() => {
49
- const candidate = getCandidateFromPartial(type === 'hour'
50
- ? { hour: valueString }
51
- : type === 'minute'
52
- ? { minute: valueString }
53
- : { second: valueString });
54
- return candidate ? isOutOfRange(candidate) : false;
55
- })()
43
+ ? isPartialOutOfRange(type === 'hour'
44
+ ? { hour: valueString }
45
+ : type === 'minute'
46
+ ? { minute: valueString }
47
+ : { second: valueString })
56
48
  : false;
57
49
  options.push({
58
50
  value: valueString,
@@ -31,7 +31,8 @@
31
31
  | 'onclick'
32
32
  > & {
33
33
  type: ClockEditableSegmentType;
34
- children?: Snippet<[TimePickerWheelOption]>;
34
+ /** Receives the option and whether it is the column's selected value. */
35
+ children?: Snippet<[TimePickerWheelOption, boolean]>;
35
36
  class?: string;
36
37
  'aria-label'?: string;
37
38
  };
@@ -202,6 +203,13 @@
202
203
  const fallbackIndex = findClosestEnabledIndex(nextIndex, direction);
203
204
  if (fallbackIndex >= 0 && fallbackIndex !== nextIndex) {
204
205
  lastCenteredIndex = fallbackIndex;
206
+ // The wheel re-centres on the fallback, so the value has to follow it.
207
+ // Leaving it behind desynced the column from the committed time: the
208
+ // item under the axis read `16` while the value stayed on `15`.
209
+ const fallbackOption = options[fallbackIndex];
210
+ if (fallbackOption && selectedValue !== fallbackOption.value) {
211
+ clock.selectWheelValue(type, fallbackOption.value);
212
+ }
205
213
  return fallbackIndex;
206
214
  }
207
215
  return null;
@@ -512,7 +520,7 @@
512
520
  >
513
521
  {#each options as option, index (option.value)}
514
522
  {#if children}
515
- {@render children(option)}
523
+ {@render children(option, selectedValue === option.value)}
516
524
  {:else}
517
525
  <TimePickerWheelItem
518
526
  {type}
@@ -8,7 +8,8 @@ type TimePickerWheelOption = {
8
8
  };
9
9
  type TimePickerWheelColumnProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class' | 'role' | 'tabindex' | 'aria-label' | 'onkeydown' | 'onfocusin' | 'onfocusout' | 'onmousedown' | 'onclick'> & {
10
10
  type: ClockEditableSegmentType;
11
- children?: Snippet<[TimePickerWheelOption]>;
11
+ /** Receives the option and whether it is the column's selected value. */
12
+ children?: Snippet<[TimePickerWheelOption, boolean]>;
12
13
  class?: string;
13
14
  'aria-label'?: string;
14
15
  };
@@ -9,6 +9,7 @@
9
9
  id,
10
10
  open: openProp = $bindable(),
11
11
  defaultOpen = false,
12
+ controlledOpen = false,
12
13
  onOpenChange,
13
14
  disabled = false,
14
15
  children,
@@ -18,18 +19,22 @@
18
19
  ...restProps
19
20
  }: CollapsibleRootProps = $props();
20
21
 
21
- const isControlled = untrack(() => openProp !== undefined);
22
22
  const instanceId = untrack(() => id) ?? generatedId;
23
23
 
24
24
  let rootRef: HTMLDivElement | null = $state(null);
25
25
  let internalOpen = $state(untrack(() => defaultOpen));
26
26
 
27
- const isOpen = $derived(isControlled ? Boolean(openProp) : internalOpen);
27
+ // `open` wins whenever it is supplied — that covers both `bind:open` and a plain
28
+ // `open={...}` — and the internal state only carries the fully uncontrolled case.
29
+ // Controlled-ness is NOT inferred from `open` being defined: `bind:open={value}` and
30
+ // `open={value}` are indistinguishable at runtime, so inferring it silently broke
31
+ // every `bind:open` seeded with `false`. It is opt-in via `controlledOpen` instead.
32
+ const isOpen = $derived(controlledOpen ? Boolean(openProp) : (openProp ?? internalOpen));
28
33
 
29
34
  function setOpen(next: boolean) {
30
35
  if (disabled || next === isOpen) return;
31
- if (!isControlled) {
32
- // Uncontrolled: apply the change and keep `bind:open` in sync.
36
+ if (!controlledOpen) {
37
+ // Apply the change and keep `bind:open` in sync.
33
38
  internalOpen = next;
34
39
  openProp = next;
35
40
  }
@@ -3,8 +3,17 @@ import type { HTMLAttributes, HTMLButtonAttributes } from 'svelte/elements';
3
3
  import type { CollapsibleContext } from './root/context.js';
4
4
  export type { CollapsibleContext } from './root/context.js';
5
5
  export type CollapsibleRootProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class'> & {
6
+ /** Open state. Two-way by default — use `bind:open`. */
6
7
  open?: boolean;
8
+ /** Initial open state, for when `open` is not supplied. */
7
9
  defaultOpen?: boolean;
10
+ /**
11
+ * Opt into fully controlled state: the component stops writing back to `open` and
12
+ * only reports through `onOpenChange`, so the parent can reject a change by not
13
+ * flowing the new value back down. Off by default, because `bind:open` — the common
14
+ * case — needs the write-back to work at all.
15
+ */
16
+ controlledOpen?: boolean;
8
17
  onOpenChange?: (open: boolean) => void;
9
18
  disabled?: boolean;
10
19
  children?: Snippet;
@@ -115,6 +115,14 @@
115
115
  }
116
116
  </script>
117
117
 
118
+ <!--
119
+ `autocomplete="new-password"` where "off" is what you would expect: Chrome ignores "off"
120
+ on a field it has classified as part of an address form, so a combobox called "País" got
121
+ the browser's saved-addresses dropdown *over* its own option list. "new-password" is the
122
+ one value Chromium honours as "never autofill this", and on a text input it shows no
123
+ password UI of its own. The `data-*` attributes are the equivalent opt-out for the common
124
+ password managers. Consumers can still override it through `restProps`.
125
+ -->
118
126
  <Input
119
127
  bind:element={inputRef}
120
128
  type="text"
@@ -131,7 +139,10 @@
131
139
  aria-label={ariaLabel}
132
140
  aria-labelledby={ariaLabelledby}
133
141
  aria-describedby={ariaDescribedby}
134
- autocomplete="off"
142
+ autocomplete="new-password"
143
+ data-1p-ignore
144
+ data-lpignore="true"
145
+ data-form-type="other"
135
146
  value={ctx.displayValue}
136
147
  disabled={ctx.isDisabled}
137
148
  readonly={ctx.isReadOnly}