@human-kit/ui 1.0.0-beta.6 → 1.0.0-beta.8

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 (223) hide show
  1. package/dist/FOCUS_STATE_CONTRACT.md +15 -4
  2. package/dist/FOCUS_STATE_REVIEW_TEMPLATE.md +8 -8
  3. package/dist/autocomplete/item/autocomplete-item.svelte +10 -0
  4. package/dist/avatar/README.md +52 -0
  5. package/dist/avatar/count/avatar-count.svelte +56 -0
  6. package/dist/avatar/count/avatar-count.svelte.d.ts +4 -0
  7. package/dist/avatar/fallback/avatar-fallback.svelte +67 -0
  8. package/dist/avatar/fallback/avatar-fallback.svelte.d.ts +4 -0
  9. package/dist/avatar/group/avatar-group.svelte +65 -0
  10. package/dist/avatar/group/avatar-group.svelte.d.ts +4 -0
  11. package/dist/avatar/group/context.d.ts +15 -0
  12. package/dist/avatar/group/context.js +15 -0
  13. package/dist/avatar/image/avatar-image.svelte +104 -0
  14. package/dist/avatar/image/avatar-image.svelte.d.ts +4 -0
  15. package/dist/avatar/index.d.ts +22 -0
  16. package/dist/avatar/index.js +10 -0
  17. package/dist/avatar/index.parts.d.ts +5 -0
  18. package/dist/avatar/index.parts.js +5 -0
  19. package/dist/avatar/root/avatar-root.svelte +79 -0
  20. package/dist/avatar/root/avatar-root.svelte.d.ts +4 -0
  21. package/dist/avatar/root/context.d.ts +14 -0
  22. package/dist/avatar/root/context.js +15 -0
  23. package/dist/avatar/types.d.ts +84 -0
  24. package/dist/avatar/types.js +1 -0
  25. package/dist/breadcrumbs/README.md +65 -0
  26. package/dist/breadcrumbs/ellipsis/breadcrumbs-ellipsis.svelte +62 -0
  27. package/dist/breadcrumbs/ellipsis/breadcrumbs-ellipsis.svelte.d.ts +4 -0
  28. package/dist/breadcrumbs/index.d.ts +23 -0
  29. package/dist/breadcrumbs/index.js +10 -0
  30. package/dist/breadcrumbs/index.parts.d.ts +6 -0
  31. package/dist/breadcrumbs/index.parts.js +6 -0
  32. package/dist/breadcrumbs/item/breadcrumbs-item.svelte +42 -0
  33. package/dist/breadcrumbs/item/breadcrumbs-item.svelte.d.ts +4 -0
  34. package/dist/breadcrumbs/link/breadcrumbs-link.svelte +47 -0
  35. package/dist/breadcrumbs/link/breadcrumbs-link.svelte.d.ts +4 -0
  36. package/dist/breadcrumbs/list/breadcrumbs-list.svelte +31 -0
  37. package/dist/breadcrumbs/list/breadcrumbs-list.svelte.d.ts +4 -0
  38. package/dist/breadcrumbs/root/breadcrumbs-root.svelte +112 -0
  39. package/dist/breadcrumbs/root/breadcrumbs-root.svelte.d.ts +4 -0
  40. package/dist/breadcrumbs/root/context.d.ts +19 -0
  41. package/dist/breadcrumbs/root/context.js +15 -0
  42. package/dist/breadcrumbs/separator/breadcrumbs-separator.svelte +35 -0
  43. package/dist/breadcrumbs/separator/breadcrumbs-separator.svelte.d.ts +4 -0
  44. package/dist/breadcrumbs/types.d.ts +80 -0
  45. package/dist/breadcrumbs/types.js +1 -0
  46. package/dist/button/root/button-root.svelte +9 -0
  47. package/dist/calendar/body-cell/calendar-body-cell.svelte +7 -0
  48. package/dist/checkbox/indicator/checkbox-indicator.svelte +1 -0
  49. package/dist/checkbox/indicator/checkbox-indicator.svelte.d.ts +1 -0
  50. package/dist/checkbox/root/checkbox-root.svelte +106 -30
  51. package/dist/checkbox/root/checkbox-root.svelte.d.ts +5 -0
  52. package/dist/checkbox-group/README.md +95 -0
  53. package/dist/checkbox-group/index.d.ts +15 -0
  54. package/dist/checkbox-group/index.js +6 -0
  55. package/dist/checkbox-group/index.parts.d.ts +4 -0
  56. package/dist/checkbox-group/index.parts.js +7 -0
  57. package/dist/checkbox-group/label/checkbox-group-label.svelte +36 -0
  58. package/dist/checkbox-group/label/checkbox-group-label.svelte.d.ts +4 -0
  59. package/dist/checkbox-group/root/checkbox-group-root.svelte +118 -0
  60. package/dist/checkbox-group/root/checkbox-group-root.svelte.d.ts +4 -0
  61. package/dist/checkbox-group/root/context.svelte.d.ts +52 -0
  62. package/dist/checkbox-group/root/context.svelte.js +251 -0
  63. package/dist/checkbox-group/types.d.ts +57 -0
  64. package/dist/checkbox-group/types.js +1 -0
  65. package/dist/combobox/popover/combobox-popover.svelte +4 -56
  66. package/dist/dialog/root/dialog-root.svelte +15 -2
  67. package/dist/drawer/root/drawer-root.svelte +15 -2
  68. package/dist/index.d.ts +18 -0
  69. package/dist/index.js +17 -0
  70. package/dist/internal/localized-strings.d.ts +48 -0
  71. package/dist/internal/localized-strings.js +48 -0
  72. package/dist/internal/number-precision.d.ts +9 -0
  73. package/dist/internal/number-precision.js +27 -0
  74. package/dist/menu/root/focus-state.d.ts +2 -2
  75. package/dist/menu/root/focus-state.js +8 -32
  76. package/dist/menu/root/menu-state.svelte.js +5 -1
  77. package/dist/numberfield/root/number-utils.js +1 -20
  78. package/dist/popover/root/focus-state.d.ts +2 -2
  79. package/dist/popover/root/focus-state.js +7 -34
  80. package/dist/primitives/contain-wheel.d.ts +9 -0
  81. package/dist/primitives/contain-wheel.js +41 -0
  82. package/dist/primitives/floating.d.ts +6 -0
  83. package/dist/primitives/floating.js +26 -5
  84. package/dist/primitives/focus-visible.svelte.d.ts +14 -0
  85. package/dist/primitives/focus-visible.svelte.js +19 -0
  86. package/dist/primitives/index.d.ts +1 -0
  87. package/dist/primitives/index.js +1 -0
  88. package/dist/primitives/input-modality.d.ts +7 -0
  89. package/dist/primitives/input-modality.js +32 -5
  90. package/dist/primitives/keyboard-navigation.d.ts +6 -0
  91. package/dist/primitives/keyboard-navigation.js +2 -1
  92. package/dist/primitives/trigger-focus-state.d.ts +29 -0
  93. package/dist/primitives/trigger-focus-state.js +57 -0
  94. package/dist/progress/README.md +54 -0
  95. package/dist/progress/index.d.ts +21 -0
  96. package/dist/progress/index.js +9 -0
  97. package/dist/progress/index.parts.d.ts +5 -0
  98. package/dist/progress/index.parts.js +5 -0
  99. package/dist/progress/indicator/progress-indicator.svelte +37 -0
  100. package/dist/progress/indicator/progress-indicator.svelte.d.ts +4 -0
  101. package/dist/progress/label/progress-label.svelte +34 -0
  102. package/dist/progress/label/progress-label.svelte.d.ts +4 -0
  103. package/dist/progress/root/context.d.ts +26 -0
  104. package/dist/progress/root/context.js +15 -0
  105. package/dist/progress/root/progress-root.svelte +136 -0
  106. package/dist/progress/root/progress-root.svelte.d.ts +4 -0
  107. package/dist/progress/root/progress-utils.d.ts +12 -0
  108. package/dist/progress/root/progress-utils.js +41 -0
  109. package/dist/progress/track/progress-track.svelte +27 -0
  110. package/dist/progress/track/progress-track.svelte.d.ts +4 -0
  111. package/dist/progress/types.d.ts +81 -0
  112. package/dist/progress/types.js +1 -0
  113. package/dist/progress/value/progress-value.svelte +36 -0
  114. package/dist/progress/value/progress-value.svelte.d.ts +4 -0
  115. package/dist/radio-group/README.md +103 -0
  116. package/dist/radio-group/index.d.ts +18 -0
  117. package/dist/radio-group/index.js +9 -0
  118. package/dist/radio-group/index.parts.d.ts +4 -0
  119. package/dist/radio-group/index.parts.js +4 -0
  120. package/dist/radio-group/indicator/radio-group-indicator.svelte +43 -0
  121. package/dist/radio-group/indicator/radio-group-indicator.svelte.d.ts +12 -0
  122. package/dist/radio-group/item/context.d.ts +18 -0
  123. package/dist/radio-group/item/context.js +15 -0
  124. package/dist/radio-group/item/radio-group-item.svelte +377 -0
  125. package/dist/radio-group/item/radio-group-item.svelte.d.ts +35 -0
  126. package/dist/radio-group/label/radio-group-label.svelte +37 -0
  127. package/dist/radio-group/label/radio-group-label.svelte.d.ts +4 -0
  128. package/dist/radio-group/root/context.svelte.d.ts +57 -0
  129. package/dist/radio-group/root/context.svelte.js +284 -0
  130. package/dist/radio-group/root/radio-group-root.svelte +193 -0
  131. package/dist/radio-group/root/radio-group-root.svelte.d.ts +4 -0
  132. package/dist/radio-group/types.d.ts +50 -0
  133. package/dist/radio-group/types.js +1 -0
  134. package/dist/select/README.md +129 -0
  135. package/dist/select/index.d.ts +30 -0
  136. package/dist/select/index.js +16 -0
  137. package/dist/select/index.parts.d.ts +8 -0
  138. package/dist/select/index.parts.js +9 -0
  139. package/dist/select/item/select-item.svelte +68 -0
  140. package/dist/select/item/select-item.svelte.d.ts +10 -0
  141. package/dist/select/item-indicator/select-item-indicator.svelte +55 -0
  142. package/dist/select/item-indicator/select-item-indicator.svelte.d.ts +4 -0
  143. package/dist/select/label/select-label.svelte +46 -0
  144. package/dist/select/label/select-label.svelte.d.ts +4 -0
  145. package/dist/select/list/select-list.svelte +241 -0
  146. package/dist/select/list/select-list.svelte.d.ts +62 -0
  147. package/dist/select/popover/select-popover.svelte +80 -0
  148. package/dist/select/popover/select-popover.svelte.d.ts +9 -0
  149. package/dist/select/root/context.d.ts +106 -0
  150. package/dist/select/root/context.js +22 -0
  151. package/dist/select/root/select-root.svelte +544 -0
  152. package/dist/select/root/select-root.svelte.d.ts +25 -0
  153. package/dist/select/trigger/select-trigger.svelte +192 -0
  154. package/dist/select/trigger/select-trigger.svelte.d.ts +4 -0
  155. package/dist/select/types.d.ts +133 -0
  156. package/dist/select/types.js +1 -0
  157. package/dist/select/value/select-value.svelte +61 -0
  158. package/dist/select/value/select-value.svelte.d.ts +4 -0
  159. package/dist/separator/README.md +35 -0
  160. package/dist/separator/index.d.ts +7 -0
  161. package/dist/separator/index.js +3 -0
  162. package/dist/separator/separator.svelte +254 -0
  163. package/dist/separator/separator.svelte.d.ts +45 -0
  164. package/dist/separator/types.d.ts +1 -0
  165. package/dist/separator/types.js +1 -0
  166. package/dist/slider/README.md +61 -0
  167. package/dist/slider/fill/slider-fill.svelte +40 -0
  168. package/dist/slider/fill/slider-fill.svelte.d.ts +4 -0
  169. package/dist/slider/index.d.ts +9 -0
  170. package/dist/slider/index.js +8 -0
  171. package/dist/slider/index.parts.d.ts +6 -0
  172. package/dist/slider/index.parts.js +6 -0
  173. package/dist/slider/label/slider-label.svelte +44 -0
  174. package/dist/slider/label/slider-label.svelte.d.ts +4 -0
  175. package/dist/slider/output/slider-output.svelte +46 -0
  176. package/dist/slider/output/slider-output.svelte.d.ts +4 -0
  177. package/dist/slider/root/context.d.ts +106 -0
  178. package/dist/slider/root/context.js +15 -0
  179. package/dist/slider/root/slider-root.svelte +545 -0
  180. package/dist/slider/root/slider-root.svelte.d.ts +4 -0
  181. package/dist/slider/root/slider-utils.d.ts +57 -0
  182. package/dist/slider/root/slider-utils.js +88 -0
  183. package/dist/slider/thumb/slider-thumb.svelte +276 -0
  184. package/dist/slider/thumb/slider-thumb.svelte.d.ts +4 -0
  185. package/dist/slider/track/slider-track.svelte +60 -0
  186. package/dist/slider/track/slider-track.svelte.d.ts +4 -0
  187. package/dist/slider/types.d.ts +144 -0
  188. package/dist/slider/types.js +1 -0
  189. package/dist/switch/root/switch-root.svelte +9 -0
  190. package/dist/table/column-header-cell/table-column-header-cell.svelte +24 -0
  191. package/dist/table/root/table-root.svelte +29 -6
  192. package/dist/timepicker/input/time-picker-input.svelte +12 -4
  193. package/dist/timepicker/input/time-picker-input.svelte.d.ts +12 -4
  194. package/dist/toggle/root/toggle-root.svelte +28 -0
  195. package/dist/toggle/root/toggle-root.svelte.d.ts +19 -0
  196. package/dist/toggle-group/README.md +6 -4
  197. package/dist/toggle-group/index.d.ts +2 -0
  198. package/dist/toggle-group/index.parts.d.ts +1 -0
  199. package/dist/toggle-group/index.parts.js +4 -0
  200. package/dist/tooltip/README.md +53 -0
  201. package/dist/tooltip/arrow/tooltip-arrow.svelte +36 -0
  202. package/dist/tooltip/arrow/tooltip-arrow.svelte.d.ts +4 -0
  203. package/dist/tooltip/content/tooltip-content.svelte +148 -0
  204. package/dist/tooltip/content/tooltip-content.svelte.d.ts +4 -0
  205. package/dist/tooltip/index.d.ts +8 -0
  206. package/dist/tooltip/index.js +7 -0
  207. package/dist/tooltip/index.parts.d.ts +5 -0
  208. package/dist/tooltip/index.parts.js +5 -0
  209. package/dist/tooltip/provider/tooltip-provider.svelte +36 -0
  210. package/dist/tooltip/provider/tooltip-provider.svelte.d.ts +4 -0
  211. package/dist/tooltip/root/context.d.ts +46 -0
  212. package/dist/tooltip/root/context.js +22 -0
  213. package/dist/tooltip/root/safe-polygon.d.ts +26 -0
  214. package/dist/tooltip/root/safe-polygon.js +66 -0
  215. package/dist/tooltip/root/tooltip-group.d.ts +26 -0
  216. package/dist/tooltip/root/tooltip-group.js +41 -0
  217. package/dist/tooltip/root/tooltip-root.svelte +454 -0
  218. package/dist/tooltip/root/tooltip-root.svelte.d.ts +4 -0
  219. package/dist/tooltip/trigger/tooltip-trigger.svelte +52 -0
  220. package/dist/tooltip/trigger/tooltip-trigger.svelte.d.ts +4 -0
  221. package/dist/tooltip/types.d.ts +105 -0
  222. package/dist/tooltip/types.js +1 -0
  223. package/package.json +46 -1
