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

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 (59) hide show
  1. package/dist/autocomplete/item/autocomplete-item.svelte +10 -0
  2. package/dist/button/root/button-root.svelte +9 -0
  3. package/dist/calendar/body-cell/calendar-body-cell.svelte +7 -0
  4. package/dist/checkbox/indicator/checkbox-indicator.svelte +1 -0
  5. package/dist/checkbox/indicator/checkbox-indicator.svelte.d.ts +1 -0
  6. package/dist/checkbox/root/checkbox-root.svelte +106 -30
  7. package/dist/checkbox/root/checkbox-root.svelte.d.ts +5 -0
  8. package/dist/checkbox-group/README.md +95 -0
  9. package/dist/checkbox-group/index.d.ts +15 -0
  10. package/dist/checkbox-group/index.js +6 -0
  11. package/dist/checkbox-group/index.parts.d.ts +4 -0
  12. package/dist/checkbox-group/index.parts.js +7 -0
  13. package/dist/checkbox-group/label/checkbox-group-label.svelte +36 -0
  14. package/dist/checkbox-group/label/checkbox-group-label.svelte.d.ts +4 -0
  15. package/dist/checkbox-group/root/checkbox-group-root.svelte +118 -0
  16. package/dist/checkbox-group/root/checkbox-group-root.svelte.d.ts +4 -0
  17. package/dist/checkbox-group/root/context.svelte.d.ts +52 -0
  18. package/dist/checkbox-group/root/context.svelte.js +251 -0
  19. package/dist/checkbox-group/types.d.ts +57 -0
  20. package/dist/checkbox-group/types.js +1 -0
  21. package/dist/index.d.ts +4 -0
  22. package/dist/index.js +4 -0
  23. package/dist/primitives/focus-visible.svelte.d.ts +14 -0
  24. package/dist/primitives/focus-visible.svelte.js +19 -0
  25. package/dist/primitives/index.d.ts +1 -0
  26. package/dist/primitives/index.js +1 -0
  27. package/dist/primitives/input-modality.d.ts +7 -0
  28. package/dist/primitives/input-modality.js +32 -5
  29. package/dist/radio-group/README.md +103 -0
  30. package/dist/radio-group/index.d.ts +18 -0
  31. package/dist/radio-group/index.js +9 -0
  32. package/dist/radio-group/index.parts.d.ts +4 -0
  33. package/dist/radio-group/index.parts.js +4 -0
  34. package/dist/radio-group/indicator/radio-group-indicator.svelte +43 -0
  35. package/dist/radio-group/indicator/radio-group-indicator.svelte.d.ts +12 -0
  36. package/dist/radio-group/item/context.d.ts +18 -0
  37. package/dist/radio-group/item/context.js +15 -0
  38. package/dist/radio-group/item/radio-group-item.svelte +377 -0
  39. package/dist/radio-group/item/radio-group-item.svelte.d.ts +35 -0
  40. package/dist/radio-group/label/radio-group-label.svelte +37 -0
  41. package/dist/radio-group/label/radio-group-label.svelte.d.ts +4 -0
  42. package/dist/radio-group/root/context.svelte.d.ts +57 -0
  43. package/dist/radio-group/root/context.svelte.js +284 -0
  44. package/dist/radio-group/root/radio-group-root.svelte +193 -0
  45. package/dist/radio-group/root/radio-group-root.svelte.d.ts +4 -0
  46. package/dist/radio-group/types.d.ts +50 -0
  47. package/dist/radio-group/types.js +1 -0
  48. package/dist/switch/root/switch-root.svelte +9 -0
  49. package/dist/table/column-header-cell/table-column-header-cell.svelte +24 -0
  50. package/dist/table/root/table-root.svelte +29 -6
  51. package/dist/timepicker/input/time-picker-input.svelte +12 -4
  52. package/dist/timepicker/input/time-picker-input.svelte.d.ts +12 -4
  53. package/dist/toggle/root/toggle-root.svelte +28 -0
  54. package/dist/toggle/root/toggle-root.svelte.d.ts +19 -0
  55. package/dist/toggle-group/README.md +6 -4
  56. package/dist/toggle-group/index.d.ts +2 -0
  57. package/dist/toggle-group/index.parts.d.ts +1 -0
  58. package/dist/toggle-group/index.parts.js +4 -0
  59. package/package.json +11 -1
