@lumx/core 4.27.1-alpha.0 → 4.27.1-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/components-and-utils.css +93 -8
  2. package/js/components/Combobox/Tests.d.ts +5 -0
  3. package/js/components/Combobox/index.d.ts +1 -1
  4. package/js/components/Combobox/setupCombobox.d.ts +13 -11
  5. package/js/components/Combobox/setupComboboxButton.d.ts +2 -2
  6. package/js/components/Combobox/setupComboboxInput.d.ts +2 -2
  7. package/js/components/Combobox/types.d.ts +55 -17
  8. package/js/components/Composite/CompositeItemDescription.d.ts +17 -0
  9. package/js/components/Composite/CompositeSelectionIcon.d.ts +20 -0
  10. package/js/components/Composite/CompositeStatus.d.ts +82 -0
  11. package/js/components/{Listbox → Composite}/constants.d.ts +3 -1
  12. package/js/components/Composite/index.d.ts +7 -0
  13. package/js/components/Composite/setupComposite.d.ts +28 -0
  14. package/js/components/Composite/types.d.ts +260 -0
  15. package/js/components/Composite/utils.d.ts +19 -0
  16. package/js/components/Listbox/ListboxSection.d.ts +1 -1
  17. package/js/components/Listbox/index.d.ts +2 -5
  18. package/js/components/Listbox/navigation.d.ts +3 -38
  19. package/js/components/Listbox/setupListbox.d.ts +6 -4
  20. package/js/components/Listbox/types.d.ts +6 -125
  21. package/js/components/Listbox/utils.d.ts +4 -28
  22. package/js/components/TreeList/Stories.d.ts +72 -0
  23. package/js/components/TreeList/TestStories.d.ts +88 -0
  24. package/js/components/TreeList/Tests.d.ts +49 -0
  25. package/js/components/TreeList/TreeList.d.ts +60 -0
  26. package/js/components/TreeList/TreeListItem.d.ts +84 -0
  27. package/js/components/TreeList/dom.d.ts +61 -0
  28. package/js/components/TreeList/index.d.ts +9 -0
  29. package/js/components/TreeList/navigation.d.ts +15 -0
  30. package/js/components/TreeList/selection.d.ts +9 -0
  31. package/js/components/TreeList/setupTreeList.d.ts +18 -0
  32. package/js/components/TreeList/types.d.ts +55 -0
  33. package/js/components/TreeList/utils.d.ts +4 -0
  34. package/js/utils/string/includesIgnoreCase.d.ts +2 -0
  35. package/lumx.css +93 -8
  36. package/package.json +2 -2
  37. package/scss/_components_classes.scss +2 -0
  38. package/scss/components/combobox/_index.scss +4 -4
  39. package/scss/components/composite/_index.scss +20 -0
  40. package/scss/components/list-box/_index.scss +2 -13
  41. package/scss/components/tree-list/_index.scss +144 -0
  42. package/scss/core/action-area/_index.scss +3 -4
  43. package/scss/core/action-area/_mixins.scss +11 -0
  44. package/js/components/Listbox/ListboxOptionSelectionIcon.d.ts +0 -13
  45. package/js/components/Listbox/ListboxState.d.ts +0 -105
  46. package/js/components/Listbox/subscribeListboxState.d.ts +0 -24