@@ -0,0 +1,276 @@
1
+ <script lang="ts">
2
+ import { untrack, type Snippet } from 'svelte';
3
+ import { readable } from 'svelte/store';
4
+ import { resolveLocalizedString } from '../../internal/localized-strings';
5
+ import { isRtl } from '../../internal/rtl';
6
+ import { getLocaleContext } from '../../locale-provider/context';
7
+ import { watchFocusVisible } from '../../primitives/focus-visible.svelte';
8
+ import {
9
+ shouldShowFocusVisible,
10
+ trackInteractionModality
11
+ } from '../../primitives/input-modality';
12
+ import { useSliderContext, type SliderChangeDetails } from '../root/context';
13
+ import type { SliderThumbProps, SliderThumbRenderState } from '../types';
14
+
15
+ /**
16
+ * Slider.Thumb — the handle of one value.
17
+ *
18
+ * The element the user sees is a `<div>` positioned along the track. Inside it, a native
19
+ * `<input type="range">` fills the thumb, invisible, and it is what has the focus and the ARIA
20
+ * state. The native input gives the role and the value to a screen reader, and it receives
21
+ * the swipe of a mobile screen reader as an `input` event. The keyboard is handled here and
22
+ * not by the input, so that the steps, the large steps and the text direction are the same in
23
+ * every browser.
24
+ */
25
+ let {
26
+ index: indexProp,
27
+ name,
28
+ 'aria-label': ariaLabel,
29
+ 'aria-labelledby': ariaLabelledBy,
30
+ children,
31
+ class: className = '',
32
+ element = $bindable<HTMLDivElement | null>(null),
33
+ style,
34
+ onpointerdown,
35
+ ...restProps
36
+ }: SliderThumbProps = $props();
37
+
38
+ const ctx = useSliderContext('Slider.Thumb');
39
+ const localeStore = getLocaleContext()?.locale ?? readable<string | undefined>(undefined);
40
+
41
+ let thumbRef: HTMLDivElement | null = $state(null);
42
+ let inputRef: HTMLInputElement | null = $state(null);
43
+
44
+ const registration = ctx.registerThumb({
45
+ index: untrack(() => indexProp),
46
+ inputRef: () => inputRef
47
+ });
48
+ const index = registration.index;
49
+ const inputId = ctx.getThumbInputId(index);
50
+
51
+ $effect(() => {
52
+ element = thumbRef;
53
+ return () => {
54
+ element = null;
55
+ };
56
+ });
57
+
58
+ $effect(() => registration.unregister);
59
+
60
+ const value = $derived(ctx.values[index] ?? ctx.min);
61
+ const percent = $derived(ctx.getPercent(value));
62
+ const text = $derived(ctx.formatValue(value));
63
+ const valueText = $derived(ctx.getValueText(value, index));
64
+ const dragging = $derived(ctx.draggingIndex === index);
65
+ const focused = $derived(ctx.focusedIndex === index);
66
+ const focusVisible = $derived(focused && ctx.isFocusVisible);
67
+ const active = $derived(ctx.activeIndex === index);
68
+
69
+ // Two thumbs with the same name are two sliders the screen reader cannot tell apart. A range
70
+ // of two gets "Minimum" and "Maximum" when the consumer gives no name of its own.
71
+ const defaultLabel = $derived.by(() => {
72
+ if (ctx.values.length !== 2) return undefined;
73
+ return resolveLocalizedString($localeStore, index === 0 ? 'slider.minimum' : 'slider.maximum');
74
+ });
75
+ const ownLabel = $derived(ariaLabel ?? (ariaLabelledBy ? undefined : defaultLabel));
76
+ const ownLabelSource = $derived(ariaLabelledBy ?? (ownLabel ? inputId : null));
77
+ // The name of the group: the label, the ids the consumer gave, or the root element itself
78
+ // when it carries an `aria-label`.
79
+ const groupLabelSource = $derived(
80
+ ctx.ariaLabelledBy ?? ctx.labelId ?? (ctx.ariaLabel ? ctx.rootId : null)
81
+ );
82
+ const inputAriaLabel = $derived(
83
+ ownLabel ?? (groupLabelSource === ctx.rootId ? ctx.ariaLabel : undefined)
84
+ );
85
+ const inputLabelledBy = $derived.by(() => {
86
+ if (!ownLabelSource) {
87
+ return groupLabelSource && groupLabelSource !== ctx.rootId ? groupLabelSource : undefined;
88
+ }
89
+ return groupLabelSource ? `${ownLabelSource} ${groupLabelSource}` : ownLabelSource;
90
+ });
91
+
92
+ // The native input keeps the value: a screen reader reads it from there, and a form sends it.
93
+ $effect(() => {
94
+ if (!inputRef) return;
95
+ const nextValue = String(value);
96
+ if (inputRef.value !== nextValue) inputRef.value = nextValue;
97
+ });
98
+
99
+ // The focus ring must appear when a pointer press is followed by a key press, and the
100
+ // modality alone changes there: no focus event fires to re-read it.
101
+ watchFocusVisible({
102
+ isFocused: () => focused,
103
+ element: () => inputRef,
104
+ set: (visible) => ctx.setFocusVisible(visible)
105
+ });
106
+
107
+ const positionStyle = $derived.by(() => {
108
+ if (ctx.orientation === 'vertical') {
109
+ return `position: absolute; bottom: ${percent}%; left: 50%; translate: -50% 50%;`;
110
+ }
111
+ // A physical `left`, because the `translate` that centers the thumb is physical too.
112
+ const left = ctx.isRtl ? 100 - percent : percent;
113
+ return `position: absolute; left: ${left}%; top: 50%; translate: -50% -50%;`;
114
+ });
115
+ // The thumb the user touched last draws above the others: two thumbs at the same value
116
+ // would hide the one that just moved.
117
+ const resolvedStyle = $derived(
118
+ `${positionStyle} touch-action: none;${active ? ' z-index: 1;' : ''}${style ? ` ${style}` : ''}`
119
+ );
120
+
121
+ // The keyboard reports `onChange` on each key press, and `onChangeEnd` one time at the
122
+ // release, thus a held key does not report an end on each repeat.
123
+ let keyboardChanged = false;
124
+
125
+ function commitKeyboard(event: Event) {
126
+ if (!keyboardChanged) return;
127
+ keyboardChanged = false;
128
+ ctx.commitValue({ reason: 'keyboard', index, event });
129
+ }
130
+
131
+ function handleKeyDown(event: KeyboardEvent) {
132
+ if (event.defaultPrevented) return;
133
+ if (event.ctrlKey || event.metaKey || event.altKey) return;
134
+
135
+ const horizontal = ctx.orientation === 'horizontal';
136
+ const rtl = horizontal && isRtl(thumbRef);
137
+ let direction: -1 | 1 | null = null;
138
+ let large = event.shiftKey;
139
+ let absolute: number | null = null;
140
+
141
+ switch (event.key) {
142
+ case 'ArrowRight':
143
+ direction = rtl ? -1 : 1;
144
+ break;
145
+ case 'ArrowLeft':
146
+ direction = rtl ? 1 : -1;
147
+ break;
148
+ case 'ArrowUp':
149
+ direction = 1;
150
+ break;
151
+ case 'ArrowDown':
152
+ direction = -1;
153
+ break;
154
+ case 'PageUp':
155
+ direction = 1;
156
+ large = true;
157
+ break;
158
+ case 'PageDown':
159
+ direction = -1;
160
+ large = true;
161
+ break;
162
+ case 'Home':
163
+ absolute = ctx.min;
164
+ break;
165
+ case 'End':
166
+ absolute = ctx.max;
167
+ break;
168
+ default:
169
+ return;
170
+ }
171
+
172
+ // The native input would step on its own, in its own amounts.
173
+ event.preventDefault();
174
+ trackInteractionModality(event, inputRef);
175
+ if (focused) ctx.setFocusVisible(true);
176
+ if (ctx.isReadOnly) return;
177
+
178
+ if (absolute !== null) {
179
+ if (ctx.setValueAt(index, absolute, { reason: 'keyboard', index, event })) {
180
+ keyboardChanged = true;
181
+ }
182
+ return;
183
+ }
184
+ if (direction !== null && ctx.stepValueAt(index, direction, { large, event })) {
185
+ keyboardChanged = true;
186
+ }
187
+ }
188
+
189
+ function handleKeyUp(event: KeyboardEvent) {
190
+ commitKeyboard(event);
191
+ }
192
+
193
+ // A change that did not come through the keyboard handler: a mobile screen reader swipe, or
194
+ // a browser feature that writes the native input.
195
+ function handleInput(event: Event) {
196
+ if (!inputRef) return;
197
+ const nextValue = Number(inputRef.value);
198
+ if (Number.isFinite(nextValue) && nextValue !== value && !ctx.isReadOnly) {
199
+ const details: SliderChangeDetails = { reason: 'input', index, event };
200
+ if (ctx.setValueAt(index, nextValue, details)) ctx.commitValue(details);
201
+ }
202
+ // Re-sync when the change was refused, or clamped by a neighbor.
203
+ inputRef.value = String(ctx.values[index] ?? ctx.min);
204
+ }
205
+
206
+ function handleFocus() {
207
+ ctx.setThumbFocus(index, true);
208
+ ctx.setFocusVisible(shouldShowFocusVisible(inputRef));
209
+ }
210
+
211
+ function handleBlur(event: FocusEvent) {
212
+ // A key still held when the focus leaves has no release to wait for.
213
+ commitKeyboard(event);
214
+ ctx.setThumbFocus(index, false);
215
+ }
216
+
217
+ function handlePointerDown(
218
+ event: PointerEvent & { currentTarget: EventTarget & HTMLDivElement }
219
+ ) {
220
+ onpointerdown?.(event);
221
+ if (event.defaultPrevented) return;
222
+ // The thumb keeps its value at the press; only a move changes it.
223
+ ctx.startDrag(event, index);
224
+ }
225
+
226
+ const renderState = $derived<SliderThumbRenderState>({ value, text, index, dragging, focused });
227
+ </script>
228
+
229
+ <div
230
+ {...restProps}
231
+ bind:this={thumbRef}
232
+ class={className}
233
+ style={resolvedStyle}
234
+ data-slider-thumb="true"
235
+ data-index={index}
236
+ data-orientation={ctx.orientation}
237
+ data-disabled={ctx.isDisabled || undefined}
238
+ data-readonly={ctx.isReadOnly || undefined}
239
+ data-invalid={ctx.isInvalid || undefined}
240
+ data-dragging={dragging || undefined}
241
+ data-focused={focused || undefined}
242
+ data-focus-visible={focusVisible || undefined}
243
+ onpointerdown={handlePointerDown}
244
+ >
245
+ <input
246
+ bind:this={inputRef}
247
+ type="range"
248
+ id={inputId}
249
+ name={name ?? ctx.name}
250
+ form={ctx.form}
251
+ min={ctx.min}
252
+ max={ctx.max}
253
+ step={ctx.step}
254
+ value={String(value)}
255
+ disabled={ctx.isDisabled}
256
+ aria-orientation={ctx.orientation}
257
+ aria-valuenow={value}
258
+ aria-valuetext={valueText}
259
+ aria-label={inputAriaLabel}
260
+ aria-labelledby={inputLabelledBy}
261
+ aria-describedby={ctx.ariaDescribedBy}
262
+ aria-readonly={ctx.isReadOnly || undefined}
263
+ aria-invalid={ctx.isInvalid || undefined}
264
+ data-slider-input="true"
265
+ data-index={index}
266
+ style="position:absolute;inset:0;width:100%;height:100%;margin:0;padding:0;border:0;opacity:0;cursor:inherit;pointer-events:none;"
267
+ onkeydown={handleKeyDown}
268
+ onkeyup={handleKeyUp}
269
+ oninput={handleInput}
270
+ onfocus={handleFocus}
271
+ onblur={handleBlur}
272
+ />
273
+ {#if children}
274
+ {@render (children as Snippet<[SliderThumbRenderState]>)(renderState)}
275
+ {/if}
276
+ </div>
@@ -0,0 +1,4 @@
1
+ import type { SliderThumbProps } from '../types';
2
+ declare const SliderThumb: import("svelte").Component<SliderThumbProps, {}, "element">;
3
+ type SliderThumb = ReturnType<typeof SliderThumb>;
4
+ export default SliderThumb;
@@ -0,0 +1,60 @@
1
+ <script lang="ts">
2
+ import { useSliderContext } from '../root/context';
3
+ import type { SliderTrackProps } from '../types';
4
+
5
+ /**
6
+ * Slider.Track — the rail, and the surface of the pointer.
7
+ *
8
+ * A press on it moves the nearest thumb to the pointer and starts a drag. The thumbs sit in
9
+ * it, positioned along it in percent of the value. It is `position: relative` for that, and
10
+ * `touch-action: none` so that a touch drag moves the thumb and not the page.
11
+ */
12
+ let {
13
+ children,
14
+ class: className = '',
15
+ element = $bindable<HTMLDivElement | null>(null),
16
+ style,
17
+ onpointerdown,
18
+ ...restProps
19
+ }: SliderTrackProps = $props();
20
+
21
+ const ctx = useSliderContext('Slider.Track');
22
+ let trackRef: HTMLDivElement | null = $state(null);
23
+
24
+ $effect(() => {
25
+ element = trackRef;
26
+ ctx.setTrackRef(trackRef);
27
+ return () => {
28
+ ctx.setTrackRef(null);
29
+ };
30
+ });
31
+
32
+ // The consumer style comes last, thus it can replace the two defaults.
33
+ const resolvedStyle = $derived(
34
+ `position: relative; touch-action: none;${style ? ` ${style}` : ''}`
35
+ );
36
+
37
+ function handlePointerDown(
38
+ event: PointerEvent & { currentTarget: EventTarget & HTMLDivElement }
39
+ ) {
40
+ onpointerdown?.(event);
41
+ if (event.defaultPrevented) return;
42
+ ctx.startDrag(event);
43
+ }
44
+ </script>
45
+
46
+ <div
47
+ {...restProps}
48
+ bind:this={trackRef}
49
+ class={className}
50
+ style={resolvedStyle}
51
+ data-slider-track="true"
52
+ data-orientation={ctx.orientation}
53
+ data-disabled={ctx.isDisabled || undefined}
54
+ data-readonly={ctx.isReadOnly || undefined}
55
+ data-invalid={ctx.isInvalid || undefined}
56
+ data-dragging={ctx.draggingIndex !== null || undefined}
57
+ onpointerdown={handlePointerDown}
58
+ >
59
+ {@render children?.()}
60
+ </div>
@@ -0,0 +1,4 @@
1
+ import type { SliderTrackProps } from '../types';
2
+ declare const SliderTrack: import("svelte").Component<SliderTrackProps, {}, "element">;
3
+ type SliderTrack = ReturnType<typeof SliderTrack>;
4
+ export default SliderTrack;
@@ -0,0 +1,144 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { HTMLAttributes } from 'svelte/elements';
3
+ import type { SliderChangeDetails, SliderContext, SliderOrientation } from './root/context';
4
+ export type { SliderChangeDetails, SliderOrientation };
5
+ export type SliderValue = number | number[];
6
+ export type SliderRootProps = {
7
+ /** A stable id, from which the component makes its internal ARIA ids. Give one on a server. */
8
+ id?: string;
9
+ /**
10
+ * The value: one number for one thumb, and an array in ascending order for a range with more
11
+ * thumbs. You can bind it with `bind:value`.
12
+ */
13
+ value?: SliderValue;
14
+ /** The value at the start, for when you give no `value`. The default is `min`. */
15
+ defaultValue?: SliderValue;
16
+ /**
17
+ * Give your own code full control of the value. The component stops to write back to `value`,
18
+ * and it reports only through `onChange`. Thus the parent can refuse a change: the parent does
19
+ * not send the new value down. The default is off, because `bind:value` is the usual case and
20
+ * it needs the write-back.
21
+ */
22
+ controlledValue?: boolean;
23
+ /** The component calls it on each change, also on each move of a drag. */
24
+ onChange?: (value: SliderValue, details: SliderChangeDetails) => void;
25
+ /**
26
+ * The component calls it when a sequence of changes ends: at the release of a key, and at the
27
+ * end of a drag. A change from assistive technology ends at once. Use it for work that must
28
+ * not run on each move.
29
+ */
30
+ onChangeEnd?: (value: SliderValue, details: SliderChangeDetails) => void;
31
+ /** The lowest value. The default is 0. */
32
+ min?: number;
33
+ /** The highest value. The default is 100. */
34
+ max?: number;
35
+ /** The distance between two values. The default is 1. */
36
+ step?: number;
37
+ /**
38
+ * The distance of `PageUp`, `PageDown` and `Shift+Arrow`. The default is one tenth of the
39
+ * range, and never less than one step.
40
+ */
41
+ largeStep?: number;
42
+ /** The steps that two thumbs of a range keep between them. The default is 0: they can meet. */
43
+ minStepsBetweenThumbs?: number;
44
+ /** The direction of the track. The default is horizontal. */
45
+ orientation?: SliderOrientation;
46
+ /** Disables the slider. The native inputs are disabled, and the thumbs leave the tab order. */
47
+ disabled?: boolean;
48
+ /** Keeps the thumbs in the tab order, but the value does not change. */
49
+ readonly?: boolean;
50
+ /** Marks the value as invalid. The thumbs get `aria-invalid`. */
51
+ invalid?: boolean;
52
+ /** The name of the native inputs. A `Slider.Thumb` can give its own. */
53
+ name?: string;
54
+ /** The id of the form that the native inputs belong to, when the slider is outside it. */
55
+ form?: string;
56
+ /** The format of the value in `Slider.Output` and in the text that a screen reader reads. */
57
+ formatOptions?: Intl.NumberFormatOptions;
58
+ /**
59
+ * The text that a screen reader reads for a value, in place of the formatted number. The
60
+ * second argument is the index of the thumb.
61
+ */
62
+ getValueText?: (value: number, index: number) => string;
63
+ /** The accessible name of the slider, for when there is no `Slider.Label`. */
64
+ 'aria-label'?: string;
65
+ /** The id of the element that gives the slider its name, in place of `Slider.Label`. */
66
+ 'aria-labelledby'?: string;
67
+ /** The id of the element that describes the slider, for example an error message. */
68
+ 'aria-describedby'?: string;
69
+ /** The content: the label, the output and the track. */
70
+ children?: Snippet;
71
+ /** The CSS class names of the root element. */
72
+ class?: string;
73
+ /** A bindable reference to the root element. */
74
+ element?: HTMLDivElement | null;
75
+ /** A bindable reference to the context, for a composition of your own. */
76
+ context?: SliderContext;
77
+ } & Omit<HTMLAttributes<HTMLDivElement>, 'class' | 'children' | 'id' | 'role' | 'aria-label' | 'aria-labelledby' | 'aria-describedby' | 'onchange'>;
78
+ export type SliderLabelProps = Omit<HTMLAttributes<HTMLSpanElement>, 'class'> & {
79
+ /** The CSS class names of the label. */
80
+ class?: string;
81
+ };
82
+ export type SliderOutputRenderState = {
83
+ /** The values, one per thumb. */
84
+ values: number[];
85
+ /** The text of each value, in the locale and the `formatOptions`. */
86
+ texts: string[];
87
+ /** The text of the whole value: one number, or a range in the locale. */
88
+ text: string;
89
+ };
90
+ export type SliderOutputProps = Omit<HTMLAttributes<HTMLOutputElement>, 'class' | 'children'> & {
91
+ /**
92
+ * The content. As a snippet with one argument, it receives the render state: `values`, `texts`
93
+ * and `text`. Without it, the component shows `text`.
94
+ */
95
+ children?: Snippet<[SliderOutputRenderState]>;
96
+ /** The CSS class names of the element. */
97
+ class?: string;
98
+ };
99
+ export type SliderTrackProps = Omit<HTMLAttributes<HTMLDivElement>, 'class'> & {
100
+ /** The CSS class names of the track. */
101
+ class?: string;
102
+ /** A bindable reference to the track element. */
103
+ element?: HTMLDivElement | null;
104
+ };
105
+ export type SliderFillProps = Omit<HTMLAttributes<HTMLDivElement>, 'class'> & {
106
+ /** The CSS class names of the fill. */
107
+ class?: string;
108
+ };
109
+ export type SliderThumbRenderState = {
110
+ /** The value of the thumb. */
111
+ value: number;
112
+ /** The text of the value. */
113
+ text: string;
114
+ /** The index of the thumb. */
115
+ index: number;
116
+ /** Whether the thumb is under a pointer drag. */
117
+ dragging: boolean;
118
+ /** Whether the native input of the thumb has the focus. */
119
+ focused: boolean;
120
+ };
121
+ export type SliderThumbProps = Omit<HTMLAttributes<HTMLDivElement>, 'class' | 'children' | 'aria-label' | 'aria-labelledby'> & {
122
+ /**
123
+ * The index of the thumb, for a range. Without it, the thumbs take the indexes in mount order.
124
+ */
125
+ index?: number;
126
+ /** The `name` of the native input of this thumb. It replaces the `name` of the root. */
127
+ name?: string;
128
+ /**
129
+ * The name of this thumb, before the name of the slider. A range of two thumbs without one
130
+ * gets "Minimum" and "Maximum" in the locale.
131
+ */
132
+ 'aria-label'?: string;
133
+ /** The id of the element that names this thumb, in place of `aria-label`. */
134
+ 'aria-labelledby'?: string;
135
+ /**
136
+ * The content. As a snippet with one argument, it receives the render state: `value`, `text`,
137
+ * `index`, `dragging` and `focused`.
138
+ */
139
+ children?: Snippet<[SliderThumbRenderState]> | Snippet;
140
+ /** The CSS class names of the thumb. */
141
+ class?: string;
142
+ /** A bindable reference to the thumb element. */
143
+ element?: HTMLDivElement | null;
144
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -5,6 +5,7 @@
5
5
  shouldShowFocusVisible,
6
6
  trackInteractionModality
7
7
  } from '../../primitives/input-modality';
8
+ import { watchFocusVisible } from '../../primitives/focus-visible.svelte';
8
9
  import { setSwitchContext, type SwitchContext } from './context';
9
10
 
10
11
  type SwitchRootProps = Omit<
@@ -136,6 +137,14 @@
136
137
  let pressedKey: 'Enter' | 'Space' | null = $state(null);
137
138
  let focused = $state(false);
138
139
  let focusVisible = $state(false);
140
+
141
+ // The focus ring must appear when a pointer press is followed by a key press, and the
142
+ // modality alone changes there — no focus event fires to re-read it.
143
+ watchFocusVisible({
144
+ isFocused: () => focused,
145
+ element: () => rootRef,
146
+ set: (visible) => (focusVisible = visible)
147
+ });
139
148
  let rootRef: HTMLSpanElement | null = $state(null);
140
149
  let inputRef: HTMLInputElement | null = $state(null);
141
150
 
@@ -11,6 +11,8 @@
11
11
  shouldShowFocusVisible,
12
12
  trackInteractionModality
13
13
  } from '../../primitives/input-modality';