@@ -112,6 +112,15 @@
112
112
  if (isVisibleRegistered) ctx.unregisterVisibleItem(id);
113
113
  });
114
114
 
115
+ function handleHoverStart(itemId: string | number) {
116
+ // The pointer takes the virtual focus, the same as in a ComboBox. Without
117
+ // this the keys move one row and the pointer marks another, and both read
118
+ // as the current one at the same time — which the item cannot correct on
119
+ // its own, because it only sees its own attributes.
120
+ ctx.setFocusVisible(false);
121
+ ctx.setFocusedItemId(itemId);
122
+ }
123
+
115
124
  function handleSelect(itemId: string | number) {
116
125
  if (ctx.isReadOnly) return;
117
126
  // Selection here is pointer-driven (click); clear the keyboard focus ring.
@@ -136,6 +145,7 @@
136
145
  isFocusVisibleOverride={isFocusVisible}
137
146
  onItemSelect={handleSelect}
138
147
  onResolvedTextValue={handleResolvedTextValue}
148
+ onItemHoverStart={handleHoverStart}
139
149
  scrollOnFocus={true}
140
150
  isParentDisabled={ctx.isDisabled}
141
151
  />
@@ -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 { cn } from '../../utils/cn';
9
10
 
10
11
  export type ButtonRenderState = {
@@ -120,6 +121,14 @@
120
121
  let pressed = $state(false);
121
122
  let focused = $state(false);
122
123
  let focusVisible = $state(false);
124
+
125
+ // The focus ring must appear when a pointer press is followed by a key press, and the
126
+ // modality alone changes there — no focus event fires to re-read it.
127
+ watchFocusVisible({
128
+ isFocused: () => focused,
129
+ element: () => buttonRef,
130
+ set: (visible) => (focusVisible = visible)
131
+ });
123
132
  let pressedKey: 'Enter' | 'Space' | null = $state(null);
124
133
  let expandedPressed = $state(false);
125
134
 
@@ -58,6 +58,7 @@
58
58
  shouldShowFocusVisible,
59
59
  trackInteractionModality
60
60
  } from '../../primitives/input-modality';
61
+ import { watchFocusVisible } from '../../primitives/focus-visible.svelte';
61
62
 
62
63
  type CalendarBodyCellProps = Omit<HTMLAttributes<HTMLTableCellElement>, 'children'> & {
63
64
  date: string;
@@ -154,6 +155,12 @@
154
155
  calendar.setFocusVisible(shouldShowFocusVisible(buttonElement ?? null));
155
156
  }
156
157
 
158
+ watchFocusVisible({
159
+ isFocused: () => hasDomFocus,
160
+ element: () => buttonElement ?? null,
161
+ set: (visible) => calendar.setFocusVisible(visible)
162
+ });
163
+
157
164
  function handleBlur() {
158
165
  hasDomFocus = false;
159
166
  isHovered = false;
@@ -4,6 +4,7 @@
4
4
  import { useCheckboxContext } from '../root/context';
5
5
 
6
6
  type CheckboxIndicatorProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children' | 'class'> & {
7
+ /** Keeps the indicator in the DOM even while the checkbox is unchecked. */
7
8
  forceMount?: boolean;
8
9
  children?: Snippet;
9
10
  class?: string;
@@ -1,6 +1,7 @@
1
1
  import type { HTMLAttributes } from 'svelte/elements';
2
2
  import type { Snippet } from 'svelte';
3
3
  type CheckboxIndicatorProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children' | 'class'> & {
4
+ /** Keeps the indicator in the DOM even while the checkbox is unchecked. */
4
5
  forceMount?: boolean;
5
6
  children?: Snippet;
6
7
  class?: string;
@@ -1,10 +1,12 @@
1
1
  <script lang="ts">
2
- import { untrack, type Snippet } from 'svelte';
2
+ import { onDestroy, untrack, type Snippet } from 'svelte';
3
3
  import type { HTMLAttributes } from 'svelte/elements';
4
4
  import {
5
5
  shouldShowFocusVisible,
6
6
  trackInteractionModality
7
7
  } from '../../primitives/input-modality';
8
+ import { watchFocusVisible } from '../../primitives/focus-visible.svelte';
9
+ import { getCheckboxGroupContext } from '../../checkbox-group/root/context.svelte';
8
10
  import { setCheckboxContext, type CheckboxContext, type CheckboxState } from './context';
9
11
 
10
12
  type CheckboxRootProps = Omit<
@@ -46,15 +48,20 @@
46
48
  defaultIndeterminate?: boolean;
47
49
  /** Give your own code full control of `indeterminate`. Read `controlledChecked`. */
48
50
  controlledIndeterminate?: boolean;
51
+ /** The component calls it when the user changes the checked state. */
49
52
  onCheckedChange?: (checked: boolean) => void;
53
+ /** The component calls it when the user changes the indeterminate state. From the indeterminate state, the first user action makes the checkbox checked. */
50
54
  onIndeterminateChange?: (indeterminate: boolean) => void;
51
55
  disabled?: boolean;
52
56
  readonly?: boolean;
53
57
  required?: boolean;
54
58
  children?: Snippet;
55
59
  class?: string;
60
+ /** The accessible name, for when the user sees no name. */
56
61
  'aria-label'?: string;
62
+ /** The id of the element that gives the checkbox its name. */
57
63
  'aria-labelledby'?: string;
64
+ /** Replaces the default position in the tab order. */
58
65
  tabindex?: number;
59
66
  onclick?: HTMLAttributes<HTMLSpanElement>['onclick'];
60
67
  onkeydown?: HTMLAttributes<HTMLSpanElement>['onkeydown'];
@@ -138,6 +145,13 @@
138
145
  const inputId = instanceId;
139
146
  const rootId = `${instanceId}-root`;
140
147
 
148
+ // Inside a `CheckboxGroup.Root` the group owns the checked state, and this checkbox becomes
149
+ // one entry of its `value` array. Outside one the context is undefined and every path below
150
+ // keeps the standalone behavior.
151
+ const checkboxGroup = getCheckboxGroupContext();
152
+ const registrationOwner = Symbol('checkbox-root');
153
+ let registeredValue = untrack(() => value);
154
+
141
155
  const initialChecked = untrack(() => checked ?? defaultChecked);
142
156
  const initialIndeterminate = untrack(() => indeterminate ?? defaultIndeterminate);
143
157
  const initialState = resolveState(initialChecked, initialIndeterminate);
@@ -151,6 +165,35 @@
151
165
  let rootRef: HTMLSpanElement | null = $state(null);
152
166
  let inputRef: HTMLInputElement | null = $state(null);
153
167
 
168
+ // Registered while the script runs, before the element exists, so the group knows the
169
+ // checkbox at its first render. The effect below repeats it with the element attached,
170
+ // which is what gives the group its DOM order.
171
+ untrack(() => {
172
+ checkboxGroup?.registerCheckbox(registeredValue, {
173
+ isDisabled: disabled,
174
+ owner: registrationOwner
175
+ });
176
+ });
177
+
178
+ $effect(() => {
179
+ if (!checkboxGroup) return;
180
+
181
+ if (registeredValue !== value) {
182
+ checkboxGroup.unregisterCheckbox(registeredValue);
183
+ }
184
+
185
+ registeredValue = value;
186
+ checkboxGroup.registerCheckbox(value, {
187
+ isDisabled: disabled,
188
+ element: rootRef,
189
+ owner: registrationOwner
190
+ });
191
+ });
192
+
193
+ onDestroy(() => {
194
+ checkboxGroup?.unregisterCheckbox(registeredValue);
195
+ });
196
+
154
197
  $effect(() => {
155
198
  element = rootRef;
156
199
  return () => {
@@ -158,10 +201,21 @@
158
201
  };
159
202
  });
160
203
 
204
+ // A grouped checkbox adds the disabled and read-only state of the group to its own.
205
+ // `required` is NOT among them: native `required` on a checkbox demands THAT box, so
206
+ // spreading it would turn "at least one" into "every one". The group carries that
207
+ // meaning itself, with `aria-required` on its own element.
208
+ const renderedDisabled = $derived(
209
+ checkboxGroup ? checkboxGroup.isCheckboxDisabled(value) : disabled
210
+ );
211
+ const renderedReadOnly = $derived(readonly || Boolean(checkboxGroup?.isReadOnly));
212
+ const renderedRequired = $derived(required);
213
+ const renderedName = $derived(name ?? checkboxGroup?.name);
214
+
161
215
  $effect(() => {
162
- if (!disabled && !readonly) return;
216
+ if (!renderedDisabled && !renderedReadOnly) return;
163
217
  clearPressState();
164
- if (disabled) {
218
+ if (renderedDisabled) {
165
219
  focusVisible = false;
166
220
  }
167
221
  });
@@ -171,7 +225,9 @@
171
225
  // broke every `bind:checked` seeded with `false`. It is opt-in per prop instead.
172
226
  // Write the initial state back so `bind:` parents see the resolved default. Read
173
227
  // untracked: this is a deliberate one-time seed at init, not a reactive mirror.
174
- if (!untrack(() => controlledChecked)) {
228
+ // Skipped when grouped: there the group holds the checked state, and seeding the prop would
229
+ // report a value the group never agreed to.
230
+ if (!checkboxGroup && !untrack(() => controlledChecked)) {
175
231
  checked = initialState === 'checked';
176
232
  }
177
233
 
@@ -180,10 +236,15 @@
180
236
  }
181
237
 
182
238
  // The prop wins whenever it is supplied — that covers both `bind:` and a plain
183
- // value — and the internal state only carries the fully uncontrolled case.
239
+ // value — and the internal state only carries the fully uncontrolled case. A group
240
+ // outranks all of it.
184
241
  const currentState = $derived.by(() =>
185
242
  resolveState(
186
- controlledChecked ? Boolean(checked) : (checked ?? checkedInternal),
243
+ checkboxGroup
244
+ ? checkboxGroup.isSelected(value)
245
+ : controlledChecked
246
+ ? Boolean(checked)
247
+ : (checked ?? checkedInternal),
187
248
  controlledIndeterminate ? Boolean(indeterminate) : (indeterminate ?? indeterminateInternal)
188
249
  )
189
250
  );
@@ -192,6 +253,14 @@
192
253
  const currentIndeterminate = $derived(currentState === 'indeterminate');
193
254
  const currentUnchecked = $derived(currentState === 'unchecked');
194
255
 
256
+ // The focus ring must appear when a pointer press is followed by a key press, and the modality
257
+ // alone changes there — no focus event fires to re-read it.
258
+ watchFocusVisible({
259
+ isFocused: () => focused,
260
+ element: () => rootRef,
261
+ set: (visible) => (focusVisible = visible)
262
+ });
263
+
195
264
  function clearPressState() {
196
265
  pressed = false;
197
266
  pressedKey = null;
@@ -202,8 +271,15 @@
202
271
  const nextIndeterminate = nextState === 'indeterminate';
203
272
  const previousChecked = currentChecked;
204
273
  const previousIndeterminate = currentIndeterminate;
205
-
206
- if (!controlledChecked) {
274
+ let didChangeChecked = nextChecked !== previousChecked;
275
+
276
+ if (checkboxGroup) {
277
+ // The group owns the checked state, so the standalone `checked` prop is not written
278
+ // back. The group reports the whole selection through its own `value` and `onChange`,
279
+ // and it answers whether it took the change — a group that refuses one must not make
280
+ // this checkbox announce it.
281
+ didChangeChecked = checkboxGroup.setValueSelected(value, nextChecked) !== null;
282
+ } else if (!controlledChecked) {
207
283
  checkedInternal = nextChecked;
208
284
  checked = nextChecked;
209
285
  }
@@ -213,7 +289,7 @@
213
289
  indeterminate = nextIndeterminate;
214
290
  }
215
291
 
216
- if (nextChecked !== previousChecked) {
292
+ if (didChangeChecked) {
217
293
  onCheckedChange?.(nextChecked);
218
294
  }
219
295
 
@@ -227,7 +303,7 @@
227
303
  }
228
304
 
229
305
  function setState(nextState: CheckboxState, event?: Event) {
230
- if (disabled || readonly) return;
306
+ if (renderedDisabled || renderedReadOnly) return;
231
307
  publishState(nextState, event);
232
308
  }
233
309
 
@@ -236,7 +312,7 @@
236
312
  }
237
313
 
238
314
  function requestNativeToggle(event?: Event) {
239
- if (disabled || readonly) return;
315
+ if (renderedDisabled || renderedReadOnly) return;
240
316
  if (!inputRef) {
241
317
  toggle(event);
242
318
  return;
@@ -249,7 +325,7 @@
249
325
  trackInteractionModality(event, rootRef);
250
326
 
251
327
  if (event.defaultPrevented) return;
252
- if (disabled || readonly) {
328
+ if (renderedDisabled || renderedReadOnly) {
253
329
  event.preventDefault();
254
330
  return;
255
331
  }
@@ -307,7 +383,7 @@
307
383
  trackInteractionModality(event, rootRef);
308
384
  focusVisible = false;
309
385
 
310
- if (disabled || readonly) {
386
+ if (renderedDisabled || renderedReadOnly) {
311
387
  event.preventDefault();
312
388
  clearPressState();
313
389
  return;
@@ -330,7 +406,7 @@
330
406
  }
331
407
 
332
408
  function handlePointerEnter(event: PointerEvent) {
333
- if (disabled || readonly) return;
409
+ if (renderedDisabled || renderedReadOnly) return;
334
410
 
335
411
  if ((event.buttons & 1) === 1 && pressedKey === null) {
336
412
  pressed = true;
@@ -347,7 +423,7 @@
347
423
  trackInteractionModality(event, rootRef);
348
424
  focusVisible = false;
349
425
 
350
- if (disabled || readonly) {
426
+ if (renderedDisabled || renderedReadOnly) {
351
427
  event.preventDefault();
352
428
  clearPressState();
353
429
  return;
@@ -386,7 +462,7 @@
386
462
  const target = event.currentTarget;
387
463
  if (!(target instanceof HTMLInputElement)) return;
388
464
 
389
- if (disabled || readonly) {
465
+ if (renderedDisabled || renderedReadOnly) {
390
466
  target.checked = currentChecked;
391
467
  target.indeterminate = currentIndeterminate;
392
468
  return;
@@ -459,13 +535,13 @@
459
535
  return currentIndeterminate;
460
536
  },
461
537
  get isDisabled() {
462
- return disabled;
538
+ return renderedDisabled;
463
539
  },
464
540
  get isReadOnly() {
465
- return readonly;
541
+ return renderedReadOnly;
466
542
  },
467
543
  get required() {
468
- return required;
544
+ return renderedRequired;
469
545
  },
470
546
  get focused() {
471
547
  return focused;
@@ -483,11 +559,11 @@
483
559
  bind:this={rootRef}
484
560
  id={rootId}
485
561
  role="checkbox"
486
- tabindex={disabled ? undefined : (tabindex ?? 0)}
562
+ tabindex={renderedDisabled ? undefined : (tabindex ?? 0)}
487
563
  aria-checked={currentIndeterminate ? 'mixed' : currentChecked ? 'true' : 'false'}
488
- aria-disabled={disabled || undefined}
489
- aria-readonly={readonly || undefined}
490
- aria-required={required || undefined}
564
+ aria-disabled={renderedDisabled || undefined}
565
+ aria-readonly={renderedReadOnly || undefined}
566
+ aria-required={renderedRequired || undefined}
491
567
  aria-label={ariaLabel}
492
568
  aria-labelledby={ariaLabelledby}
493
569
  data-checkbox-root="true"
@@ -495,9 +571,9 @@
495
571
  data-unchecked={currentUnchecked || undefined}
496
572
  data-indeterminate={currentIndeterminate || undefined}
497
573
  data-pressed={pressed || undefined}
498
- data-disabled={disabled || undefined}
499
- data-readonly={readonly || undefined}
500
- data-required={required || undefined}
574
+ data-disabled={renderedDisabled || undefined}
575
+ data-readonly={renderedReadOnly || undefined}
576
+ data-required={renderedRequired || undefined}
501
577
  data-focused={focused || undefined}
502
578
  data-focus-visible={focusVisible || undefined}
503
579
  onclick={composeEventHandlers(onClickExternal ?? undefined, handleClick)}
@@ -522,13 +598,13 @@
522
598
  id={inputId}
523
599
  tabindex={-1}
524
600
  type="checkbox"
525
- {name}
601
+ name={renderedName}
526
602
  {value}
527
603
  {form}
528
604
  checked={currentChecked}
529
- {disabled}
530
- {required}
531
- {readonly}
605
+ disabled={renderedDisabled}
606
+ required={renderedRequired}
607
+ readonly={renderedReadOnly}
532
608
  aria-hidden="true"
533
609
  data-checkbox-input="true"
534
610
  onclick={handleInputClick}
@@ -26,15 +26,20 @@ type CheckboxRootProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children' | 'cla
26
26
  defaultIndeterminate?: boolean;
27
27
  /** Give your own code full control of `indeterminate`. Read `controlledChecked`. */
28
28
  controlledIndeterminate?: boolean;
29
+ /** The component calls it when the user changes the checked state. */
29
30
  onCheckedChange?: (checked: boolean) => void;
31
+ /** The component calls it when the user changes the indeterminate state. From the indeterminate state, the first user action makes the checkbox checked. */
30
32
  onIndeterminateChange?: (indeterminate: boolean) => void;
31
33
  disabled?: boolean;
32
34
  readonly?: boolean;
33
35
  required?: boolean;
34
36
  children?: Snippet;
35
37
  class?: string;
38
+ /** The accessible name, for when the user sees no name. */
36
39
  'aria-label'?: string;
40
+ /** The id of the element that gives the checkbox its name. */
37
41
  'aria-labelledby'?: string;
42
+ /** Replaces the default position in the tab order. */
38
43
  tabindex?: number;
39
44
  onclick?: HTMLAttributes<HTMLSpanElement>['onclick'];
40
45
  onkeydown?: HTMLAttributes<HTMLSpanElement>['onkeydown'];
@@ -0,0 +1,95 @@
1
+ # CheckboxGroup
2
+
3
+ ## Description
4
+
5
+ `CheckboxGroup` coordinates several `Checkbox.Root` boxes as one field. It holds an array value,
6
+ and it shares a `name` for form submission. It also spreads group-wide disabled, read-only and
7
+ required state, and it reports the counts a parent "select all" checkbox needs.
8
+
9
+ ## Anatomy
10
+
11
+ - `CheckboxGroup.Root`
12
+ - `CheckboxGroup.Label`
13
+ - `CheckboxGroup.Item`
14
+ - `CheckboxGroup.Indicator`
15
+
16
+ ```svelte
17
+ <CheckboxGroup.Root name="colors" defaultValue={['red']}>
18
+ <CheckboxGroup.Label>Colors</CheckboxGroup.Label>
19
+ <Checkbox.Root value="red">
20
+ <Checkbox.Indicator>x</Checkbox.Indicator>
21
+ Red
22
+ </Checkbox.Root>
23
+ <Checkbox.Root value="green">
24
+ <Checkbox.Indicator>x</Checkbox.Indicator>
25
+ Green
26
+ </Checkbox.Root>
27
+ </CheckboxGroup.Root>
28
+ ```
29
+
30
+ ## Usage guidelines
31
+
32
+ - Use `bind:value` to hand the group your state, or plain `value` + `onChange` to own it
33
+ yourself. There is no flag to declare which: supplying `value` makes it the source of
34
+ truth either way, and `onChange` always reports.
35
+ - A parent that holds `value` and refuses a change — it sends no new value down — still sees the
36
+ group move. The group then goes back to the value of the parent at the next render. Refuse a
37
+ change with a render, and not with silence.
38
+ - Give the group a `name` to submit the checked values as one field. Each `Checkbox.Root` puts its
39
+ own `value` on a hidden input under that name, which is what a native checkbox group does.
40
+ - `CheckboxGroup.Item` is `Checkbox.Root` under the namespace of the group, and the two names
41
+ are the same component. A checkbox works on its own, thus it keeps its own name too.
42
+ - Every box in a group must provide a unique `value`. The default value of a checkbox is
43
+ `on`, so two boxes without a `value` collide and the group reports it.
44
+ - Read `allSelected` and `someSelected` from the context to drive a parent "select all" checkbox,
45
+ and call `selectAll()` or `clearAll()` from it. Keep that parent checkbox **outside** the group:
46
+ it commands the group and is not one of its values.
47
+
48
+ ## API reference
49
+
50
+ `CheckboxGroup.Root` supports:
51
+
52
+ - `value?: string[]`
53
+ - `defaultValue?: string[]`
54
+ - `onChange?: (value: string[]) => void`
55
+ - `name?: string`
56
+ - `disabled?: boolean`
57
+ - `readonly?: boolean`
58
+ - `required?: boolean`
59
+ - `orientation?: 'horizontal' | 'vertical'`
60
+ - `context?: CheckboxGroupContext`
61
+ - `children?: Snippet`
62
+ - `...restProps: HTMLAttributes<HTMLDivElement>`
63
+
64
+ ## Accessibility
65
+
66
+ - `CheckboxGroup.Root` renders `role="group"`.
67
+ - `required` gives `data-required` only. It marks no element with `aria-required`, because
68
+ `role="group"` does not support that property. It also never goes down to the boxes. Native
69
+ `required` on a checkbox demands that one box. It would thus turn "at least one" into
70
+ "every one". Put the word in the group label, and give the reason with `aria-describedby`.
71
+ - Provide an accessible group name with `CheckboxGroup.Label`, or with `aria-label` on the root for
72
+ a name the user does not see. Two labels read as one name, in the order they appear. An
73
+ `aria-labelledby` that the caller gives stands, thus an element of your own wins.
74
+ - `CheckboxGroup.Label` renders a span, and not a `<label>`: a `<label>` names one control, thus it
75
+ cannot name a set.
76
+ - The id reaches the group through the context. The server cannot do that: the group tag is
77
+ already written when the label registers. Thus `aria-labelledby` appears at hydration. Give
78
+ `aria-label` as well when the name must be there on the first paint.
79
+ - Every checkbox keeps its own tab stop, and `Space` toggles the focused one. The group adds no
80
+ arrow-key navigation. This matches the APG, React Aria and Base UI: React Aria gives each
81
+ checkbox of a group `tabindex="0"`, measured on its own live example. Arrow keys and one tab
82
+ stop for a full set belong to a radio group, which is the `radiogroup` role.
83
+
84
+ ## Notes
85
+
86
+ - Grouped checkboxes ignore their standalone `checked` and `defaultChecked` props. The group holds
87
+ the checked state and reports it through its own `value`.
88
+ - A checkbox that becomes disabled keeps its place in the value. This parts with `ToggleGroup`,
89
+ which drops a disabled selection. A checked and disabled checkbox is a state the platform
90
+ supports, and dropping it would rewrite the value a form was seeded with.
91
+ - Removing one `Checkbox.Root` from a mounted group is a real change, and the group reports the
92
+ shorter value. The removal of the full group is not a change, and it reports nothing. Without
93
+ this rule, a move to a different screen would look like the user clearing the boxes.
94
+ - Values are strings only. A grouped checkbox carries its value on a native `<input>`, which stores
95
+ it as a string. A number would thus let `value={[1]}` miss a checkbox declared as `value="1"`.
@@ -0,0 +1,15 @@
1
+ import type { ComponentProps } from 'svelte';
2
+ import type CheckboxIndicatorComponent from '../checkbox/indicator/checkbox-indicator.svelte';
3
+ import type CheckboxRootComponent from '../checkbox/root/checkbox-root.svelte';
4
+ import type CheckboxGroupLabelComponent from './label/checkbox-group-label.svelte';
5
+ import type CheckboxGroupRootComponent from './root/checkbox-group-root.svelte';
6
+ export * as CheckboxGroup from './index.parts.js';
7
+ export { default as CheckboxGroupRoot } from './root/checkbox-group-root.svelte';
8
+ export { default as CheckboxGroupLabel } from './label/checkbox-group-label.svelte';
9
+ export type CheckboxGroupRootProps = ComponentProps<typeof CheckboxGroupRootComponent>;
10
+ export type CheckboxGroupLabelProps = ComponentProps<typeof CheckboxGroupLabelComponent>;
11
+ export type CheckboxGroupItemProps = ComponentProps<typeof CheckboxRootComponent>;
12
+ export type CheckboxGroupIndicatorProps = ComponentProps<typeof CheckboxIndicatorComponent>;
13
+ export { createCheckboxGroupContext, getCheckboxGroupContext, setCheckboxGroupContext, type CheckboxGroupContext, type CheckboxGroupOrientation, type CheckboxGroupValue, type CreateCheckboxGroupContextOptions } from './root/context.svelte';
14
+ import * as CheckboxGroupParts from './index.parts.js';
15
+ export default CheckboxGroupParts;
@@ -0,0 +1,6 @@
1
+ export * as CheckboxGroup from './index.parts.js';
2
+ export { default as CheckboxGroupRoot } from './root/checkbox-group-root.svelte';
3
+ export { default as CheckboxGroupLabel } from './label/checkbox-group-label.svelte';
4
+ export { createCheckboxGroupContext, getCheckboxGroupContext, setCheckboxGroupContext } from './root/context.svelte';
5
+ import * as CheckboxGroupParts from './index.parts.js';
6
+ export default CheckboxGroupParts;
@@ -0,0 +1,4 @@
1
+ export { default as Root } from './root/checkbox-group-root.svelte';
2
+ export { default as Label } from './label/checkbox-group-label.svelte';
3
+ export { default as Item } from '../checkbox/root/checkbox-root.svelte';
4
+ export { default as Indicator } from '../checkbox/indicator/checkbox-indicator.svelte';
@@ -0,0 +1,7 @@
1
+ export { default as Root } from './root/checkbox-group-root.svelte';
2
+ export { default as Label } from './label/checkbox-group-label.svelte';
3
+ // `Item` and `Indicator` are `Checkbox.Root` and `Checkbox.Indicator` under the namespace of the
4
+ // group. A checkbox works on its own, so it keeps its own name; this pair only gives every group
5
+ // in the library the same shape — `Group.Root` with `Group.Item` inside.
6
+ export { default as Item } from '../checkbox/root/checkbox-root.svelte';
7
+ export { default as Indicator } from '../checkbox/indicator/checkbox-indicator.svelte';
@@ -0,0 +1,36 @@
1
+ <script lang="ts">
2
+ import type { CheckboxGroupLabelProps } from '../types.js';
3
+ import { getCheckboxGroupContext } from '../root/context.svelte';
4
+
5
+ /**
6
+ * CheckboxGroup.Label — the accessible name of the group.
7
+ *
8
+ * It registers its id with the root, which gives it to the group element as
9
+ * `aria-labelledby`. A bare heading beside the group leaves the group unnamed: a
10
+ * `role="group"` takes its name from `aria-labelledby` or `aria-label`, never from the text
11
+ * near it. It renders a `<span>` and not a `<label>`, because a `<label>` names one control.
12
+ */
13
+ let {
14
+ children,
15
+ class: className = '',
16
+ id: idProp,
17
+ ...restProps
18
+ }: CheckboxGroupLabelProps = $props();
19
+
20
+ const checkboxGroup = getCheckboxGroupContext();
21
+
22
+ if (!checkboxGroup) {
23
+ throw new Error('CheckboxGroup.Label must be used within CheckboxGroup.Root.');
24
+ }
25
+
26
+ const group = checkboxGroup;
27
+ const generatedId = $props.id();
28
+ const id = $derived(idProp ?? generatedId);
29
+
30
+ // The returned unregister runs on destroy, and again whenever the id changes.
31
+ $effect(() => group.registerLabel(id));
32
+ </script>
33
+
34
+ <span {...restProps} {id} class={className} data-checkbox-group-label="true">
35
+ {@render children?.()}
36
+ </span>
@@ -0,0 +1,4 @@
1
+ import type { CheckboxGroupLabelProps } from '../types.js';
2
+ declare const CheckboxGroupLabel: import("svelte").Component<CheckboxGroupLabelProps, {}, "">;
3
+ type CheckboxGroupLabel = ReturnType<typeof CheckboxGroupLabel>;
4
+ export default CheckboxGroupLabel;