@@ -0,0 +1,260 @@
1
+ import type { FocusNavigationCallbacks, FocusNavigationController } from '../../utils/focusNavigation';
2
+ /**
3
+ * Pattern of a mounted composite element (from its role, e.g. `'listbox'`, `'grid'` or `'tree'`): each composite
4
+ * specialization (see {@link setupComposite}) defines its own patterns.
5
+ */
6
+ export type CompositeType = string;
7
+ /** Mode of the filter (see {@link CompositeHandle.setFilter}). */
8
+ export type CompositeFilterMode = 'auto' | 'manual';
9
+ /** The current filter of a composite (see {@link CompositeHandle.setFilter}). */
10
+ export interface CompositeFilter {
11
+ /** Filter value (empty string: no filter). */
12
+ value: string;
13
+ /** Filter mode (`'manual'`: the consumer renders the result, the specialization hides nothing). */
14
+ mode: CompositeFilterMode;
15
+ }
16
+ /** Event name for the active state of one item. */
17
+ export type OptionActiveEvent = `optionActive:${string}`;
18
+ /**
19
+ * State of a composite for its live region (see `CompositeStatus`): the item count, the loading state and the
20
+ * open state, as one snapshot (see {@link CompositeEventMap.stateChange}).
21
+ */
22
+ export interface CompositeState {
23
+ /** The number of visible items. */
24
+ optionsLength: number;
25
+ /** The current input value (combobox only, empty string otherwise). */
26
+ inputValue: string;
27
+ /** Whether the item count must not be announced (set by the composite specialization). */
28
+ isCountHidden: boolean;
29
+ /** Whether root skeletons are registered (loading), at once. */
30
+ isLoading: boolean;
31
+ /** Whether the loading lasted long enough to be announced (500ms after skeletons mount while open). */
32
+ isLoadingAnnounced: boolean;
33
+ /**
34
+ * Whether the items are open for the live region: set 100ms after the composite opens (the popover must
35
+ * be in the accessibility tree before the live region content changes), cleared at once when it closes.
36
+ * A standalone composite is always open.
37
+ */
38
+ isOpenForAnnouncement: boolean;
39
+ }
40
+ /** Map of composite event names to their payload types. */
41
+ export interface CompositeEventMap {
42
+ /** Fired when the active descendant changes (visual focus). Payload: the active item id or null. */
43
+ activeDescendantChange: string | null;
44
+ /**
45
+ * Fired when the visible item count changes.
46
+ * Payload: the number of visible items plus the current input value (combobox only), and whether
47
+ * the item count must not be announced (set by the composite specialization).
48
+ */
49
+ optionsChange: {
50
+ optionsLength: number;
51
+ inputValue?: string;
52
+ isCountHidden?: boolean;
53
+ } | undefined;
54
+ /**
55
+ * Fired immediately when the aggregate loading state changes (root skeleton count transitions
56
+ * between 0 and >0). Used for `aria-busy` on the list. The live region reads the loading state and
57
+ * the loading announcement from {@link stateChange}.
58
+ */
59
+ loadingChange: boolean;
60
+ /**
61
+ * Fired when the items become visible or hidden (see {@link CompositeHandle.setOpen}).
62
+ * Inside a combobox, this is the combobox open state. A standalone composite is open from
63
+ * creation and never closes.
64
+ */
65
+ open: boolean;
66
+ /**
67
+ * Fired when any field of the live region state changes (see {@link CompositeState}): the visible count,
68
+ * the loading state, the loading announcement, and the delayed open state. Has a value from creation
69
+ * (`undefined` only as the initial value of the framework hooks, without a handle).
70
+ */
71
+ stateChange: CompositeState | undefined;
72
+ /**
73
+ * Fired only when this item becomes the active descendant (true)
74
+ * or stops being the active descendant (false).
75
+ * Build the key with optionActiveEvent(itemId).
76
+ */
77
+ [event: OptionActiveEvent]: boolean;
78
+ }
79
+ /**
80
+ * Link to a parent widget that owns focus (e.g. a combobox trigger).
81
+ * Without it, the composite is standalone and owns focus itself.
82
+ * The parent sets the open state ({@link CompositeHandle.setOpen}) and observes the composite through its
83
+ * events (e.g. `stateChange`).
84
+ */
85
+ export interface CompositeFocusOwnerLink {
86
+ /** The element that holds DOM focus and `aria-activedescendant`. */
87
+ getFocusOwner(): HTMLElement | null;
88
+ /** Current input value, sent in the `optionsChange` payload. */
89
+ getInputValue?(): string;
90
+ /** Called after the composite element is mounted (e.g. to sync `aria-haspopup` on the trigger). */
91
+ onMount?(element: HTMLElement): void;
92
+ }
93
+ /** Options of {@link setupComposite} (and of its specializations). */
94
+ export interface CompositeOptions {
95
+ /**
96
+ * Called when an item is selected, or when the selection is cleared (see {@link CompositeHandle.select}).
97
+ * `option.value` is the selected item value (empty string when clearing).
98
+ * `element` is the selected item element (null when clearing).
99
+ */
100
+ onSelect?(option: {
101
+ value: string;
102
+ }, element: HTMLElement | null): void;
103
+ /** When true, ArrowDown/ArrowUp wrap around (list mode). Default: false. */
104
+ wrapNavigation?: boolean;
105
+ /** Parent focus owner. Omit for a standalone composite. */
106
+ focusOwner?: CompositeFocusOwnerLink;
107
+ }
108
+ /** Options given to the navigation module of a composite specialization on mount. */
109
+ export interface CompositeNavigationOptions {
110
+ /** The mounted composite element (the navigation module is selected from its role). */
111
+ container: HTMLElement;
112
+ /** Focus state change callbacks (visual focus + `aria-activedescendant`). */
113
+ callbacks: FocusNavigationCallbacks;
114
+ /** Abort signal (unmount). */
115
+ signal: AbortSignal;
116
+ /** Read the active item (from the focus owner `aria-activedescendant`). */
117
+ getActiveItem: () => HTMLElement | null;
118
+ /** When true, ArrowDown/ArrowUp wrap around (list mode only). */
119
+ wrap?: boolean;
120
+ }
121
+ /**
122
+ * Navigation module of a mounted composite: everything that differs between the patterns
123
+ * (listbox, grid, …). Created by the composite specialization from the mounted element.
124
+ */
125
+ export interface CompositeNavigation {
126
+ /** Pattern of the mounted element. */
127
+ readonly type: CompositeType;
128
+ /** The focus navigation controller. */
129
+ readonly focusNav: FocusNavigationController;
130
+ /** Selector of the elements that can become active (options, grid cells, …). */
131
+ readonly cellSelector: string;
132
+ /**
133
+ * Selector of other elements (not cells) whose mousedown must not move DOM focus away from the
134
+ * focus owner (e.g. an expand toggle next to a tree item).
135
+ */
136
+ readonly keepFocusSelector?: string;
137
+ /** Whether a clicked cell selects its item (e.g. false for grid action cells). */
138
+ isOptionCell(cell: HTMLElement): boolean;
139
+ /**
140
+ * Find the cell of a pressed or clicked element (e.g. the tree item of an expand toggle that covers its row).
141
+ * Default: the closest element that matches {@link cellSelector}.
142
+ */
143
+ getCellFromTarget?(target: HTMLElement): HTMLElement | null;
144
+ /** Scroll the active item into view. */
145
+ scrollIntoView(item: HTMLElement): void;
146
+ /**
147
+ * Handle ArrowLeft/ArrowRight on the active item (when the pattern has a horizontal navigation: e.g. move
148
+ * between the grid cells, open or close a tree item). Returns true when the key was handled (an active item
149
+ * exists and the pattern handles the key), even when nothing changed. Without an active item, the key is
150
+ * not handled: a standalone composite consumes it anyway, a combobox input moves its caret
151
+ * (see {@link CompositeHandle.handleKeydown}).
152
+ */
153
+ navigateHorizontal(key: 'ArrowLeft' | 'ArrowRight'): boolean;
154
+ }
155
+ /**
156
+ * What a composite specialization (listbox, …) gives to {@link setupComposite}:
157
+ * its navigation modules, its item count and its filter.
158
+ */
159
+ export interface CompositeSpecialization {
160
+ /** Create the navigation module of the mounted element (`options.container`, selected from its role). */
161
+ createNavigation(options: CompositeNavigationOptions): CompositeNavigation;
162
+ /** Number of visible items with the current filter (`optionsChange` payload and `hasVisibleContent`). */
163
+ getVisibleCount(filter: CompositeFilter): number;
164
+ /** Whether the item count must not be announced with the current filter (`optionsChange` payload). Default: false. */
165
+ isCountHidden?(filter: CompositeFilter): boolean;
166
+ /**
167
+ * Apply the new filter (see {@link CompositeHandle.setFilter}). The composite stores it (see
168
+ * {@link CompositeSetup.getFilter}), and fires `optionsChange` after it when the visible count changed.
169
+ */
170
+ applyFilter(filter: CompositeFilter): void;
171
+ /** Called after the element is mounted, to attach the specialization listeners (removed on `signal` abort). */
172
+ onMount?(element: HTMLElement, signal: AbortSignal): void;
173
+ /** Clear the specialization state (see {@link CompositeHandle.destroy}). */
174
+ destroy?(): void;
175
+ }
176
+ /** Read-only event source of a composite handle (`subscribe` + `getSnapshot`). */
177
+ export interface CompositeEventSource<M = CompositeEventMap> {
178
+ /** Subscribe to an event. Returns an unsubscribe function. */
179
+ subscribe<K extends keyof M>(event: K, callback: (value: M[K]) => void): () => void;
180
+ /** Read the last dispatched value of an event (for pull-based subscribers). */
181
+ getSnapshot<K extends keyof M>(event: K): M[K] | undefined;
182
+ }
183
+ /**
184
+ * Handle returned by {@link setupComposite}: the behavior shared by the composite widgets
185
+ * (one active item among many: listbox, grid, …).
186
+ */
187
+ export interface CompositeHandle extends CompositeEventSource {
188
+ /**
189
+ * Mount the composite element: create the focus navigation and the delegated click/mousedown
190
+ * listeners. In standalone mode, also attach the keyboard and focus listeners.
191
+ * Returns a cleanup function that unmounts it. Mounting another element unmounts the previous one.
192
+ */
193
+ mount(element: HTMLElement): () => void;
194
+ /** Tear down all listeners and state. */
195
+ destroy(): void;
196
+ /** The mounted composite element. */
197
+ readonly element: HTMLElement | null;
198
+ /** Pattern of the mounted element (null while not mounted). */
199
+ readonly type: CompositeType | null;
200
+ /** The active item (null while there is none, or while not mounted). */
201
+ readonly activeItem: HTMLElement | null;
202
+ /** Whether the composite owns focus itself (no `focusOwner` link). */
203
+ readonly isStandalone: boolean;
204
+ /** Whether the items are visible (standalone: always; combobox: the open state). */
205
+ readonly isOpen: boolean;
206
+ /** Whether the composite is in multi-select mode (`aria-multiselectable="true"`). */
207
+ readonly isMultiSelect: boolean;
208
+ /**
209
+ * Whether the composite has visible items or root skeletons. Without them, the mounted element gets
210
+ * `hidden` (unless it holds a status: the live region, e.g. a `Combobox.State` inside the list).
211
+ */
212
+ readonly hasVisibleContent: boolean;
213
+ /**
214
+ * Set whether the items are visible (standalone: always visible; combobox: open state).
215
+ * The loading announcement only fires while the items are visible.
216
+ */
217
+ setOpen(isOpen: boolean): void;
218
+ /**
219
+ * Select an item and fire `onSelect` with its value.
220
+ * With `null`, clear the selection: `onSelect` receives an empty string value and a null element.
221
+ */
222
+ select(option: HTMLElement | null): void;
223
+ /**
224
+ * Handle the navigation keys: arrows, Home/End, PageUp/PageDown, Enter, Space,
225
+ * ArrowLeft/ArrowRight (delegated to the navigation module) and typeahead. The only navigation
226
+ * implementation: a standalone composite calls it from its own keydown, a combobox calls it from
227
+ * the trigger keydown.
228
+ * Returns true when the key was handled: ArrowDown/ArrowUp/Home/End always; Enter/Space and
229
+ * PageUp/PageDown with an active item; ArrowLeft/ArrowRight always in a standalone composite, and in a
230
+ * linked one only when the navigation module handled them.
231
+ */
232
+ handleKeydown(event: KeyboardEvent): boolean;
233
+ /** Replay the pending navigation intent (see {@link activateDefaultItem}). */
234
+ flushPendingNavigation(): void;
235
+ /** Clear the active item and discard the pending navigation intent. No-op while not mounted. */
236
+ clearActiveItem(): void;
237
+ /** Make an item active (e.g. a parent tree item when its group closes). No-op while not mounted. */
238
+ setActiveItem(item: HTMLElement): void;
239
+ /**
240
+ * Make the first selected item active, or else the first (`'first'`) or the last (`'last'`) item.
241
+ * When no item can become active yet (e.g. the combobox popup is opening and its items are not
242
+ * rendered), keep the intent until {@link flushPendingNavigation}. No-op while not mounted.
243
+ */
244
+ activateDefaultItem(edge: 'first' | 'last'): void;
245
+ /**
246
+ * Set the filter value. The specialization applies it:
247
+ * - `'auto'` (default): hide the items that do not match.
248
+ * - `'manual'`: the consumer renders the result (the specialization hides nothing).
249
+ */
250
+ setFilter(filterValue: string, mode?: CompositeFilterMode): void;
251
+ /**
252
+ * Register a skeleton placeholder. Returns a cleanup function (a second call does nothing).
253
+ * A root skeleton makes the composite busy (`loadingChange`). A nested skeleton
254
+ * (`isNested`, inside a nested level of items) does not make it busy, but it starts the loading
255
+ * announcement.
256
+ */
257
+ registerSkeleton(options?: {
258
+ isNested?: boolean;
259
+ }): () => void;
260
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Get the visible label for an item element (its trimmed `textContent`).
3
+ *
4
+ * Used for typeahead matching: the user types the characters they see, which is the
5
+ * item's label — not its `data-value` (which can be an unrelated id).
6
+ */
7
+ export declare function getOptionLabel(option: HTMLElement): string;
8
+ /**
9
+ * Get the value for an item element.
10
+ * Uses `data-value` when set; falls back to the item label (see {@link getOptionLabel}).
11
+ *
12
+ * This is the *selection* value, which may differ from the visible label.
13
+ */
14
+ export declare function getOptionValue(option: HTMLElement): string;
15
+ /** Returns true when an item carries aria-disabled="true". */
16
+ export declare function isOptionDisabled(option: HTMLElement): boolean;
17
+ /** Selector of a selected item (`aria-selected="true"`). */
18
+ export declare const SELECTED_SELECTOR = "[aria-selected=\"true\"]";
19
+ export declare const isSelected: (el: Element) => boolean;
@@ -20,7 +20,7 @@ export interface ListboxSectionProps extends HasClassName {
20
20
  /**
21
21
  * When true, the section is visually rendered (label + content) but hidden from assistive
22
22
  * technology. Used for skeleton-only sections: the visual skeleton provides feedback to
23
- * sighted users, while the live region (`ListboxState`) handles the loading announcement.
23
+ * sighted users, while the live region (`CompositeStatus`) handles the loading announcement.
24
24
  */
25
25
  'aria-hidden'?: boolean;
26
26
  }
@@ -1,5 +1,6 @@
1
1
  export { setupListbox } from './setupListbox';
2
- export type { ListboxEventMap, ListboxFocusOwnerLink, ListboxHandle, ListboxOptions, OptionActiveEvent } from './types';
2
+ export type { ListboxHandle, ListboxType } from './types';
3
+ export { isListboxHandle } from './utils';
3
4
  export { ListboxList } from './ListboxList';
4
5
  export type { ListboxListProps, ListboxListType } from './ListboxList';
5
6
  export { ListboxOption } from './ListboxOption';
@@ -12,7 +13,3 @@ export { ListboxOptionMoreInfo } from './ListboxOptionMoreInfo';
12
13
  export type { ListboxOptionMoreInfoProps, ListboxOptionMoreInfoPropsToOverride, ListboxOptionMoreInfoComponents, } from './ListboxOptionMoreInfo';
13
14
  export { ListboxSection } from './ListboxSection';
14
15
  export type { ListboxSectionProps, ListboxSectionPropsToOverride, ListboxSectionComponents } from './ListboxSection';
15
- export { ListboxState } from './ListboxState';
16
- export type { ListboxStateProps } from './ListboxState';
17
- export { subscribeListboxState } from './subscribeListboxState';
18
- export type { ListboxStateSetters } from './subscribeListboxState';
@@ -1,40 +1,5 @@
1
- import { type FocusNavigationCallbacks, type FocusNavigationController } from '../../utils/focusNavigation';
2
- /** Options shared by the list and grid navigation modules. */
3
- interface NavigationOptions {
4
- /** The mounted listbox (or grid) element. */
5
- container: HTMLElement;
6
- /** Focus state change callbacks (visual focus + `aria-activedescendant`). */
7
- callbacks: FocusNavigationCallbacks;
8
- /** Abort signal (unmount). */
9
- signal: AbortSignal;
10
- /** Read the active item (from the focus owner `aria-activedescendant`). */
11
- getActiveItem: () => HTMLElement | null;
12
- /** When true, ArrowDown/ArrowUp wrap around (list mode only). */
13
- wrap?: boolean;
14
- }
15
- /**
16
- * Navigation module of a mounted listbox: everything that differs between
17
- * the listbox pattern (`role="listbox"`) and the grid pattern (`role="grid"`).
18
- */
19
- export interface ListboxNavigation {
20
- /** Pattern of the mounted element. */
21
- readonly type: 'listbox' | 'grid';
22
- /** The focus navigation controller. */
23
- readonly focusNav: FocusNavigationController;
24
- /** Selector of the elements that can become active (options, or grid cells). */
25
- readonly cellSelector: string;
26
- /** Whether a clicked cell selects its option (false for grid action cells). */
27
- isOptionCell(cell: HTMLElement): boolean;
28
- /** Scroll the active item into view. */
29
- scrollIntoView(item: HTMLElement): void;
30
- /**
31
- * Move the active cell left/right (grid only, when there is an active cell).
32
- * Returns true when the key was handled (grid with an active cell), even at the row edge.
33
- */
34
- navigateHorizontal(key: 'ArrowLeft' | 'ArrowRight'): boolean;
35
- }
1
+ import type { CompositeNavigation, CompositeNavigationOptions } from '../Composite/types';
36
2
  /** Navigation module for the listbox pattern (1D list of `role="option"`). */
37
- export declare function createListNavigation(options: NavigationOptions): ListboxNavigation;
3
+ export declare function createListNavigation(options: CompositeNavigationOptions): CompositeNavigation;
38
4
  /** Navigation module for the grid pattern (rows of `role="gridcell"`: option cell + action cells). */
39
- export declare function createGridNavigation(options: NavigationOptions): ListboxNavigation;
40
- export {};
5
+ export declare function createGridNavigation(options: CompositeNavigationOptions): CompositeNavigation;
@@ -1,9 +1,11 @@
1
- import type { ListboxHandle, ListboxOptions } from './types';
1
+ import type { CompositeOptions } from '../Composite/types';
2
+ import type { ListboxHandle } from './types';
2
3
  /**
3
4
  * Set up listbox behavior (WAI-ARIA listbox or grid pattern) independent of any DOM element.
4
5
  *
5
- * The handle owns the option/section/skeleton registry, the filter state, the focus navigation
6
- * (once an element is mounted), the selection, the loading announcement and the listbox events.
6
+ * Built on the composite base (see {@link setupComposite}: focus owner, focus navigation, keyboard,
7
+ * selection, open state, skeletons, loading announcement and events). The listbox adds the
8
+ * option/section registry, the option filter and the list and grid navigation modules.
7
9
  * The navigation module (listbox or grid pattern) is selected from the element role on mount.
8
10
  *
9
11
  * - Standalone (no `focusOwner` option): the listbox element owns DOM focus and
@@ -14,4 +16,4 @@ import type { ListboxHandle, ListboxOptions } from './types';
14
16
  * @see https://www.w3.org/WAI/ARIA/apg/patterns/listbox/
15
17
  * @see https://www.w3.org/WAI/ARIA/apg/patterns/grid/
16
18
  */
17
- export declare function setupListbox(options?: ListboxOptions): ListboxHandle;
19
+ export declare function setupListbox(options?: CompositeOptions): ListboxHandle;
@@ -1,4 +1,6 @@
1
- import type { FocusNavigationController } from '../../utils/focusNavigation';
1
+ import type { CompositeHandle } from '../Composite/types';
2
+ /** Pattern of a mounted listbox element (from its role): `'listbox'` or `'grid'`. */
3
+ export type ListboxType = 'listbox' | 'grid';
2
4
  /** Section visibility state tracked per registration. */
3
5
  export interface SectionState {
4
6
  hidden: boolean;
@@ -14,136 +16,15 @@ export interface OptionRegistration {
14
16
  callback: (isFiltered: boolean) => void;
15
17
  lastFiltered: boolean;
16
18
  }
17
- /** Event name for the active state of one option. */
18
- export type OptionActiveEvent = `optionActive:${string}`;
19
- /** Map of listbox event names to their payload types. */
20
- export interface ListboxEventMap {
21
- /** Fired when the active descendant changes (visual focus). Payload: the option id or null. */
22
- activeDescendantChange: string | null;
23
- /**
24
- * Fired when the visible option count changes.
25
- * Payload: the number of visible options plus the current input value (combobox only).
26
- */
27
- optionsChange: {
28
- optionsLength: number;
29
- inputValue?: string;
30
- } | undefined;
31
- /**
32
- * Fired immediately when the aggregate loading state changes (skeleton count transitions
33
- * between 0 and >0). Used for empty suppression in ListboxState and for aria-busy on the listbox.
34
- */
35
- loadingChange: boolean;
36
- /**
37
- * Fired after a 500ms debounce when loading persists while the options are visible,
38
- * or immediately when loading ends. Used to control the loading message text in the live region.
39
- */
40
- loadingAnnouncement: boolean;
41
- /**
42
- * Fired when the options become visible or hidden (see {@link ListboxHandle.setOpen}).
43
- * Inside a combobox, this is the combobox open state. A standalone listbox is open from
44
- * creation and never closes. Replayed on subscribe while open.
45
- */
46
- open: boolean;
47
- /**
48
- * Fired only when this option becomes the active descendant (true)
49
- * or stops being the active descendant (false).
50
- * Build the key with optionActiveEvent(optionId).
51
- */
52
- [event: OptionActiveEvent]: boolean;
53
- }
54
19
  /**
55
- * Link to a parent widget that owns focus (e.g. a combobox trigger).
56
- * Without it, the listbox is standalone and owns focus itself.
57
- * The parent observes the listbox through its events (`optionsChange`, `loadingChange`, `open`, …).
20
+ * Handle returned by {@link setupListbox}: the composite handle (WAI-ARIA listbox or grid pattern),
21
+ * plus the option and section registry.
58
22
  */
59
- export interface ListboxFocusOwnerLink {
60
- /** The element that holds DOM focus and `aria-activedescendant`. */
61
- getFocusOwner(): HTMLElement | null;
62
- /** Current input value, sent in the `optionsChange` payload. */
63
- getInputValue?(): string;
64
- /** Called after the listbox (or grid) element is mounted (e.g. to sync `aria-haspopup` on the trigger). */
65
- onMount?(element: HTMLElement): void;
66
- }
67
- /** Options of {@link setupListbox}. */
68
- export interface ListboxOptions {
69
- /**
70
- * Called when an option is selected, or when the selection is cleared (see {@link ListboxHandle.select}).
71
- * `option.value` is the selected option value (empty string when clearing).
72
- * `element` is the selected option element (null when clearing).
73
- */
74
- onSelect?(option: {
75
- value: string;
76
- }, element: HTMLElement | null): void;
77
- /** When true, ArrowDown/ArrowUp wrap around (list mode). Default: false. */
78
- wrapNavigation?: boolean;
79
- /** Parent focus owner. Omit for a standalone listbox. */
80
- focusOwner?: ListboxFocusOwnerLink;
81
- }
82
- /** Handle returned by {@link setupListbox}. */
83
- export interface ListboxHandle {
84
- /**
85
- * Mount the listbox (or grid) element: create the focus navigation and the delegated
86
- * click/mousedown listeners. In standalone mode, also attach the keyboard and focus listeners.
87
- * Returns a cleanup function that unmounts it. Mounting another element unmounts the previous one.
88
- */
89
- mount(element: HTMLElement): () => void;
90
- /** Tear down all listeners and state. */
91
- destroy(): void;
92
- /** Subscribe to a listbox event. Returns an unsubscribe function. */
93
- subscribe<K extends keyof ListboxEventMap>(event: K, callback: (value: ListboxEventMap[K]) => void): () => void;
94
- /** Read the last dispatched value of an event (for pull-based subscribers). */
95
- getSnapshot<K extends keyof ListboxEventMap>(event: K): ListboxEventMap[K] | undefined;
96
- /** The mounted listbox/grid element. */
97
- readonly element: HTMLElement | null;
98
- /** Pattern of the mounted element: `'listbox'` or `'grid'` (null while not mounted). */
99
- readonly type: 'listbox' | 'grid' | null;
100
- /** The focus navigation controller (null while not mounted). */
101
- readonly focusNav: FocusNavigationController | null;
102
- /** Whether the listbox owns focus itself (no `focusOwner` link). */
103
- readonly isStandalone: boolean;
104
- /** Whether the options are visible (standalone: always; combobox: the open state). */
105
- readonly isOpen: boolean;
106
- /** Whether the listbox is in multi-select mode (`aria-multiselectable="true"`). */
107
- readonly isMultiSelect: boolean;
108
- /** Whether any skeleton placeholders are registered (loading). */
109
- readonly isLoading: boolean;
110
- /**
111
- * Whether the listbox has visible options or skeletons. Without them, the mounted element gets `hidden`
112
- * (unless it holds a status: the live region, e.g. a `Combobox.State` inside the list).
113
- */
114
- readonly hasVisibleContent: boolean;
115
- /**
116
- * Set whether the options are visible (standalone: always visible; combobox: open state).
117
- * The loading announcement only fires while the options are visible.
118
- */
119
- setOpen(isOpen: boolean): void;
120
- /**
121
- * Select an option and fire `onSelect` with its value.
122
- * With `null`, clear the selection: `onSelect` receives an empty string value and a null element.
123
- */
124
- select(option: HTMLElement | null): void;
125
- /**
126
- * Handle the listbox navigation keys: arrows, Home/End, PageUp/PageDown, Enter, Space,
127
- * grid cells (ArrowLeft/ArrowRight) and typeahead. The only navigation implementation: a
128
- * standalone listbox calls it from its own keydown, a combobox calls it from the trigger keydown.
129
- * Returns true when the key was handled (Enter/Space need an active option, PageUp/PageDown too).
130
- */
131
- handleKeydown(event: KeyboardEvent): boolean;
132
- /**
133
- * Move the active cell left/right (grid pattern only, when there is an active cell).
134
- * Returns true when the key was handled.
135
- */
136
- navigateHorizontal(key: 'ArrowLeft' | 'ArrowRight'): boolean;
137
- /** Replay the pending navigation intent (see {@link FocusNavigationController.goTo}). */
138
- flushPendingNavigation(): void;
23
+ export interface ListboxHandle extends CompositeHandle {
139
24
  /** Register an option element for filter notifications. Returns a cleanup function. */
140
25
  registerOption(element: HTMLElement, onFilterChange: (isFiltered: boolean) => void): () => void;
141
- /** Set the filter value and notify all registered options. */
142
- setFilter(filterValue: string): void;
143
26
  /** Re-evaluate the filter state of a single registered option. */
144
27
  refilterOption(element: HTMLElement): void;
145
28
  /** Register a section element for state notifications. Returns a cleanup function. */
146
29
  registerSection(element: HTMLElement, onChange: (state: SectionState) => void): () => void;
147
- /** Register a skeleton placeholder. Returns a cleanup function. */
148
- registerSkeleton(): () => void;
149
30
  }
@@ -1,30 +1,6 @@
1
- import type { OptionRegistration, SectionRegistration } from './types';
2
- /**
3
- * Get the value for an option element.
4
- * Uses `data-value` when set; falls back to the element's trimmed `textContent`.
5
- *
6
- * This is the *selection* value , which may differ from the visible label
7
- */
8
- export declare function getOptionValue(option: HTMLElement): string;
9
- /**
10
- * Get the visible label for an option element (its trimmed `textContent`).
11
- *
12
- * Used for typeahead matching: the user types the characters they see, which is the
13
- * option's label — not its `data-value` (which can be an unrelated id).
14
- */
15
- export declare function getOptionLabel(option: HTMLElement): string;
16
- /** Returns true when an option carries aria-disabled="true". */
17
- export declare function isOptionDisabled(option: HTMLElement): boolean;
1
+ import type { CompositeHandle } from '../Composite/types';
2
+ import type { ListboxHandle } from './types';
3
+ /** Whether a composite handle is a listbox handle (it has the option registry). */
4
+ export declare function isListboxHandle(handle: CompositeHandle | null | undefined): handle is ListboxHandle;
18
5
  /** Returns true when the cell is NOT the first gridcell in its row (i.e., it's an action cell). */
19
6
  export declare function isActionCell(cell: HTMLElement): boolean;
20
- export declare const isSelected: (el: Element) => boolean;
21
- /**
22
- * Compute the current state of a section and notify when it changed.
23
- *
24
- * Section state:
25
- * - `hidden`: true when the section has registered options but all are filtered out.
26
- * - `aria-hidden`: true when the section has no registered options at all (skeleton-only).
27
- *
28
- * At most one of `hidden` / `aria-hidden` is true at a time.
29
- */
30
- export declare function notifySection(sectionElement: HTMLElement, sectionRegistrations: Map<HTMLElement, SectionRegistration>, optionRegistrations: Map<HTMLElement, OptionRegistration>, force?: boolean): void;
@@ -0,0 +1,72 @@
1
+ import type { SetupStoriesOptions } from '@lumx/core/stories/types';
2
+ import type { TreeListComponents } from './Tests';
3
+ /**
4
+ * Setup the TreeList demo stories for a specific framework (React or Vue): a standalone tree, or a tree in a
5
+ * combobox. Framework-specific components and decorators are injected via options.
6
+ */
7
+ export declare function setup({ components: { TreeList, TreeListItem, Combobox }, decorators: { withValueOnChange }, }: SetupStoriesOptions<{
8
+ components: TreeListComponents;
9
+ decorators: 'withValueOnChange';
10
+ }>): {
11
+ meta: {
12
+ component: any;
13
+ };
14
+ Standalone: {
15
+ args: {
16
+ value: string;
17
+ };
18
+ decorators: ((story: any, context: any) => any)[];
19
+ render: ({ value, onChange }: any) => import("react").JSX.Element;
20
+ };
21
+ StandaloneMultipleSelection: {
22
+ args: {
23
+ value: string[];
24
+ };
25
+ decorators: ((story: any, context: any) => any)[];
26
+ render: ({ value, onChange }: any) => import("react").JSX.Element;
27
+ };
28
+ InComboboxInput: {
29
+ args: {
30
+ value: {
31
+ text: string;
32
+ selected: string;
33
+ };
34
+ };
35
+ decorators: ((story: any, context: any) => any)[];
36
+ render: ({ value, onUpdate }: any) => import("react").JSX.Element;
37
+ };
38
+ InComboboxInline: {
39
+ args: {
40
+ value: {
41
+ text: string;
42
+ selected: string;
43
+ };
44
+ };
45
+ decorators: ((story: any, context: any) => any)[];
46
+ render: ({ value, onUpdate }: any) => import("react").JSX.Element;
47
+ };
48
+ InComboboxButton: {
49
+ args: {
50
+ value: string;
51
+ };
52
+ decorators: ((story: any, context: any) => any)[];
53
+ render: ({ value, onChange }: any) => import("react").JSX.Element;
54
+ };
55
+ InComboboxMultipleSelection: {
56
+ args: {
57
+ value: {
58
+ text: string;
59
+ selected: string[];
60
+ };
61
+ };
62
+ decorators: ((story: any, context: any) => any)[];
63
+ render: ({ value, onUpdate }: any) => import("react").JSX.Element;
64
+ };
65
+ LazyParentItem: {
66
+ args: {
67
+ snacks: string;
68
+ };
69
+ decorators: ((story: any, context: any) => any)[];
70
+ render: ({ snacks, onSnacksChange }: any) => import("react").JSX.Element;
71
+ };
72
+ };