14
+
15
+ import { watchFocusVisible } from '../../primitives/focus-visible.svelte';
14
16
  import { isRtl } from '../../internal/rtl';
15
17
 
16
18
  let { children, class: className = '', ...restProps }: TableColumnHeaderCellProps = $props();
@@ -174,6 +176,28 @@
174
176
  isFocusVisibleWithin = false;
175
177
  }
176
178
 
179
+ function getFocusedDescendant() {
180
+ if (!element) return null;
181
+ const active = element.ownerDocument.activeElement;
182
+ if (!(active instanceof HTMLElement) || active === element) return null;
183
+ return element.contains(active) ? active : null;
184
+ }
185
+
186
+ watchFocusVisible({
187
+ isFocused: () => isElementFocused,
188
+ element: () => element ?? null,
189
+ set: (visible) => {
190
+ isElementFocusVisible = visible;
191
+ table.setFocusVisible(visible);
192
+ }
193
+ });
194
+
195
+ watchFocusVisible({
196
+ isFocused: () => isFocusWithin,
197
+ element: getFocusedDescendant,
198
+ set: (visible) => (isFocusVisibleWithin = visible)
199
+ });
200
+
177
201
  function handleClick() {
178
202
  // A drag-resize that just ended emits a residual click on the header;
179
203
  // consume the one-shot suppression flag BEFORE focusing the cell.
@@ -21,6 +21,7 @@
21
21
  shouldShowFocusVisible,
22
22
  trackInteractionModality
23
23
  } from '../../primitives/input-modality';
