@human-kit/ui 1.0.0-beta.4 → 1.0.0-beta.6
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-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 +15 -10
- package/dist/button/root/button-root.svelte.d.ts +15 -10
- package/dist/calendar/README.md +3 -3
- 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/root/README.md +2 -2
- package/dist/checkbox/root/checkbox-root.svelte +12 -10
- package/dist/checkbox/root/checkbox-root.svelte.d.ts +12 -10
- 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/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/scroll-lock.js +37 -8
- package/dist/switch/root/README.md +2 -2
- package/dist/switch/root/switch-root.svelte +23 -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-resizer/README.md +2 -2
- package/dist/table/root/README.md +1 -1
- 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 +58 -5
- package/dist/timepicker/input/time-picker-input.svelte.d.ts +10 -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-group/README.md +6 -0
- package/dist/toggle-group/root/context.svelte.d.ts +1 -1
- package/dist/toggle-group/root/context.svelte.js +20 -11
- package/dist/toggle-group/root/toggle-group-root.svelte +20 -15
- package/dist/toggle-group/root/toggle-group-teardown-order-child.svelte +13 -0
- package/dist/toggle-group/root/toggle-group-teardown-order-child.svelte.d.ts +7 -0
- package/dist/toggle-group/types.d.ts +9 -9
- 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 +1 -1
|
@@ -1,42 +1,47 @@
|
|
|
1
1
|
import { type Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
type SwitchRootProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children' | 'class' | 'id' | 'role' | 'aria-checked' | 'aria-disabled' | 'aria-readonly' | 'aria-required' | 'onclick' | 'onkeydown' | 'value'> & {
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* The id of the hidden input, thus a `label[for]` element can point at the switch. If you give
|
|
6
|
+
* none, the component makes one.
|
|
7
|
+
*/
|
|
5
8
|
id?: string;
|
|
6
|
-
/**
|
|
9
|
+
/** A bindable reference to the root element. */
|
|
7
10
|
element?: HTMLSpanElement | null;
|
|
8
|
-
/**
|
|
11
|
+
/** The name that the form submits while the switch is on. */
|
|
9
12
|
name?: string;
|
|
10
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* The value that the form submits while the switch is on. It does not change the visual state.
|
|
15
|
+
*/
|
|
11
16
|
value?: string;
|
|
12
|
-
/**
|
|
17
|
+
/** The id of the form of the hidden input. */
|
|
13
18
|
form?: string;
|
|
14
|
-
/**
|
|
19
|
+
/** The checked state. By default it goes in the two directions: use `bind:checked`. */
|
|
15
20
|
checked?: boolean;
|
|
16
|
-
/**
|
|
21
|
+
/** The checked state at the start, for when you give no `checked`. */
|
|
17
22
|
defaultChecked?: boolean;
|
|
18
23
|
/**
|
|
19
|
-
*
|
|
20
|
-
* and
|
|
21
|
-
* not
|
|
22
|
-
*
|
|
24
|
+
* Give your own code full control of the state. The component stops to write back to `checked`,
|
|
25
|
+
* and it reports only through `onCheckedChange`. Thus the parent can refuse a change: the parent
|
|
26
|
+
* does not send the new value down. The default is off, because `bind:checked` is the usual case
|
|
27
|
+
* and it needs the write-back.
|
|
23
28
|
*/
|
|
24
29
|
controlledChecked?: boolean;
|
|
25
|
-
/**
|
|
30
|
+
/** The component calls it when the user changes the switch. */
|
|
26
31
|
onCheckedChange?: (checked: boolean) => void;
|
|
27
|
-
/**
|
|
32
|
+
/** Stops the interaction with the switch and removes it from the focus order. */
|
|
28
33
|
disabled?: boolean;
|
|
29
|
-
/** Keeps the switch focusable
|
|
34
|
+
/** Keeps the switch focusable, but stops the changes of the state. */
|
|
30
35
|
readonly?: boolean;
|
|
31
|
-
/**
|
|
36
|
+
/** Makes the hidden input required for the form validation. */
|
|
32
37
|
required?: boolean;
|
|
33
38
|
children?: Snippet;
|
|
34
39
|
class?: string;
|
|
35
|
-
/**
|
|
40
|
+
/** The accessible name, for when the user sees no name. */
|
|
36
41
|
'aria-label'?: string;
|
|
37
|
-
/**
|
|
42
|
+
/** The id of the element that gives the switch its name. */
|
|
38
43
|
'aria-labelledby'?: string;
|
|
39
|
-
/**
|
|
44
|
+
/** Replaces the default position in the tab order. */
|
|
40
45
|
tabindex?: number;
|
|
41
46
|
onclick?: HTMLAttributes<HTMLSpanElement>['onclick'];
|
|
42
47
|
onkeydown?: HTMLAttributes<HTMLSpanElement>['onkeydown'];
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { useSwitchContext } from '../root/context';
|
|
5
5
|
|
|
6
6
|
type SwitchThumbProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children' | 'class'> & {
|
|
7
|
-
/**
|
|
7
|
+
/** The content of the thumb. */
|
|
8
8
|
children?: Snippet;
|
|
9
9
|
class?: string;
|
|
10
10
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
type SwitchThumbProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children' | 'class'> & {
|
|
4
|
-
/**
|
|
4
|
+
/** The content of the thumb. */
|
|
5
5
|
children?: Snippet;
|
|
6
6
|
class?: string;
|
|
7
7
|
};
|
package/dist/table/README.md
CHANGED
|
@@ -6,7 +6,12 @@
|
|
|
6
6
|
|
|
7
7
|
`Table` is a headless interactive table primitive with grid-style keyboard navigation, row selection, explicit sortable header triggers, and a composable part-based API.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
The table barrel exports the prop types of each public Table part.
|
|
10
|
+
|
|
11
|
+
These are `TableRootProps`, `TableColumnProps`, `TableHeaderProps`, `TableBodyProps`,
|
|
12
|
+
`TableFooterProps`, `TableRowProps`, `TableColumnHeaderCellProps`, `TableSortTriggerProps`,
|
|
13
|
+
`TableColumnResizerProps`, `TableCellProps`, `TableEmptyStateProps`, `TableCheckboxProps`,
|
|
14
|
+
and `TableCheckboxIndicatorProps`.
|
|
10
15
|
|
|
11
16
|
## Anatomy
|
|
12
17
|
|
|
@@ -88,8 +93,8 @@ All public Table part prop types are exported from the table barrel, including `
|
|
|
88
93
|
## Usage guidelines
|
|
89
94
|
|
|
90
95
|
- Use `Table.Root` as the stateful container for focus, selection, and sorting state.
|
|
91
|
-
- Use `keyboardNavigation` to choose how far the roving tab stop reaches into the body: `'grid'` (default) makes every body cell a focus target, `'row'` makes the row the only one, and `'none'` leaves the body inert.
|
|
92
|
-
- Use `selectionBehavior="toggle"` to
|
|
96
|
+
- Use `keyboardNavigation` to choose how far the roving tab stop reaches into the body: `'grid'` (default) makes every body cell a focus target, `'row'` makes the row the only one, and `'none'` leaves the body inert. The cell navigation has a cost: one focus registration and one focus state for each cell. A virtualized table does this again for each row that it makes. Use `'row'` when the body is a list, and not a surface where the user works. Use `'none'` only when nothing in the body does an action. The header keeps its own navigation in every mode.
|
|
97
|
+
- Use `selectionBehavior="toggle"` to let the user remove the selection of a selected row. Use `selectionBehavior="replace"` to keep a selected row selected when the user presses it again.
|
|
93
98
|
- `Table.Column` is a logical-only wrapper for column metadata; it does not render DOM by itself and should wrap a single `Table.ColumnHeaderCell`.
|
|
94
99
|
- Wrap each header cell in `Table.Column` so the table can register stable column metadata.
|
|
95
100
|
- Add `Table.ColumnResizer` inside `Table.ColumnHeaderCell` to make the owning `Table.Column` resizable.
|
|
@@ -102,16 +107,16 @@ All public Table part prop types are exported from the table barrel, including `
|
|
|
102
107
|
- Use `defaultHiddenColumns` for uncontrolled initial column visibility.
|
|
103
108
|
- Use `columnWidths` / `onColumnWidthsChange` for controlled column width state. Width specs can be px, `%`, or `fr`.
|
|
104
109
|
- Use `defaultColumnWidths` and `Table.Column.defaultWidth` to seed uncontrolled initial widths that can still be resized by the user.
|
|
105
|
-
- Use `Table.Column.width` when a column
|
|
106
|
-
- In resizable tables, unspecified columns behave like an implicit `1fr` width before interaction.
|
|
110
|
+
- Use `Table.Column.width` when a column must keep an exact width. A column with a fixed width does not change its width, also with a `Table.ColumnResizer` in it.
|
|
111
|
+
- In resizable tables, unspecified columns behave like an implicit `1fr` width before interaction. At the first width change, the component sets each visible column in px. The last column takes the difference, down to its minimum width. After that, the table becomes wider than its container.
|
|
107
112
|
- Setting `sortDescriptor` back to `undefined` clears the controlled sort state, matching React Aria Table semantics.
|
|
108
113
|
- Set `Table.Column.textValue` when the spoken column label should differ from the column id; `Table.Root` uses it for polite sort announcements.
|
|
109
114
|
- Use `Table.EmptyState` inside `Table.Body` instead of conditionally rendering freeform body content.
|
|
110
115
|
- Use `Table.Checkbox` when you need explicit selection UI inside cells instead of relying only on row or cell presses.
|
|
111
|
-
- Use `Table.CheckboxIndicator` to
|
|
112
|
-
- Use `Table.InteractiveCell` for body
|
|
116
|
+
- Use `Table.CheckboxIndicator` to make your own marks for the checked state and the indeterminate state.
|
|
117
|
+
- Use `Table.InteractiveCell` for a body cell that has its own controls. While the focus is on the cell, the grid keyboard operation is the same as in `Table.Cell`. While the focus is on a control in the cell, that control gets the keys and the pointer.
|
|
113
118
|
- `Table.Checkbox` auto-hides in header cells unless `selectionMode="multiple"`, and auto-hides everywhere when `selectionMode="none"`.
|
|
114
|
-
-
|
|
119
|
+
- A hidden column is not in the grid navigation, not in the column count, and not in the width changes. It keeps its width, thus you can show it again with that width.
|
|
115
120
|
- Dedicated utility columns like selection checkboxes should usually set an explicit `width`, `minWidth`, and `maxWidth` on `Table.Column` so sibling resizes do not redistribute their space.
|
|
116
121
|
- When `selectionMode` changes to `none`, the component clears any existing row selection internally.
|
|
117
122
|
- v1 leaves text selection and `Ctrl+C` behavior browser-native; the table does not implement custom copy handling or force a text-selection policy.
|
|
@@ -134,10 +139,10 @@ All public Table part prop types are exported from the table barrel, including `
|
|
|
134
139
|
- `Table.Root` renders an interactive `grid` over native table markup.
|
|
135
140
|
- Keyboard navigation uses roving `tabindex` across header and body cells.
|
|
136
141
|
- Under `keyboardNavigation="row"` the body's roving tab stop sits on the rows: arrows walk rows, `Enter` presses one and `Space` toggles its selection. Focusable content inside body cells becomes a regular tab stop instead, since no roving focus reaches it there.
|
|
137
|
-
-
|
|
142
|
+
- A body row can also take the focus when the horizontal navigation goes past the start or the end of the row. If the user continues to push the left key or the right key, the focus goes to the cell at the opposite edge.
|
|
138
143
|
- `Table.Checkbox` can receive DOM focus directly while still participating in the table's roving-focus grid.
|
|
139
144
|
- First-column body cells become `rowheader` when their associated column has `rowHeader`.
|
|
140
145
|
- Disabled rows remain rendered and non-selectable, but are skipped by focus navigation.
|
|
141
146
|
- `Table.SortTrigger` renders the trigger button, while the header cell remains the roving-focus target for arrow-key grid navigation.
|
|
142
147
|
- Sort changes are mirrored into a polite live region so screen readers announce direction changes more reliably than `aria-sort` alone.
|
|
143
|
-
- Column resize handles are keyboard accessible separators.
|
|
148
|
+
- Column resize handles are keyboard accessible separators. Push `Enter` to start the resize mode. Use the horizontal arrow keys to change the width. Push `Home` for the minimum width, and `End` for the width of the content. Push `Enter` again to leave the resize mode. The focus stays on the handle.
|
|
@@ -13,7 +13,7 @@ Public prop type: `TableCheckboxIndicatorProps`
|
|
|
13
13
|
| -------------- | --------------------------------- | ----------- | ------------------------------------------------------------------------------- |
|
|
14
14
|
| `forceMount` | `boolean` | `false` | Keeps the indicator mounted while hidden when the checkbox is unchecked. |
|
|
15
15
|
| `children` | `Snippet` | `undefined` | Rendered indicator content, such as a check icon or dash icon. |
|
|
16
|
-
| `class` | `string` | `''` | CSS class names
|
|
16
|
+
| `class` | `string` | `''` | The CSS class names of the indicator container. |
|
|
17
17
|
| `...restProps` | `HTMLAttributes<HTMLSpanElement>` | `-` | Additional native attributes forwarded to the composed checkbox indicator span. |
|
|
18
18
|
|
|
19
19
|
## Usage notes
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
### Table.ColumnResizer
|
|
8
8
|
|
|
9
9
|
Name: `Table.ColumnResizer`
|
|
10
|
-
Description:
|
|
10
|
+
Description: The handle that changes the width of the current `Table.Column`. Put it in a `Table.ColumnHeaderCell`. It changes the width of the column of the `Table.Column` context around it.
|
|
11
11
|
|
|
12
12
|
Public prop type: `TableColumnResizerProps`
|
|
13
13
|
|
|
@@ -25,7 +25,7 @@ Public prop type: `TableColumnResizerProps`
|
|
|
25
25
|
- The handle resolves the active column from `Table.Column` context. It does not accept a separate `columnId` prop.
|
|
26
26
|
- Width state lives in `Table.Root` through `columnWidths` / `defaultColumnWidths`.
|
|
27
27
|
- Pointer resizing uses Pointer Events, so mouse, touch, and pen interactions share the same behavior.
|
|
28
|
-
-
|
|
28
|
+
- The keyboard changes the width in a resize mode. Move the focus to the handle and push `Enter` to start that mode. Use the `ArrowLeft` key and the `ArrowRight` key, with `Shift` for a larger step, to change the width. Push `Home` for the minimum width, and `End` for the width of the content. Push `Enter` again to keep the width. The focus stays on the handle.
|
|
29
29
|
- While keyboard resize mode is active, pressing `Escape` restores the starting width, exits resize mode, and returns focus to the owning header cell.
|
|
30
30
|
- Keyboard resizing uses the same resize lifecycle callbacks as pointer resizing and announces committed widths through a polite live region.
|
|
31
31
|
- During pointer drag, pressing `Escape` restores the starting width and cancels the resize interaction.
|
|
@@ -37,7 +37,7 @@ Public prop type: `TableRootProps`
|
|
|
37
37
|
| `aria-labelledby` | `string` | `undefined` | Id reference for an external label. |
|
|
38
38
|
| `class` | `string` | `''` | Class names for the root table element. |
|
|
39
39
|
| `context` | `TableContext` | `undefined` | Bindable reference to the active internal table context instance. |
|
|
40
|
-
| `element` | `HTMLTableElement` | `undefined` |
|
|
40
|
+
| `element` | `HTMLTableElement` | `undefined` | A bindable reference to the table element. |
|
|
41
41
|
| `children` | `Snippet` | `undefined` | Composed table parts. |
|
|
42
42
|
|
|
43
43
|
### Behavior notes
|
|
@@ -13,7 +13,7 @@ Public prop type: `TableSortTriggerProps`
|
|
|
13
13
|
|
|
14
14
|
| Prop | Type | Default | Description |
|
|
15
15
|
| -------------- | --------------------------------------------------- | ----------- | --------------------------------------------------------------------------------- |
|
|
16
|
-
| `children` | `Snippet<[TableSortTriggerRenderState]> \| Snippet` | `undefined` |
|
|
16
|
+
| `children` | `Snippet<[TableSortTriggerRenderState]> \| Snippet` | `undefined` | The content of the button. The snippet receives the current `sortDirection`. |
|
|
17
17
|
| `class` | `string` | `''` | CSS class names for the button. |
|
|
18
18
|
| `...restProps` | `HTMLButtonAttributes` | `-` | Additional native button attributes, excluding reserved trigger button semantics. |
|
|
19
19
|
|
package/dist/table/types.d.ts
CHANGED
|
@@ -11,10 +11,10 @@ export type TableColumnProps = {
|
|
|
11
11
|
minWidth?: number;
|
|
12
12
|
maxWidth?: number;
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
* the
|
|
16
|
-
*
|
|
17
|
-
*
|
|
14
|
+
* Keeps the column at an edge of the horizontal scroll: `'left'` at the start, and `'right'` at
|
|
15
|
+
* the end. More than one column can go to the same side. They go in the sequence of the document.
|
|
16
|
+
* The table calculates the position of each one from the widths of the columns already at that
|
|
17
|
+
* side.
|
|
18
18
|
*/
|
|
19
19
|
pin?: TableColumnPin;
|
|
20
20
|
children?: Snippet;
|
|
@@ -90,14 +90,16 @@ export type TableFooterProps = Omit<HTMLAttributes<HTMLTableSectionElement>, 'ch
|
|
|
90
90
|
export type TableRootProps = Omit<HTMLAttributes<HTMLTableElement>, 'children'> & {
|
|
91
91
|
selectionMode?: TableSelectionMode;
|
|
92
92
|
/**
|
|
93
|
-
* How far the roving tab stop
|
|
93
|
+
* How far the roving tab stop goes into the body. The default is `'grid'`.
|
|
94
94
|
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
95
|
+
* The cell navigation has a cost. Each body cell registers itself and calculates its own focus
|
|
96
|
+
* state. A virtualized table does this again for each block of rows that it makes while the user
|
|
97
|
+
* scrolls.
|
|
98
|
+
*
|
|
99
|
+
* With `'row'`, the keyboard still reaches the body, at one focus target for each row. With
|
|
100
|
+
* `'none'`, the body takes no focus. Use `'none'` only when nothing in the body does an action.
|
|
101
|
+
* In each mode, the header keeps its own navigation, and with it the sort control and the width
|
|
102
|
+
* control.
|
|
101
103
|
*/
|
|
102
104
|
keyboardNavigation?: TableKeyboardNavigation;
|
|
103
105
|
selectionBehavior?: TableSelectionBehavior;
|
|
@@ -112,16 +114,15 @@ export type TableRootProps = Omit<HTMLAttributes<HTMLTableElement>, 'children'>
|
|
|
112
114
|
columnWidths?: Map<string, TableColumnWidth>;
|
|
113
115
|
defaultColumnWidths?: Iterable<readonly [string, TableColumnWidth]>;
|
|
114
116
|
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
+
* The width that the table keeps with `min-width` on the server, in px, before the columns
|
|
118
|
+
* register their own widths.
|
|
119
|
+
*
|
|
120
|
+
* On the server, the `<table>` element goes to the output before the column children register.
|
|
121
|
+
* Thus the table does not know its own minimum width, and it takes the width of its container. At
|
|
122
|
+
* the hydration, the column widths can make the table wider, and the layout moves.
|
|
117
123
|
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
* minimum width yet and renders at the container width. On hydration the
|
|
121
|
-
* resolved column widths can push the table wider, producing a layout
|
|
122
|
-
* shift. Set this to the sum of the columns' resolved widths to reserve
|
|
123
|
-
* that space up-front and avoid the jump. Ignored once the real columns
|
|
124
|
-
* register on the client.
|
|
124
|
+
* Set this prop to the sum of the column widths to keep that space from the start. On the client,
|
|
125
|
+
* the component ignores it after the columns register.
|
|
125
126
|
*/
|
|
126
127
|
ssrMinTableWidth?: number;
|
|
127
128
|
disabledKeys?: Iterable<TableSelectionKey>;
|
package/dist/tabs/types.d.ts
CHANGED
|
@@ -6,15 +6,15 @@ export type TabsRootProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'c
|
|
|
6
6
|
keyboardActivation?: TabsKeyboardActivation;
|
|
7
7
|
orientation?: TabsOrientation;
|
|
8
8
|
disabled?: boolean;
|
|
9
|
-
/**
|
|
9
|
+
/** The value of the selected tab. By default it goes in the two directions: use `bind:value`. */
|
|
10
10
|
value?: TabsValue | null;
|
|
11
|
-
/**
|
|
11
|
+
/** The selected value at the start, for when you give no `value`. */
|
|
12
12
|
defaultValue?: TabsValue | null;
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* the new value
|
|
17
|
-
* needs the write-back
|
|
14
|
+
* Give your own code full control of the state. The component stops to write back to `value`, and
|
|
15
|
+
* it reports only through `onChange`. Thus the parent can refuse a change: the parent does not
|
|
16
|
+
* send the new value down. The default is off, because `bind:value` is the usual case and it
|
|
17
|
+
* needs the write-back.
|
|
18
18
|
*/
|
|
19
19
|
controlledValue?: boolean;
|
|
20
20
|
disabledKeys?: Iterable<TabsValue>;
|
|
@@ -63,7 +63,8 @@
|
|
|
63
63
|
- `defaultOpen?: boolean`
|
|
64
64
|
- `onOpenChange?: (open: boolean, details: { reason, event?, cancel(), isCanceled }) => void`
|
|
65
65
|
- Null-first empty contract: when `value` and `defaultValue` are omitted, the empty state is `null`.
|
|
66
|
-
- `TimePicker.Input` exposes `aria-invalid` and `data-invalid` when the current segment draft is not committeable
|
|
66
|
+
- `TimePicker.Input` exposes `aria-invalid` and `data-invalid` when the current segment draft is not committeable, or when the consumer passes `aria-invalid`.
|
|
67
|
+
- `TimePicker.Input` accepts `id` and `name`. Either one renders a hidden but focusable proxy input that carries them. Thus a `<label for>` reaches the segments, and a native form submit reads the committed value. The group keeps `${id}-group`. Autofill is not supported on the proxy (`autocomplete="off"`).
|
|
67
68
|
|
|
68
69
|
## Popover API
|
|
69
70
|
|
|
@@ -83,7 +84,7 @@
|
|
|
83
84
|
|
|
84
85
|
- `TimePicker.Clock` resolves visible wheel columns from root state (`granularity`, `hourCycle`) in stable order: `hour → minute? → second? → dayPeriod?`.
|
|
85
86
|
- `class?: string` uses default layout (`flex gap-2`) when omitted.
|
|
86
|
-
- `column?: Snippet<[ClockColumnInfo]>`
|
|
87
|
+
- `column?: Snippet<[ClockColumnInfo]>` lets you make your own content for each column.
|
|
87
88
|
- `ClockColumnInfo` shape:
|
|
88
89
|
- `type: 'hour' | 'minute' | 'second' | 'dayPeriod'`
|
|
89
90
|
- `label?: string`
|
|
@@ -11,5 +11,5 @@ Description: Group wrapper for rendered time segments; manages focus entry and s
|
|
|
11
11
|
| -------------- | ---------------------------------- | ----------- | ----------------------------------------------------- |
|
|
12
12
|
| `children` | `Snippet<[TimePickerSegmentPart]>` | `undefined` | Optional custom renderer for each segment part. |
|
|
13
13
|
| `class` | `string` | `''` | CSS class names for the group element. |
|
|
14
|
-
| `aria-label` | `string` | `undefined` |
|
|
14
|
+
| `aria-label` | `string` | `undefined` | The accessible name of the input. group. |
|
|
15
15
|
| `...restProps` | `HTMLAttributes<HTMLDivElement>` | `-` | Additional attributes forwarded to the group element. |
|
|
@@ -12,17 +12,29 @@
|
|
|
12
12
|
|
|
13
13
|
type TimePickerInputProps = Omit<
|
|
14
14
|
HTMLAttributes<HTMLDivElement>,
|
|
15
|
-
'children' | 'class' | 'id' | 'role' | 'tabindex'
|
|
15
|
+
'children' | 'class' | 'id' | 'role' | 'tabindex' | 'aria-invalid'
|
|
16
16
|
> & {
|
|
17
|
+
id?: string;
|
|
18
|
+
/**
|
|
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
|
+
*/
|
|
24
|
+
name?: string;
|
|
17
25
|
children?: Snippet<[TimePickerSegmentPart]>;
|
|
18
26
|
class?: string;
|
|
19
27
|
'aria-label'?: string;
|
|
28
|
+
'aria-invalid'?: HTMLAttributes<HTMLDivElement>['aria-invalid'];
|
|
20
29
|
};
|
|
21
30
|
|
|
22
31
|
let {
|
|
32
|
+
id,
|
|
33
|
+
name,
|
|
23
34
|
children,
|
|
24
35
|
class: className = '',
|
|
25
36
|
'aria-label': ariaLabel,
|
|
37
|
+
'aria-invalid': ariaInvalid,
|
|
26
38
|
onmousedown: onMouseDownExternal,
|
|
27
39
|
onfocus: onFocusExternal,
|
|
28
40
|
onblur: onBlurExternal,
|
|
@@ -32,7 +44,28 @@
|
|
|
32
44
|
|
|
33
45
|
const timePicker = useTimePickerContext();
|
|
34
46
|
const segments = $derived(timePicker.getSegments());
|
|
35
|
-
|
|
47
|
+
// With an `id` the group keeps a derived one: the id itself belongs to the proxy input, so
|
|
48
|
+
// a `<label for>` points at something focusable. Mirrors `DatePicker.Input`.
|
|
49
|
+
const groupId = $derived(id ? `${id}-group` : `${timePicker.id}-input`);
|
|
50
|
+
const proxyValue = $derived(timePicker.value ?? '');
|
|
51
|
+
// Invalid is either half: the consumer's (a form rule) or an uncommittable segment draft.
|
|
52
|
+
const isInvalid = $derived(
|
|
53
|
+
ariaInvalid === true || ariaInvalid === 'true' || timePicker.isInvalidDraft
|
|
54
|
+
);
|
|
55
|
+
const shouldRenderProxyInput = $derived(Boolean(id || name));
|
|
56
|
+
const proxyInputStyle =
|
|
57
|
+
'position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0;';
|
|
58
|
+
|
|
59
|
+
function handleProxyFocus(event: FocusEvent) {
|
|
60
|
+
if (timePicker.isDisabled) {
|
|
61
|
+
(event.currentTarget as HTMLElement | null)?.blur();
|
|
62
|
+
timePicker.syncFocusWithin();
|
|
63
|
+
timePicker.setFocusVisible(false);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
timePicker.setFocusVisible(shouldShowFocusVisible(event.currentTarget as HTMLElement));
|
|
67
|
+
timePicker.focusNextPlaceholderOrLastSegment();
|
|
68
|
+
}
|
|
36
69
|
|
|
37
70
|
function handleMouseDown(event: MouseEvent) {
|
|
38
71
|
if (timePicker.isDisabled) return;
|
|
@@ -83,15 +116,35 @@
|
|
|
83
116
|
}
|
|
84
117
|
</script>
|
|
85
118
|
|
|
119
|
+
{#if shouldRenderProxyInput}
|
|
120
|
+
<!--
|
|
121
|
+
A focusable stand-in for the segmented group: it carries the `id` a `<label for>` points
|
|
122
|
+
at and the `name` a native form submit reads, and hands focus straight to the segments.
|
|
123
|
+
-->
|
|
124
|
+
<input
|
|
125
|
+
{id}
|
|
126
|
+
{name}
|
|
127
|
+
value={proxyValue}
|
|
128
|
+
readonly
|
|
129
|
+
tabindex="-1"
|
|
130
|
+
autocomplete="off"
|
|
131
|
+
disabled={timePicker.isDisabled || undefined}
|
|
132
|
+
aria-hidden="true"
|
|
133
|
+
aria-invalid={ariaInvalid}
|
|
134
|
+
style={proxyInputStyle}
|
|
135
|
+
onfocus={handleProxyFocus}
|
|
136
|
+
/>
|
|
137
|
+
{/if}
|
|
138
|
+
|
|
86
139
|
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
|
87
140
|
<!-- svelte-ignore a11y_role_supports_aria_props -->
|
|
88
141
|
<div
|
|
89
|
-
id={
|
|
142
|
+
id={groupId}
|
|
90
143
|
class={className}
|
|
91
144
|
{...restProps}
|
|
92
145
|
role="group"
|
|
93
146
|
aria-label={ariaLabel}
|
|
94
|
-
aria-invalid={
|
|
147
|
+
aria-invalid={isInvalid || undefined}
|
|
95
148
|
aria-required={timePicker.isRequired || undefined}
|
|
96
149
|
tabindex={timePicker.isDisabled || timePicker.focusWithin ? -1 : 0}
|
|
97
150
|
data-disabled={timePicker.isDisabled || undefined}
|
|
@@ -99,7 +152,7 @@
|
|
|
99
152
|
data-open={timePicker.open || undefined}
|
|
100
153
|
data-focus-visible={timePicker.focusVisible || undefined}
|
|
101
154
|
data-focus-within={timePicker.focusWithin || undefined}
|
|
102
|
-
data-invalid={
|
|
155
|
+
data-invalid={isInvalid || undefined}
|
|
103
156
|
onmousedown={composeEventHandlers(handleMouseDown, onMouseDownExternal ?? undefined)}
|
|
104
157
|
onfocus={composeEventHandlers(handleFocus, onFocusExternal ?? undefined)}
|
|
105
158
|
onblur={composeEventHandlers(handleBlur, onBlurExternal ?? undefined)}
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
import { type TimePickerSegmentPart } from '../root/context';
|
|
4
|
-
type TimePickerInputProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class' | 'id' | 'role' | 'tabindex'> & {
|
|
4
|
+
type TimePickerInputProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class' | 'id' | 'role' | 'tabindex' | 'aria-invalid'> & {
|
|
5
|
+
id?: string;
|
|
6
|
+
/**
|
|
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
|
+
*/
|
|
12
|
+
name?: string;
|
|
5
13
|
children?: Snippet<[TimePickerSegmentPart]>;
|
|
6
14
|
class?: string;
|
|
7
15
|
'aria-label'?: string;
|
|
16
|
+
'aria-invalid'?: HTMLAttributes<HTMLDivElement>['aria-invalid'];
|
|
8
17
|
};
|
|
9
18
|
declare const TimePickerInput: import("svelte").Component<TimePickerInputProps, {}, "">;
|
|
10
19
|
type TimePickerInput = ReturnType<typeof TimePickerInput>;
|
|
@@ -26,7 +26,7 @@ Description: State container for segmented time input, popover lifecycle, wheel
|
|
|
26
26
|
| `readonly` | `boolean` | `false` | Prevents value changes while keeping focus/navigation. |
|
|
27
27
|
| `required` | `boolean` | `false` | Propagates required state to input accessibility attributes. |
|
|
28
28
|
| `children` | `Snippet` | `undefined` | Composed `TimePicker` parts. |
|
|
29
|
-
| `class` | `string` | `''` | CSS class names
|
|
29
|
+
| `class` | `string` | `''` | The CSS class names of the root element. |
|
|
30
30
|
| `element` | `HTMLDivElement \| null` | `bindable` | Reference to the root DOM element. |
|
|
31
31
|
| `aria-label` | `string` | `undefined` | Accessible label for the root wrapper. |
|
|
32
32
|
|
|
@@ -10,5 +10,5 @@ Description: Button part that toggles `TimePicker.Popover` and synchronizes focu
|
|
|
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/toggle/README.md
CHANGED
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
## Accessibility
|
|
37
37
|
|
|
38
38
|
- `Toggle.Root` renders a native `<button type="button">`.
|
|
39
|
-
- The selected state
|
|
39
|
+
- The component gives the selected state to assistive technology with `aria-pressed="true" | "false"`.
|
|
40
40
|
- Native keyboard activation is supported with `Enter` and `Space`.
|
|
41
41
|
- `data-focus-visible` follows the shared modality contract and is only exposed for keyboard or virtual focus.
|
|
42
42
|
|
|
@@ -19,6 +19,10 @@
|
|
|
19
19
|
## Usage guidelines
|
|
20
20
|
|
|
21
21
|
- Use `value` / `defaultValue` arrays for both single and multiple selection.
|
|
22
|
+
- Use `bind:value` to hand the group your state, or plain `value` + `onChange` to own it
|
|
23
|
+
yourself. There is no flag to declare which: supplying `value` makes it the source of
|
|
24
|
+
truth either way, and `onChange` always reports.
|
|
25
|
+
- A parent that holds `value` and refuses a change — it sends no new value down — still sees the group move. The group then goes back to the value of the parent at the next render. Refuse a change with a render, and not with silence.
|
|
22
26
|
- Use `selectionMode="single"` when only one toggle can be selected.
|
|
23
27
|
- Use `selectionMode="multiple"` when several toggles can be selected.
|
|
24
28
|
- Use `disallowEmptySelection` when at least one enabled toggle must remain selected.
|
|
@@ -48,4 +52,6 @@
|
|
|
48
52
|
## Notes
|
|
49
53
|
|
|
50
54
|
- Grouped toggles ignore their standalone `selected` and `defaultSelected` props.
|
|
55
|
+
- Removing one `Toggle.Root` from a mounted group is a real selection change: with
|
|
56
|
+
`disallowEmptySelection` the group picks a fallback and fires `onChange`. The removal of the full group is not a change, and it reports nothing. Without this rule, a move to a different screen would look like a press on the last toggle.
|
|
51
57
|
- Form serialization is out of scope for this primitive.
|
|
@@ -3,7 +3,6 @@ export type ToggleGroupSelectionMode = 'single' | 'multiple';
|
|
|
3
3
|
export type ToggleGroupOrientation = 'horizontal' | 'vertical';
|
|
4
4
|
export type CreateToggleGroupContextOptions = {
|
|
5
5
|
initialValue?: ToggleGroupValue[];
|
|
6
|
-
isControlled?: boolean;
|
|
7
6
|
selectionMode?: ToggleGroupSelectionMode;
|
|
8
7
|
isDisabled?: boolean;
|
|
9
8
|
orientation?: ToggleGroupOrientation;
|
|
@@ -23,6 +22,7 @@ export type ToggleGroupContext = {
|
|
|
23
22
|
owner?: symbol;
|
|
24
23
|
}) => void;
|
|
25
24
|
unregisterToggle: (value: ToggleGroupValue) => void;
|
|
25
|
+
setLive: (live: boolean) => void;
|
|
26
26
|
setSelectionMode: (mode: ToggleGroupSelectionMode) => void;
|
|
27
27
|
setDisabled: (disabled: boolean) => void;
|
|
28
28
|
setOrientation: (orientation: ToggleGroupOrientation) => void;
|
|
@@ -29,7 +29,6 @@ export function valuesToArray(values, order) {
|
|
|
29
29
|
return [...orderedValues, ...unknownValues];
|
|
30
30
|
}
|
|
31
31
|
export function createToggleGroupContext(options) {
|
|
32
|
-
const isControlled = options.isControlled ?? false;
|
|
33
32
|
let selectionMode = $state(options.selectionMode ?? 'single');
|
|
34
33
|
let isDisabled = $state(options.isDisabled ?? false);
|
|
35
34
|
let orientation = $state(options.orientation ?? 'horizontal');
|
|
@@ -39,6 +38,10 @@ export function createToggleGroupContext(options) {
|
|
|
39
38
|
let selectedValues = $state(normalizeValues(options.initialValue, options.selectionMode ?? 'single'));
|
|
40
39
|
let focusedValue = $state(null);
|
|
41
40
|
let focusVisible = $state(false);
|
|
41
|
+
// Whether the group is mounted and interactive. Plain `let`, not `$state`: nothing renders
|
|
42
|
+
// from it, and the reads happen while toggles register and unregister, where a reactive
|
|
43
|
+
// read would only add a dependency.
|
|
44
|
+
let isLive = false;
|
|
42
45
|
const toggles = new SvelteMap();
|
|
43
46
|
const toggleOrder = $state([]);
|
|
44
47
|
function getOrderedValues() {
|
|
@@ -115,13 +118,6 @@ export function createToggleGroupContext(options) {
|
|
|
115
118
|
previousValue.some((value, index) => !valuesMatch(value, nextValue[index]));
|
|
116
119
|
if (!didChange)
|
|
117
120
|
return false;
|
|
118
|
-
if (isControlled && changeOptions?.notify !== false) {
|
|
119
|
-
// Controlled mode: request the change and let the parent apply it via props.
|
|
120
|
-
// Mirrors Accordion's identical `setOpen`, which had this guard while this one
|
|
121
|
-
// silently fell through and applied the change the parent might have rejected.
|
|
122
|
-
options.onValueChange?.(nextValue);
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
121
|
selectedValues = normalizedValues;
|
|
126
122
|
if (changeOptions?.notify !== false) {
|
|
127
123
|
options.onValueChange?.(nextValue);
|
|
@@ -129,8 +125,6 @@ export function createToggleGroupContext(options) {
|
|
|
129
125
|
return true;
|
|
130
126
|
}
|
|
131
127
|
function reconcileSelection(changedValue, changeOptions) {
|
|
132
|
-
if (isControlled)
|
|
133
|
-
return;
|
|
134
128
|
const nextValues = new SvelteSet(selectedValues);
|
|
135
129
|
let removedSelectedValue;
|
|
136
130
|
for (const selectedValue of selectedValues) {
|
|
@@ -175,6 +169,13 @@ export function createToggleGroupContext(options) {
|
|
|
175
169
|
}
|
|
176
170
|
reconcileSelection(value, { notify: isExisting });
|
|
177
171
|
}
|
|
172
|
+
// Turned on by the root as it renders and off as it goes away, which is the only way to
|
|
173
|
+
// tell the two unregistrations apart: a toggle removed from a live group leaves a group
|
|
174
|
+
// behind that still has to show something, while a group on its way out has no one left
|
|
175
|
+
// to show anything to.
|
|
176
|
+
function setLive(live) {
|
|
177
|
+
isLive = live;
|
|
178
|
+
}
|
|
178
179
|
function unregisterToggle(value) {
|
|
179
180
|
if (!toggles.has(value))
|
|
180
181
|
return;
|
|
@@ -186,13 +187,20 @@ export function createToggleGroupContext(options) {
|
|
|
186
187
|
if (focusedValue !== null && valuesMatch(focusedValue, value)) {
|
|
187
188
|
focusedValue = null;
|
|
188
189
|
}
|
|
190
|
+
// Only a live group can lose a toggle from under it. Outside that window the toggle is
|
|
191
|
+
// leaving because the group is — on the client while it unmounts, on the server as the
|
|
192
|
+
// markup closes — and picking a fallback would report a selection the user never made,
|
|
193
|
+
// to a consumer already on its way out. Bound to a URL, that fake change navigated
|
|
194
|
+
// straight back to the screen being left.
|
|
195
|
+
if (!isLive)
|
|
196
|
+
return;
|
|
189
197
|
reconcileSelection(value);
|
|
190
198
|
}
|
|
191
199
|
function setSelectionMode(mode) {
|
|
192
200
|
if (selectionMode === mode)
|
|
193
201
|
return;
|
|
194
202
|
selectionMode = mode;
|
|
195
|
-
setSelection(selectedValues
|
|
203
|
+
setSelection(selectedValues);
|
|
196
204
|
reconcileSelection();
|
|
197
205
|
}
|
|
198
206
|
function setDisabled(disabled) {
|
|
@@ -307,6 +315,7 @@ export function createToggleGroupContext(options) {
|
|
|
307
315
|
},
|
|
308
316
|
registerToggle: asCommand(registerToggle),
|
|
309
317
|
unregisterToggle: asCommand(unregisterToggle),
|
|
318
|
+
setLive: asCommand(setLive),
|
|
310
319
|
setSelectionMode: asCommand(setSelectionMode),
|
|
311
320
|
setDisabled: asCommand(setDisabled),
|
|
312
321
|
setOrientation: asCommand(setOrientation),
|