@human-kit/ui 1.0.0-beta.5 → 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.
- package/README.md +19 -17
- package/dist/accordion/README.md +3 -3
- package/dist/accordion/types.d.ts +37 -23
- package/dist/autocomplete/README.md +6 -7
- package/dist/autocomplete/empty/autocomplete-empty.svelte +1 -1
- package/dist/autocomplete/empty/autocomplete-empty.svelte.d.ts +1 -1
- package/dist/autocomplete/input/autocomplete-input.svelte +3 -3
- package/dist/autocomplete/input/autocomplete-input.svelte.d.ts +3 -3
- package/dist/autocomplete/item/autocomplete-item.svelte +10 -0
- package/dist/autocomplete/item-indicator/autocomplete-item-indicator.svelte +2 -2
- package/dist/autocomplete/item-indicator/autocomplete-item-indicator.svelte.d.ts +2 -2
- package/dist/autocomplete/list/autocomplete-list.svelte +2 -2
- package/dist/autocomplete/list/autocomplete-list.svelte.d.ts +2 -2
- package/dist/autocomplete/root/autocomplete.svelte +7 -7
- package/dist/autocomplete/root/autocomplete.svelte.d.ts +7 -7
- package/dist/autocomplete/status/autocomplete-status.svelte +1 -1
- package/dist/autocomplete/status/autocomplete-status.svelte.d.ts +1 -1
- package/dist/button/README.md +1 -1
- package/dist/button/root/button-root.svelte +24 -10
- package/dist/button/root/button-root.svelte.d.ts +15 -10
- package/dist/calendar/README.md +3 -3
- package/dist/calendar/body-cell/calendar-body-cell.svelte +7 -0
- package/dist/calendar/grid-header/calendar-grid-header.svelte +3 -4
- package/dist/calendar/grid-header/calendar-grid-header.svelte.d.ts +3 -4
- package/dist/calendar/root/calendar-root.svelte +8 -2
- package/dist/calendar/root/calendar-root.svelte.d.ts +8 -2
- package/dist/calendar/trigger-next/README.md +1 -1
- package/dist/calendar/trigger-previous/README.md +1 -1
- package/dist/checkbox/README.md +1 -1
- package/dist/checkbox/indicator/README.md +1 -1
- package/dist/checkbox/indicator/checkbox-indicator.svelte +1 -0
- package/dist/checkbox/indicator/checkbox-indicator.svelte.d.ts +1 -0
- package/dist/checkbox/root/README.md +2 -2
- package/dist/checkbox/root/checkbox-root.svelte +118 -40
- package/dist/checkbox/root/checkbox-root.svelte.d.ts +17 -10
- package/dist/checkbox-group/README.md +95 -0
- package/dist/checkbox-group/index.d.ts +15 -0
- package/dist/checkbox-group/index.js +6 -0
- package/dist/checkbox-group/index.parts.d.ts +4 -0
- package/dist/checkbox-group/index.parts.js +7 -0
- package/dist/checkbox-group/label/checkbox-group-label.svelte +36 -0
- package/dist/checkbox-group/label/checkbox-group-label.svelte.d.ts +4 -0
- package/dist/checkbox-group/root/checkbox-group-root.svelte +118 -0
- package/dist/checkbox-group/root/checkbox-group-root.svelte.d.ts +4 -0
- package/dist/checkbox-group/root/context.svelte.d.ts +52 -0
- package/dist/checkbox-group/root/context.svelte.js +251 -0
- package/dist/checkbox-group/types.d.ts +57 -0
- package/dist/checkbox-group/types.js +1 -0
- package/dist/clock/README.md +3 -3
- package/dist/clock/axis/README.md +1 -1
- package/dist/clock/root/README.md +1 -1
- package/dist/clock/wheel-column/clock-wheel-column.svelte +1 -1
- package/dist/clock/wheel-column/clock-wheel-column.svelte.d.ts +1 -1
- package/dist/collapsible/README.md +3 -3
- package/dist/collapsible/types.d.ts +10 -7
- package/dist/combobox/README.md +2 -2
- package/dist/combobox/button/README.md +6 -6
- package/dist/combobox/input/README.md +1 -1
- package/dist/combobox/input/combobox-input.svelte +3 -3
- package/dist/combobox/input/combobox-input.svelte.d.ts +3 -3
- package/dist/combobox/item/combobox-listboxitem.svelte +4 -2
- package/dist/combobox/item/combobox-listboxitem.svelte.d.ts +4 -2
- package/dist/combobox/item-indicator/README.md +1 -1
- package/dist/combobox/item-indicator/combobox-item-indicator.svelte +2 -2
- package/dist/combobox/item-indicator/combobox-item-indicator.svelte.d.ts +2 -2
- package/dist/combobox/list/combobox-listbox.svelte +11 -8
- package/dist/combobox/list/combobox-listbox.svelte.d.ts +11 -8
- package/dist/combobox/popover/README.md +1 -1
- package/dist/combobox/root/README.md +24 -24
- package/dist/combobox/root/combobox.svelte +26 -17
- package/dist/combobox/root/combobox.svelte.d.ts +26 -17
- package/dist/combobox/status/README.md +1 -1
- package/dist/combobox/status/combobox-status.svelte +1 -1
- package/dist/combobox/status/combobox-status.svelte.d.ts +1 -1
- package/dist/combobox/tag/README.md +1 -1
- package/dist/combobox/tag/combobox-tag.svelte +1 -1
- package/dist/combobox/tag/combobox-tag.svelte.d.ts +1 -1
- package/dist/combobox/tag-remove/README.md +1 -1
- package/dist/combobox/tag-remove/combobox-tag-remove.svelte +4 -5
- package/dist/combobox/tag-remove/combobox-tag-remove.svelte.d.ts +4 -5
- package/dist/combobox/tags/README.md +1 -1
- package/dist/combobox/tags/combobox-tags.svelte +11 -11
- package/dist/combobox/tags/combobox-tags.svelte.d.ts +11 -11
- package/dist/combobox/trigger/README.md +7 -7
- package/dist/datepicker/README.md +4 -4
- package/dist/datepicker/input/date-picker-input.svelte +3 -4
- package/dist/datepicker/input/date-picker-input.svelte.d.ts +3 -4
- package/dist/datepicker/root/date-picker-root.svelte +1 -1
- package/dist/datepicker/trigger/README.md +1 -1
- package/dist/daterangepicker/README.md +3 -3
- package/dist/daterangepicker/input/date-range-picker-input.svelte +3 -4
- package/dist/daterangepicker/input/date-range-picker-input.svelte.d.ts +3 -4
- package/dist/dialog/README.md +1 -1
- package/dist/dialog/close/dialog-close.svelte +3 -3
- package/dist/dialog/close/dialog-close.svelte.d.ts +3 -3
- package/dist/dialog/content/dialog-content.svelte +4 -4
- package/dist/dialog/content/dialog-content.svelte.d.ts +4 -4
- package/dist/dialog/description/dialog-description.svelte +3 -3
- package/dist/dialog/description/dialog-description.svelte.d.ts +3 -3
- package/dist/dialog/overlay/dialog-overlay.svelte +1 -1
- package/dist/dialog/overlay/dialog-overlay.svelte.d.ts +1 -1
- package/dist/dialog/portal/dialog-portal.svelte +1 -1
- package/dist/dialog/portal/dialog-portal.svelte.d.ts +1 -1
- package/dist/dialog/root/README.md +1 -1
- package/dist/dialog/root/dialog-root.svelte +36 -11
- package/dist/dialog/root/dialog-root.svelte.d.ts +11 -9
- package/dist/dialog/title/dialog-title.svelte +3 -3
- package/dist/dialog/title/dialog-title.svelte.d.ts +3 -3
- package/dist/dialog/trigger/README.md +1 -1
- package/dist/drawer/README.md +3 -3
- package/dist/drawer/body/drawer-body.svelte +2 -2
- package/dist/drawer/body/drawer-body.svelte.d.ts +2 -2
- package/dist/drawer/close/drawer-close.svelte +3 -3
- package/dist/drawer/close/drawer-close.svelte.d.ts +3 -3
- package/dist/drawer/content/drawer-content.svelte +12 -9
- package/dist/drawer/content/drawer-content.svelte.d.ts +12 -9
- package/dist/drawer/description/drawer-description.svelte +3 -3
- package/dist/drawer/description/drawer-description.svelte.d.ts +3 -3
- package/dist/drawer/indent/drawer-indent-background.svelte +1 -1
- package/dist/drawer/indent/drawer-indent-background.svelte.d.ts +1 -1
- package/dist/drawer/indent/drawer-indent.svelte +2 -2
- package/dist/drawer/indent/drawer-indent.svelte.d.ts +2 -2
- package/dist/drawer/overlay/drawer-overlay.svelte +1 -1
- package/dist/drawer/overlay/drawer-overlay.svelte.d.ts +1 -1
- package/dist/drawer/portal/drawer-portal.svelte +1 -1
- package/dist/drawer/portal/drawer-portal.svelte.d.ts +1 -1
- package/dist/drawer/root/context.d.ts +1 -1
- package/dist/drawer/root/drawer-root.svelte +25 -23
- package/dist/drawer/root/drawer-root.svelte.d.ts +25 -23
- package/dist/drawer/swipe-area/drawer-swipe-area.svelte +3 -3
- package/dist/drawer/swipe-area/drawer-swipe-area.svelte.d.ts +3 -3
- package/dist/drawer/title/drawer-title.svelte +3 -3
- package/dist/drawer/title/drawer-title.svelte.d.ts +3 -3
- package/dist/drawer/trigger/drawer-trigger.svelte +6 -6
- package/dist/drawer/trigger/drawer-trigger.svelte.d.ts +6 -6
- package/dist/drawer/viewport/drawer-viewport.svelte +2 -2
- package/dist/drawer/viewport/drawer-viewport.svelte.d.ts +2 -2
- package/dist/drawer/virtual-keyboard/drawer-virtual-keyboard-provider.svelte +1 -1
- package/dist/drawer/virtual-keyboard/drawer-virtual-keyboard-provider.svelte.d.ts +1 -1
- package/dist/dropzone/README.md +4 -6
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/input/input.svelte +6 -6
- package/dist/input/input.svelte.d.ts +6 -6
- package/dist/listbox/README.md +3 -10
- package/dist/listbox/item/listbox-item.svelte +24 -15
- package/dist/listbox/item/listbox-item.svelte.d.ts +24 -15
- package/dist/listbox/root/README.md +1 -1
- package/dist/listbox/root/context.d.ts +1 -1
- package/dist/listbox/root/listbox.svelte +50 -38
- package/dist/listbox/root/listbox.svelte.d.ts +50 -38
- package/dist/locale-provider/README.md +1 -6
- package/dist/menu/README.md +6 -15
- package/dist/menu/content/menu-content.svelte +14 -10
- package/dist/menu/content/menu-content.svelte.d.ts +14 -10
- package/dist/menu/context-trigger/menu-context-trigger.svelte +8 -9
- package/dist/menu/context-trigger/menu-context-trigger.svelte.d.ts +8 -9
- package/dist/menu/group/menu-group-label.svelte +1 -1
- package/dist/menu/group/menu-group-label.svelte.d.ts +1 -1
- package/dist/menu/item/menu-item.svelte +11 -8
- package/dist/menu/item/menu-item.svelte.d.ts +11 -8
- package/dist/menu/overlay/menu-overlay.svelte +1 -1
- package/dist/menu/overlay/menu-overlay.svelte.d.ts +1 -1
- package/dist/menu/root/context.d.ts +6 -3
- package/dist/menu/root/menu-root.svelte +14 -8
- package/dist/menu/root/menu-root.svelte.d.ts +14 -8
- package/dist/menu/root/menu-state.svelte.d.ts +1 -1
- package/dist/menu/separator/menu-separator.svelte +1 -1
- package/dist/menu/separator/menu-separator.svelte.d.ts +1 -1
- package/dist/menu/submenu/menu-submenu-root.svelte +10 -7
- package/dist/menu/submenu/menu-submenu-root.svelte.d.ts +10 -7
- package/dist/numberfield/root/README.md +1 -1
- package/dist/numberfield/scrub-area-cursor/README.md +1 -1
- package/dist/popover/README.md +1 -1
- package/dist/popover/content/popover-content.svelte +19 -14
- package/dist/popover/content/popover-content.svelte.d.ts +19 -14
- package/dist/popover/overlay/popover-overlay.svelte +1 -1
- package/dist/popover/overlay/popover-overlay.svelte.d.ts +1 -1
- package/dist/popover/root/README.md +1 -1
- package/dist/popover/root/popover-root.svelte +13 -10
- package/dist/popover/root/popover-root.svelte.d.ts +13 -10
- package/dist/popover/trigger/README.md +1 -1
- package/dist/primitives/floating.d.ts +3 -3
- package/dist/primitives/focus-visible.svelte.d.ts +14 -0
- package/dist/primitives/focus-visible.svelte.js +19 -0
- package/dist/primitives/index.d.ts +1 -0
- package/dist/primitives/index.js +1 -0
- package/dist/primitives/input-modality.d.ts +7 -0
- package/dist/primitives/input-modality.js +32 -5
- package/dist/primitives/scroll-lock.js +37 -8
- package/dist/radio-group/README.md +103 -0
- package/dist/radio-group/index.d.ts +18 -0
- package/dist/radio-group/index.js +9 -0
- package/dist/radio-group/index.parts.d.ts +4 -0
- package/dist/radio-group/index.parts.js +4 -0
- package/dist/radio-group/indicator/radio-group-indicator.svelte +43 -0
- package/dist/radio-group/indicator/radio-group-indicator.svelte.d.ts +12 -0
- package/dist/radio-group/item/context.d.ts +18 -0
- package/dist/radio-group/item/context.js +15 -0
- package/dist/radio-group/item/radio-group-item.svelte +377 -0
- package/dist/radio-group/item/radio-group-item.svelte.d.ts +35 -0
- package/dist/radio-group/label/radio-group-label.svelte +37 -0
- package/dist/radio-group/label/radio-group-label.svelte.d.ts +4 -0
- package/dist/radio-group/root/context.svelte.d.ts +57 -0
- package/dist/radio-group/root/context.svelte.js +284 -0
- package/dist/radio-group/root/radio-group-root.svelte +193 -0
- package/dist/radio-group/root/radio-group-root.svelte.d.ts +4 -0
- package/dist/radio-group/types.d.ts +50 -0
- package/dist/radio-group/types.js +1 -0
- package/dist/switch/root/README.md +2 -2
- package/dist/switch/root/switch-root.svelte +32 -18
- package/dist/switch/root/switch-root.svelte.d.ts +23 -18
- package/dist/switch/thumb/switch-thumb.svelte +1 -1
- package/dist/switch/thumb/switch-thumb.svelte.d.ts +1 -1
- package/dist/table/README.md +15 -10
- package/dist/table/checkbox-indicator/README.md +1 -1
- package/dist/table/column-header-cell/table-column-header-cell.svelte +24 -0
- package/dist/table/column-resizer/README.md +2 -2
- package/dist/table/root/README.md +1 -1
- package/dist/table/root/table-root.svelte +29 -6
- package/dist/table/sort-trigger/README.md +1 -1
- package/dist/table/types.d.ts +21 -20
- package/dist/tabs/types.d.ts +6 -6
- package/dist/timepicker/README.md +3 -2
- package/dist/timepicker/input/README.md +1 -1
- package/dist/timepicker/input/time-picker-input.svelte +66 -5
- package/dist/timepicker/input/time-picker-input.svelte.d.ts +18 -1
- package/dist/timepicker/root/README.md +1 -1
- package/dist/timepicker/trigger/README.md +1 -1
- package/dist/toggle/README.md +1 -1
- package/dist/toggle/root/toggle-root.svelte +28 -0
- package/dist/toggle/root/toggle-root.svelte.d.ts +19 -0
- package/dist/toggle-group/README.md +8 -10
- package/dist/toggle-group/index.d.ts +2 -0
- package/dist/toggle-group/index.parts.d.ts +1 -0
- package/dist/toggle-group/index.parts.js +4 -0
- package/dist/toggle-group/types.d.ts +7 -6
- package/dist/transfer-list/README.md +6 -17
- package/dist/transfer-list/item/transfer-list-item.svelte +4 -4
- package/dist/transfer-list/item/transfer-list-item.svelte.d.ts +4 -4
- package/dist/transfer-list/list/transfer-list-list.svelte +12 -12
- package/dist/transfer-list/list/transfer-list-list.svelte.d.ts +12 -12
- package/dist/transfer-list/move/transfer-list-move-button.svelte +4 -4
- package/dist/transfer-list/move/transfer-list-move-button.svelte.d.ts +4 -4
- package/dist/transfer-list/move/transfer-list-reorder-button.svelte +3 -3
- package/dist/transfer-list/move/transfer-list-reorder-button.svelte.d.ts +3 -3
- package/dist/transfer-list/root/transfer-list-root.svelte +23 -20
- package/dist/transfer-list/root/transfer-list-root.svelte.d.ts +23 -20
- package/dist/transfer-list/status/transfer-list-status.svelte +1 -1
- package/dist/transfer-list/status/transfer-list-status.svelte.d.ts +1 -1
- package/dist/tree/README.md +3 -3
- package/dist/tree/checkbox-indicator/README.md +1 -1
- package/dist/tree/root/README.md +1 -1
- package/dist/tree/types.d.ts +19 -10
- package/package.json +11 -1
|
@@ -6,10 +6,9 @@
|
|
|
6
6
|
|
|
7
7
|
type CalendarGridHeaderProps = {
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
* `weekdayStyle
|
|
11
|
-
*
|
|
12
|
-
* Wednesday in some locales).
|
|
9
|
+
* Your own content for a header cell. It receives the weekday name in the length of
|
|
10
|
+
* `weekdayStyle`, and also the long weekday name. Use the long name as the accessible name when
|
|
11
|
+
* the short one is narrow. In some locales, "M" is the narrow name of Monday and of Wednesday.
|
|
13
12
|
*/
|
|
14
13
|
children?: Snippet<[string, string]>;
|
|
15
14
|
class?: string;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
type CalendarGridHeaderProps = {
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* `weekdayStyle
|
|
6
|
-
*
|
|
7
|
-
* Wednesday in some locales).
|
|
4
|
+
* Your own content for a header cell. It receives the weekday name in the length of
|
|
5
|
+
* `weekdayStyle`, and also the long weekday name. Use the long name as the accessible name when
|
|
6
|
+
* the short one is narrow. In some locales, "M" is the narrow name of Monday and of Wednesday.
|
|
8
7
|
*/
|
|
9
8
|
children?: Snippet<[string, string]>;
|
|
10
9
|
class?: string;
|
|
@@ -42,9 +42,15 @@
|
|
|
42
42
|
showOutsideDays?: boolean;
|
|
43
43
|
firstDayOfWeek?: CalendarFirstDayOfWeek;
|
|
44
44
|
monthHeadingStyle?: CalendarMonthHeadingStyle;
|
|
45
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* The first date that the user can select (`YYYY-MM-DD`). A date before it is unavailable, and
|
|
47
|
+
* the triggers and the focus stop at this limit.
|
|
48
|
+
*/
|
|
46
49
|
minValue?: CalendarDateValue;
|
|
47
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* The last date that the user can select (`YYYY-MM-DD`). A date after it is unavailable, and the
|
|
52
|
+
* triggers and the focus stop at this limit.
|
|
53
|
+
*/
|
|
48
54
|
maxValue?: CalendarDateValue;
|
|
49
55
|
isDateUnavailable?: (date: string) => boolean;
|
|
50
56
|
disabled?: boolean;
|
|
@@ -7,9 +7,15 @@ type CalendarRootProps = {
|
|
|
7
7
|
showOutsideDays?: boolean;
|
|
8
8
|
firstDayOfWeek?: CalendarFirstDayOfWeek;
|
|
9
9
|
monthHeadingStyle?: CalendarMonthHeadingStyle;
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* The first date that the user can select (`YYYY-MM-DD`). A date before it is unavailable, and
|
|
12
|
+
* the triggers and the focus stop at this limit.
|
|
13
|
+
*/
|
|
11
14
|
minValue?: CalendarDateValue;
|
|
12
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* The last date that the user can select (`YYYY-MM-DD`). A date after it is unavailable, and the
|
|
17
|
+
* triggers and the focus stop at this limit.
|
|
18
|
+
*/
|
|
13
19
|
maxValue?: CalendarDateValue;
|
|
14
20
|
isDateUnavailable?: (date: string) => boolean;
|
|
15
21
|
disabled?: boolean;
|
|
@@ -10,5 +10,5 @@ Description: Button part that advances the visible calendar period.
|
|
|
10
10
|
| Prop | Type | Default | Description |
|
|
11
11
|
| -------------- | ---------------------- | ----------- | ------------------------------------------------------ |
|
|
12
12
|
| `children` | `Snippet` | `undefined` | Optional trigger content. |
|
|
13
|
-
| `class` | `string` | `''` | CSS class names
|
|
13
|
+
| `class` | `string` | `''` | The CSS class names of the trigger button. |
|
|
14
14
|
| `...restProps` | `HTMLButtonAttributes` | `-` | Additional button attributes forwarded to the trigger. |
|
|
@@ -10,5 +10,5 @@ Description: Button part that moves the visible calendar period backward.
|
|
|
10
10
|
| Prop | Type | Default | Description |
|
|
11
11
|
| -------------- | ---------------------- | ----------- | ------------------------------------------------------ |
|
|
12
12
|
| `children` | `Snippet` | `undefined` | Optional trigger content. |
|
|
13
|
-
| `class` | `string` | `''` | CSS class names
|
|
13
|
+
| `class` | `string` | `''` | The CSS class names of the trigger button. |
|
|
14
14
|
| `...restProps` | `HTMLButtonAttributes` | `-` | Additional button attributes forwarded to the trigger. |
|
package/dist/checkbox/README.md
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
## Usage guidelines
|
|
21
21
|
|
|
22
22
|
- Use `checked` / `defaultChecked` for the checked state and `indeterminate` / `defaultIndeterminate` for the mixed state.
|
|
23
|
-
- `indeterminate`
|
|
23
|
+
- `indeterminate` has more importance than `checked`. If both are `true`, the checkbox is indeterminate.
|
|
24
24
|
- Use `value` only for form submission through the hidden native input; it does not represent the visual state.
|
|
25
25
|
- Wrap the checkbox in a native `<label>` for the simplest accessible labeling pattern.
|
|
26
26
|
|
|
@@ -11,7 +11,7 @@ Description: Headless presence wrapper for checkbox indicator content. It render
|
|
|
11
11
|
| -------------- | --------------------------------- | ----------- | ------------------------------------------------------------------------ |
|
|
12
12
|
| `forceMount` | `boolean` | `false` | Keeps the indicator mounted while hidden when the checkbox is unchecked. |
|
|
13
13
|
| `children` | `Snippet` | `undefined` | Rendered indicator content, such as a check or dash icon. |
|
|
14
|
-
| `class` | `string` | `''` | CSS class names
|
|
14
|
+
| `class` | `string` | `''` | The CSS class names of the indicator container. |
|
|
15
15
|
| `...restProps` | `HTMLAttributes<HTMLSpanElement>` | `-` | Additional attributes forwarded to the indicator span. |
|
|
16
16
|
|
|
17
17
|
```svelte
|
|
@@ -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;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
### Checkbox.Root
|
|
6
6
|
|
|
7
7
|
Name: `Checkbox.Root`
|
|
8
|
-
Description:
|
|
8
|
+
Description: The root of a checkbox with three states. It holds the checked state, the indeterminate state, and the focus, and it keeps the hidden input correct.
|
|
9
9
|
|
|
10
10
|
| Prop | Type | Default | Description |
|
|
11
11
|
| ----------------------- | ---------------------------------- | ------------- | --------------------------------------------------------------- |
|
|
@@ -23,7 +23,7 @@ Description: Interactive tri-state checkbox root that owns checked, indeterminat
|
|
|
23
23
|
| `readonly` | `boolean` | `false` | Allows focus but blocks user-driven state changes. |
|
|
24
24
|
| `required` | `boolean` | `false` | Marks the hidden input as required and exposes `data-required`. |
|
|
25
25
|
| `children` | `Snippet` | `undefined` | Composed checkbox parts such as `Checkbox.Indicator`. |
|
|
26
|
-
| `class` | `string` | `''` | CSS class names
|
|
26
|
+
| `class` | `string` | `''` | The CSS class names of the root element. |
|
|
27
27
|
| `...restProps` | `HTMLAttributes<HTMLSpanElement>` | `-` | Additional attributes forwarded to the checkbox root span. |
|
|
28
28
|
|
|
29
29
|
### Context utilities
|
|
@@ -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<
|
|
@@ -25,34 +27,41 @@
|
|
|
25
27
|
element?: HTMLSpanElement | null;
|
|
26
28
|
name?: string;
|
|
27
29
|
value?: string;
|
|
28
|
-
/**
|
|
30
|
+
/** The id of the form of the hidden input. */
|
|
29
31
|
form?: string;
|
|
30
|
-
/**
|
|
32
|
+
/** The checked state. By default it goes in the two directions: use `bind:checked`. */
|
|
31
33
|
checked?: boolean;
|
|
32
|
-
/**
|
|
34
|
+
/** The checked state at the start, for when you give no `checked`. */
|
|
33
35
|
defaultChecked?: boolean;
|
|
34
36
|
/**
|
|
35
|
-
*
|
|
36
|
-
* and
|
|
37
|
-
* not
|
|
38
|
-
*
|
|
37
|
+
* Give your own code full control of `checked`. The component stops to write back to the prop,
|
|
38
|
+
* and it reports only through `onCheckedChange`. Thus the parent can refuse a change: the parent
|
|
39
|
+
* does not send the new value down. The default is off, because `bind:checked` is the usual case
|
|
40
|
+
* and it needs the write-back.
|
|
39
41
|
*/
|
|
40
42
|
controlledChecked?: boolean;
|
|
41
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* The indeterminate state. By default it goes in the two directions: use `bind:indeterminate`.
|
|
45
|
+
*/
|
|
42
46
|
indeterminate?: boolean;
|
|
43
|
-
/**
|
|
47
|
+
/** The indeterminate state at the start, for when you give no `indeterminate`. */
|
|
44
48
|
defaultIndeterminate?: boolean;
|
|
45
|
-
/**
|
|
49
|
+
/** Give your own code full control of `indeterminate`. Read `controlledChecked`. */
|
|
46
50
|
controlledIndeterminate?: boolean;
|
|
51
|
+
/** The component calls it when the user changes the checked state. */
|
|
47
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. */
|
|
48
54
|
onIndeterminateChange?: (indeterminate: boolean) => void;
|
|
49
55
|
disabled?: boolean;
|
|
50
56
|
readonly?: boolean;
|
|
51
57
|
required?: boolean;
|
|
52
58
|
children?: Snippet;
|
|
53
59
|
class?: string;
|
|
60
|
+
/** The accessible name, for when the user sees no name. */
|
|
54
61
|
'aria-label'?: string;
|
|
62
|
+
/** The id of the element that gives the checkbox its name. */
|
|
55
63
|
'aria-labelledby'?: string;
|
|
64
|
+
/** Replaces the default position in the tab order. */
|
|
56
65
|
tabindex?: number;
|
|
57
66
|
onclick?: HTMLAttributes<HTMLSpanElement>['onclick'];
|
|
58
67
|
onkeydown?: HTMLAttributes<HTMLSpanElement>['onkeydown'];
|
|
@@ -136,6 +145,13 @@
|
|
|
136
145
|
const inputId = instanceId;
|
|
137
146
|
const rootId = `${instanceId}-root`;
|
|
138
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
|
+
|
|
139
155
|
const initialChecked = untrack(() => checked ?? defaultChecked);
|
|
140
156
|
const initialIndeterminate = untrack(() => indeterminate ?? defaultIndeterminate);
|
|
141
157
|
const initialState = resolveState(initialChecked, initialIndeterminate);
|
|
@@ -149,6 +165,35 @@
|
|
|
149
165
|
let rootRef: HTMLSpanElement | null = $state(null);
|
|
150
166
|
let inputRef: HTMLInputElement | null = $state(null);
|
|
151
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
|
+
|
|
152
197
|
$effect(() => {
|
|
153
198
|
element = rootRef;
|
|
154
199
|
return () => {
|
|
@@ -156,10 +201,21 @@
|
|
|
156
201
|
};
|
|
157
202
|
});
|
|
158
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
|
+
|
|
159
215
|
$effect(() => {
|
|
160
|
-
if (!
|
|
216
|
+
if (!renderedDisabled && !renderedReadOnly) return;
|
|
161
217
|
clearPressState();
|
|
162
|
-
if (
|
|
218
|
+
if (renderedDisabled) {
|
|
163
219
|
focusVisible = false;
|
|
164
220
|
}
|
|
165
221
|
});
|
|
@@ -169,7 +225,9 @@
|
|
|
169
225
|
// broke every `bind:checked` seeded with `false`. It is opt-in per prop instead.
|
|
170
226
|
// Write the initial state back so `bind:` parents see the resolved default. Read
|
|
171
227
|
// untracked: this is a deliberate one-time seed at init, not a reactive mirror.
|
|
172
|
-
|
|
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)) {
|
|
173
231
|
checked = initialState === 'checked';
|
|
174
232
|
}
|
|
175
233
|
|
|
@@ -178,10 +236,15 @@
|
|
|
178
236
|
}
|
|
179
237
|
|
|
180
238
|
// 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.
|
|
239
|
+
// value — and the internal state only carries the fully uncontrolled case. A group
|
|
240
|
+
// outranks all of it.
|
|
182
241
|
const currentState = $derived.by(() =>
|
|
183
242
|
resolveState(
|
|
184
|
-
|
|
243
|
+
checkboxGroup
|
|
244
|
+
? checkboxGroup.isSelected(value)
|
|
245
|
+
: controlledChecked
|
|
246
|
+
? Boolean(checked)
|
|
247
|
+
: (checked ?? checkedInternal),
|
|
185
248
|
controlledIndeterminate ? Boolean(indeterminate) : (indeterminate ?? indeterminateInternal)
|
|
186
249
|
)
|
|
187
250
|
);
|
|
@@ -190,6 +253,14 @@
|
|
|
190
253
|
const currentIndeterminate = $derived(currentState === 'indeterminate');
|
|
191
254
|
const currentUnchecked = $derived(currentState === 'unchecked');
|
|
192
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
|
+
|
|
193
264
|
function clearPressState() {
|
|
194
265
|
pressed = false;
|
|
195
266
|
pressedKey = null;
|
|
@@ -200,8 +271,15 @@
|
|
|
200
271
|
const nextIndeterminate = nextState === 'indeterminate';
|
|
201
272
|
const previousChecked = currentChecked;
|
|
202
273
|
const previousIndeterminate = currentIndeterminate;
|
|
203
|
-
|
|
204
|
-
|
|
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) {
|
|
205
283
|
checkedInternal = nextChecked;
|
|
206
284
|
checked = nextChecked;
|
|
207
285
|
}
|
|
@@ -211,7 +289,7 @@
|
|
|
211
289
|
indeterminate = nextIndeterminate;
|
|
212
290
|
}
|
|
213
291
|
|
|
214
|
-
if (
|
|
292
|
+
if (didChangeChecked) {
|
|
215
293
|
onCheckedChange?.(nextChecked);
|
|
216
294
|
}
|
|
217
295
|
|
|
@@ -225,7 +303,7 @@
|
|
|
225
303
|
}
|
|
226
304
|
|
|
227
305
|
function setState(nextState: CheckboxState, event?: Event) {
|
|
228
|
-
if (
|
|
306
|
+
if (renderedDisabled || renderedReadOnly) return;
|
|
229
307
|
publishState(nextState, event);
|
|
230
308
|
}
|
|
231
309
|
|
|
@@ -234,7 +312,7 @@
|
|
|
234
312
|
}
|
|
235
313
|
|
|
236
314
|
function requestNativeToggle(event?: Event) {
|
|
237
|
-
if (
|
|
315
|
+
if (renderedDisabled || renderedReadOnly) return;
|
|
238
316
|
if (!inputRef) {
|
|
239
317
|
toggle(event);
|
|
240
318
|
return;
|
|
@@ -247,7 +325,7 @@
|
|
|
247
325
|
trackInteractionModality(event, rootRef);
|
|
248
326
|
|
|
249
327
|
if (event.defaultPrevented) return;
|
|
250
|
-
if (
|
|
328
|
+
if (renderedDisabled || renderedReadOnly) {
|
|
251
329
|
event.preventDefault();
|
|
252
330
|
return;
|
|
253
331
|
}
|
|
@@ -305,7 +383,7 @@
|
|
|
305
383
|
trackInteractionModality(event, rootRef);
|
|
306
384
|
focusVisible = false;
|
|
307
385
|
|
|
308
|
-
if (
|
|
386
|
+
if (renderedDisabled || renderedReadOnly) {
|
|
309
387
|
event.preventDefault();
|
|
310
388
|
clearPressState();
|
|
311
389
|
return;
|
|
@@ -328,7 +406,7 @@
|
|
|
328
406
|
}
|
|
329
407
|
|
|
330
408
|
function handlePointerEnter(event: PointerEvent) {
|
|
331
|
-
if (
|
|
409
|
+
if (renderedDisabled || renderedReadOnly) return;
|
|
332
410
|
|
|
333
411
|
if ((event.buttons & 1) === 1 && pressedKey === null) {
|
|
334
412
|
pressed = true;
|
|
@@ -345,7 +423,7 @@
|
|
|
345
423
|
trackInteractionModality(event, rootRef);
|
|
346
424
|
focusVisible = false;
|
|
347
425
|
|
|
348
|
-
if (
|
|
426
|
+
if (renderedDisabled || renderedReadOnly) {
|
|
349
427
|
event.preventDefault();
|
|
350
428
|
clearPressState();
|
|
351
429
|
return;
|
|
@@ -384,7 +462,7 @@
|
|
|
384
462
|
const target = event.currentTarget;
|
|
385
463
|
if (!(target instanceof HTMLInputElement)) return;
|
|
386
464
|
|
|
387
|
-
if (
|
|
465
|
+
if (renderedDisabled || renderedReadOnly) {
|
|
388
466
|
target.checked = currentChecked;
|
|
389
467
|
target.indeterminate = currentIndeterminate;
|
|
390
468
|
return;
|
|
@@ -457,13 +535,13 @@
|
|
|
457
535
|
return currentIndeterminate;
|
|
458
536
|
},
|
|
459
537
|
get isDisabled() {
|
|
460
|
-
return
|
|
538
|
+
return renderedDisabled;
|
|
461
539
|
},
|
|
462
540
|
get isReadOnly() {
|
|
463
|
-
return
|
|
541
|
+
return renderedReadOnly;
|
|
464
542
|
},
|
|
465
543
|
get required() {
|
|
466
|
-
return
|
|
544
|
+
return renderedRequired;
|
|
467
545
|
},
|
|
468
546
|
get focused() {
|
|
469
547
|
return focused;
|
|
@@ -481,11 +559,11 @@
|
|
|
481
559
|
bind:this={rootRef}
|
|
482
560
|
id={rootId}
|
|
483
561
|
role="checkbox"
|
|
484
|
-
tabindex={
|
|
562
|
+
tabindex={renderedDisabled ? undefined : (tabindex ?? 0)}
|
|
485
563
|
aria-checked={currentIndeterminate ? 'mixed' : currentChecked ? 'true' : 'false'}
|
|
486
|
-
aria-disabled={
|
|
487
|
-
aria-readonly={
|
|
488
|
-
aria-required={
|
|
564
|
+
aria-disabled={renderedDisabled || undefined}
|
|
565
|
+
aria-readonly={renderedReadOnly || undefined}
|
|
566
|
+
aria-required={renderedRequired || undefined}
|
|
489
567
|
aria-label={ariaLabel}
|
|
490
568
|
aria-labelledby={ariaLabelledby}
|
|
491
569
|
data-checkbox-root="true"
|
|
@@ -493,9 +571,9 @@
|
|
|
493
571
|
data-unchecked={currentUnchecked || undefined}
|
|
494
572
|
data-indeterminate={currentIndeterminate || undefined}
|
|
495
573
|
data-pressed={pressed || undefined}
|
|
496
|
-
data-disabled={
|
|
497
|
-
data-readonly={
|
|
498
|
-
data-required={
|
|
574
|
+
data-disabled={renderedDisabled || undefined}
|
|
575
|
+
data-readonly={renderedReadOnly || undefined}
|
|
576
|
+
data-required={renderedRequired || undefined}
|
|
499
577
|
data-focused={focused || undefined}
|
|
500
578
|
data-focus-visible={focusVisible || undefined}
|
|
501
579
|
onclick={composeEventHandlers(onClickExternal ?? undefined, handleClick)}
|
|
@@ -520,13 +598,13 @@
|
|
|
520
598
|
id={inputId}
|
|
521
599
|
tabindex={-1}
|
|
522
600
|
type="checkbox"
|
|
523
|
-
{
|
|
601
|
+
name={renderedName}
|
|
524
602
|
{value}
|
|
525
603
|
{form}
|
|
526
604
|
checked={currentChecked}
|
|
527
|
-
{
|
|
528
|
-
{
|
|
529
|
-
{
|
|
605
|
+
disabled={renderedDisabled}
|
|
606
|
+
required={renderedRequired}
|
|
607
|
+
readonly={renderedReadOnly}
|
|
530
608
|
aria-hidden="true"
|
|
531
609
|
data-checkbox-input="true"
|
|
532
610
|
onclick={handleInputClick}
|
|
@@ -5,34 +5,41 @@ type CheckboxRootProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children' | 'cla
|
|
|
5
5
|
element?: HTMLSpanElement | null;
|
|
6
6
|
name?: string;
|
|
7
7
|
value?: string;
|
|
8
|
-
/**
|
|
8
|
+
/** The id of the form of the hidden input. */
|
|
9
9
|
form?: string;
|
|
10
|
-
/**
|
|
10
|
+
/** The checked state. By default it goes in the two directions: use `bind:checked`. */
|
|
11
11
|
checked?: boolean;
|
|
12
|
-
/**
|
|
12
|
+
/** The checked state at the start, for when you give no `checked`. */
|
|
13
13
|
defaultChecked?: boolean;
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
* and
|
|
17
|
-
* not
|
|
18
|
-
*
|
|
15
|
+
* Give your own code full control of `checked`. The component stops to write back to the prop,
|
|
16
|
+
* and it reports only through `onCheckedChange`. Thus the parent can refuse a change: the parent
|
|
17
|
+
* does not send the new value down. The default is off, because `bind:checked` is the usual case
|
|
18
|
+
* and it needs the write-back.
|
|
19
19
|
*/
|
|
20
20
|
controlledChecked?: boolean;
|
|
21
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* The indeterminate state. By default it goes in the two directions: use `bind:indeterminate`.
|
|
23
|
+
*/
|
|
22
24
|
indeterminate?: boolean;
|
|
23
|
-
/**
|
|
25
|
+
/** The indeterminate state at the start, for when you give no `indeterminate`. */
|
|
24
26
|
defaultIndeterminate?: boolean;
|
|
25
|
-
/**
|
|
27
|
+
/** Give your own code full control of `indeterminate`. Read `controlledChecked`. */
|
|
26
28
|
controlledIndeterminate?: boolean;
|
|
29
|
+
/** The component calls it when the user changes the checked state. */
|
|
27
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. */
|
|
28
32
|
onIndeterminateChange?: (indeterminate: boolean) => void;
|
|
29
33
|
disabled?: boolean;
|
|
30
34
|
readonly?: boolean;
|
|
31
35
|
required?: boolean;
|
|
32
36
|
children?: Snippet;
|
|
33
37
|
class?: string;
|
|
38
|
+
/** The accessible name, for when the user sees no name. */
|
|
34
39
|
'aria-label'?: string;
|
|
40
|
+
/** The id of the element that gives the checkbox its name. */
|
|
35
41
|
'aria-labelledby'?: string;
|
|
42
|
+
/** Replaces the default position in the tab order. */
|
|
36
43
|
tabindex?: number;
|
|
37
44
|
onclick?: HTMLAttributes<HTMLSpanElement>['onclick'];
|
|
38
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;
|