24
+ import { watchFocusVisible } from '../../primitives/focus-visible.svelte';
24
25
  import { visuallyHiddenStyle } from '../utils/visually-hidden-style';
25
26
  import type { TableRootProps } from '../types.js';
26
27
  import {
@@ -499,30 +500,52 @@
499
500
  focusWithin =
500
501
  !!tableElement && !!document.activeElement && tableElement.contains(document.activeElement);
501
502
  if (!focusWithin) {
502
- focusVisible = false;
503
+ setFocusVisible(false);
503
504
  ctx.setFocusedCell(null);
504
505
  }
505
506
  }
506
507
 
507
508
  function handleFocusIn(event: FocusEvent) {
508
509
  focusWithin = true;
509
- focusVisible = shouldShowFocusVisible(event.target as HTMLElement | null);
510
+ setFocusVisible(shouldShowFocusVisible(event.target as HTMLElement | null));
510
511
  }
511
512
 
513
+ // Every part of the table reads one focus-visible value, and each writes it from its own
514
+ // focus handler. One watch on the focused descendant therefore serves them all: a key press
515
+ // that follows a pointer press brings the ring back on the cell, the row and the checkbox
516
+ // at once.
517
+ function getFocusedDescendant() {
518
+ if (!tableElement) return null;
519
+ const active = tableElement.ownerDocument.activeElement;
520
+ if (!(active instanceof HTMLElement)) return null;
521
+ return tableElement.contains(active) ? active : null;
522
+ }
523
+
524
+ function setFocusVisible(visible: boolean) {
525
+ focusVisible = visible;
526
+ ctx.setFocusVisible(visible);
527
+ }
528
+
529
+ watchFocusVisible({
530
+ isFocused: () => focusWithin,
531
+ element: getFocusedDescendant,
532
+ set: setFocusVisible
533
+ });
534
+
512
535
  function handleFocusOut() {
513
536
  queueMicrotask(syncFocusWithin);
514
537
  }
515
538
 
516
539
  function handleMouseDown(event: MouseEvent) {
517
540
  trackInteractionModality(event, event.target as HTMLElement | null);
518
- focusVisible = false;
541
+ setFocusVisible(false);
519
542
  }
520
543
 
544
+ // No focus-visible write here: `trackInteractionModality` reports the key to the modality,
545
+ // and the watch above answers. A key that carries a modifier is not a modality change, and
546
+ // must leave the ring as the pointer left it.
521
547
  function handleKeyDown(event: KeyboardEvent) {
522
548
  trackInteractionModality(event, event.target as HTMLElement | null);
523
- if (focusWithin) {
524
- focusVisible = true;
525
- }
526
549
  }
527
550
  </script>
528
551
 
@@ -14,17 +14,25 @@
14
14
  HTMLAttributes<HTMLDivElement>,
15
15
  'children' | 'class' | 'id' | 'role' | 'tabindex' | 'aria-invalid'
16
16
  > & {
17
+ /**
18
+ * The id of the hidden proxy input. A `<label for>` points to it, and the segmented group
19
+ * then takes a derived id.
20
+ */
17
21
  id?: string;
18
22
  /**
19
- * Name of the hidden proxy input used for form submission. The proxy only
20
- * mirrors the committed value: autofill is NOT supported (it renders with
21
- * `autocomplete="off"` so browsers and password managers do not write
22
- * into it) — times are entered through the editable segments.
23
+ * Name of the hidden proxy input for form submission. The proxy shows only the committed
24
+ * value. It does not support autofill: it renders with `autocomplete="off"`, thus browsers
25
+ * and password managers do not write into it. The user gives the time through the editable
26
+ * segments.
23
27
  */
24
28
  name?: string;
25
29
  children?: Snippet<[TimePickerSegmentPart]>;
26
30
  class?: string;
27
31
  'aria-label'?: string;
32
+ /**
33
+ * Marks the input as invalid. The group is also invalid while a segment draft is not
34
+ * committable.
35
+ */
28
36
  'aria-invalid'?: HTMLAttributes<HTMLDivElement>['aria-invalid'];
29
37
  };
30
38
 
@@ -2,17 +2,25 @@ import type { Snippet } from 'svelte';
2
2
  import type { HTMLAttributes } from 'svelte/elements';
3
3
  import { type TimePickerSegmentPart } from '../root/context';
4
4
  type TimePickerInputProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class' | 'id' | 'role' | 'tabindex' | 'aria-invalid'> & {
5
+ /**
6
+ * The id of the hidden proxy input. A `<label for>` points to it, and the segmented group
7
+ * then takes a derived id.
8
+ */
5
9
  id?: string;
6
10
  /**
7
- * Name of the hidden proxy input used for form submission. The proxy only
8
- * mirrors the committed value: autofill is NOT supported (it renders with
9
- * `autocomplete="off"` so browsers and password managers do not write
10
- * into it) — times are entered through the editable segments.
11
+ * Name of the hidden proxy input for form submission. The proxy shows only the committed
12
+ * value. It does not support autofill: it renders with `autocomplete="off"`, thus browsers
13
+ * and password managers do not write into it. The user gives the time through the editable
14
+ * segments.
11
15
  */
12
16
  name?: string;
13
17
  children?: Snippet<[TimePickerSegmentPart]>;
14
18
  class?: string;
15
19
  'aria-label'?: string;
20
+ /**
21
+ * Marks the input as invalid. The group is also invalid while a segment draft is not
22
+ * committable.
23
+ */
16
24
  'aria-invalid'?: HTMLAttributes<HTMLDivElement>['aria-invalid'];
17
25
  };
18
26
  declare const TimePickerInput: import("svelte").Component<TimePickerInputProps, {}, "">;