@pixum/combobox 5.10.5 → 5.10.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/lib/ComboBox.d.ts +32 -6
- package/lib/ComboBox.js +212 -77
- package/lib/ComboBox.js.map +1 -1
- package/lib/ComboBox.module.css +1 -0
- package/lib/hooks/index.d.ts +2 -0
- package/lib/hooks/index.js +2 -0
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useComboBox.d.ts +60 -0
- package/lib/hooks/useComboBox.js +226 -0
- package/lib/hooks/useComboBox.js.map +1 -0
- package/lib/hooks/useComboBoxFocus.d.ts +35 -0
- package/lib/hooks/useComboBoxFocus.js +49 -0
- package/lib/hooks/useComboBoxFocus.js.map +1 -0
- package/lib/hooks/useIsDesktopScreenWidth.d.ts +5 -0
- package/lib/hooks/useIsDesktopScreenWidth.js +34 -24
- package/lib/hooks/useIsDesktopScreenWidth.js.map +1 -1
- package/lib/index.d.ts +4 -4
- package/lib/index.js +2 -3
- package/lib/index.js.map +1 -1
- package/lib/partials/ComboBoxNoResults.d.ts +14 -0
- package/lib/partials/ComboBoxNoResults.js +18 -0
- package/lib/partials/ComboBoxNoResults.js.map +1 -0
- package/lib/partials/ComboBoxOptions.d.ts +16 -5
- package/lib/partials/ComboBoxOptions.js +25 -21
- package/lib/partials/ComboBoxOptions.js.map +1 -1
- package/lib/partials/ComboBoxOptionsGroup.d.ts +15 -0
- package/lib/partials/ComboBoxOptionsGroup.js +31 -0
- package/lib/partials/ComboBoxOptionsGroup.js.map +1 -0
- package/lib/partials/ComboBoxOptionsItems.d.ts +32 -17
- package/lib/partials/ComboBoxOptionsItems.js +46 -14
- package/lib/partials/ComboBoxOptionsItems.js.map +1 -1
- package/lib/partials/ComboBoxOptionsSlot.d.ts +17 -16
- package/lib/partials/ComboBoxOptionsSlot.js +26 -11
- package/lib/partials/ComboBoxOptionsSlot.js.map +1 -1
- package/lib/partials/index.d.ts +2 -1
- package/lib/partials/index.js +2 -1
- package/lib/partials/index.js.map +1 -1
- package/lib/types.d.ts +183 -45
- package/lib/utils/index.d.ts +1 -2
- package/lib/utils/index.js +1 -2
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/options.d.ts +77 -0
- package/lib/utils/options.js +145 -0
- package/lib/utils/options.js.map +1 -0
- package/package.json +8 -8
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { findEnabledIndex } from '../utils';
|
|
4
|
+
/**
|
|
5
|
+
* Headless controller for the WAI-ARIA combobox pattern.
|
|
6
|
+
*
|
|
7
|
+
* The focus never moves into the list: the active option is communicated
|
|
8
|
+
* exclusively via `aria-activedescendant`, which keeps the search field
|
|
9
|
+
* typeable while the user navigates.
|
|
10
|
+
*
|
|
11
|
+
* Keyboard (APG combobox with listbox popup):
|
|
12
|
+
* - closed: ArrowUp/ArrowDown/Alt+ArrowDown, Enter, Space open the list
|
|
13
|
+
* - open: ArrowUp/ArrowDown navigate (skipping disabled options),
|
|
14
|
+
* Home/End jump to the first/last option, Enter selects,
|
|
15
|
+
* Escape and Alt+ArrowUp close, Tab closes and lets the focus move on
|
|
16
|
+
* - Space selects while the field is not typeable; as soon as a search field
|
|
17
|
+
* is open it types a space character instead, as APG requires
|
|
18
|
+
*
|
|
19
|
+
* On open the starting point is always the selected option, so ArrowDown moves
|
|
20
|
+
* to the option right after it.
|
|
21
|
+
*
|
|
22
|
+
* @param options - Configuration of the combobox
|
|
23
|
+
* @returns ARIA props, the keyboard handler and the active option
|
|
24
|
+
*/
|
|
25
|
+
export function useComboBox({ options, isOpen, open, close, selectedValues, onSelect, listboxId, searchable = true, multiple = false, openOnEnter = true, }) {
|
|
26
|
+
var _a;
|
|
27
|
+
const [activeIndex, setActiveIndex] = useState(null);
|
|
28
|
+
/**
|
|
29
|
+
* Read inside effects only. Keeping the selection in a ref avoids re-running
|
|
30
|
+
* the "open" effect when a consumer passes a new array instance per render.
|
|
31
|
+
*/
|
|
32
|
+
const selectedValuesRef = useRef(selectedValues);
|
|
33
|
+
selectedValuesRef.current = selectedValues;
|
|
34
|
+
/** Tracks the closed -> open edge so navigation is not reset while open. */
|
|
35
|
+
const wasOpen = useRef(false);
|
|
36
|
+
/**
|
|
37
|
+
* Active option requested while the list was still closed (Home/End). The
|
|
38
|
+
* open effect consumes it instead of falling back to the selected option.
|
|
39
|
+
*/
|
|
40
|
+
const pendingActiveIndex = useRef(null);
|
|
41
|
+
/** Typing is only possible while an open search field is rendered. */
|
|
42
|
+
const canType = isOpen && searchable;
|
|
43
|
+
/**
|
|
44
|
+
* Sets the starting point when the list opens: the selected option, or the
|
|
45
|
+
* first enabled one as a fallback.
|
|
46
|
+
*/
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (!isOpen) {
|
|
49
|
+
wasOpen.current = false;
|
|
50
|
+
setActiveIndex(null);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (wasOpen.current)
|
|
54
|
+
return;
|
|
55
|
+
wasOpen.current = true;
|
|
56
|
+
const pending = pendingActiveIndex.current;
|
|
57
|
+
pendingActiveIndex.current = null;
|
|
58
|
+
if (pending !== null) {
|
|
59
|
+
setActiveIndex(pending);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const selectedIndex = options.findIndex(option => !option.disabled && selectedValuesRef.current.includes(option.value));
|
|
63
|
+
setActiveIndex(selectedIndex !== -1 ? selectedIndex : findEnabledIndex(options, -1, 1));
|
|
64
|
+
}, [isOpen, options]);
|
|
65
|
+
/**
|
|
66
|
+
* Keeps the active index valid while the list is filtered down.
|
|
67
|
+
*/
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
if (!isOpen)
|
|
70
|
+
return;
|
|
71
|
+
setActiveIndex(previous => {
|
|
72
|
+
const isStillValid = previous !== null &&
|
|
73
|
+
previous < options.length &&
|
|
74
|
+
!options[previous].disabled;
|
|
75
|
+
if (isStillValid)
|
|
76
|
+
return previous;
|
|
77
|
+
return findEnabledIndex(options, -1, 1);
|
|
78
|
+
});
|
|
79
|
+
}, [isOpen, options]);
|
|
80
|
+
/**
|
|
81
|
+
* Moves the active option by `delta` positions, wrapping around and skipping
|
|
82
|
+
* disabled options.
|
|
83
|
+
*
|
|
84
|
+
* @param delta - Number of positions to move; negative moves backwards
|
|
85
|
+
*/
|
|
86
|
+
const move = useCallback((delta) => setActiveIndex(previous => findEnabledIndex(options, previous !== null && previous !== void 0 ? previous : (delta > 0 ? -1 : 0), delta)), [options]);
|
|
87
|
+
/**
|
|
88
|
+
* Selects the active option. In single select the list closes afterwards,
|
|
89
|
+
* in multi select it stays open so further options can be toggled.
|
|
90
|
+
*/
|
|
91
|
+
const selectActiveOption = useCallback(() => {
|
|
92
|
+
if (activeIndex === null)
|
|
93
|
+
return;
|
|
94
|
+
const option = options[activeIndex];
|
|
95
|
+
if (!option || option.disabled)
|
|
96
|
+
return;
|
|
97
|
+
onSelect(option.value);
|
|
98
|
+
}, [activeIndex, options, onSelect]);
|
|
99
|
+
const onKeyDown = useCallback(event => {
|
|
100
|
+
switch (event.key) {
|
|
101
|
+
case 'ArrowDown':
|
|
102
|
+
case 'ArrowUp': {
|
|
103
|
+
event.preventDefault();
|
|
104
|
+
if (!isOpen) {
|
|
105
|
+
open();
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
// Alt+ArrowUp closes and keeps the current selection.
|
|
109
|
+
if (event.key === 'ArrowUp' && event.altKey) {
|
|
110
|
+
close();
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
// Alt+ArrowDown only opens, it never moves the active option.
|
|
114
|
+
if (event.altKey)
|
|
115
|
+
break;
|
|
116
|
+
move(event.key === 'ArrowDown' ? 1 : -1);
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
case 'Enter': {
|
|
120
|
+
if (!isOpen) {
|
|
121
|
+
if (!openOnEnter)
|
|
122
|
+
break;
|
|
123
|
+
// preventDefault stops an implicit form submit.
|
|
124
|
+
event.preventDefault();
|
|
125
|
+
open();
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
if (activeIndex === null)
|
|
129
|
+
break;
|
|
130
|
+
event.preventDefault();
|
|
131
|
+
selectActiveOption();
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
case ' ': {
|
|
135
|
+
// An open search field must receive a real space character.
|
|
136
|
+
if (canType)
|
|
137
|
+
break;
|
|
138
|
+
event.preventDefault();
|
|
139
|
+
if (isOpen && activeIndex !== null) {
|
|
140
|
+
selectActiveOption();
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
open();
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
case 'Escape': {
|
|
147
|
+
if (!isOpen)
|
|
148
|
+
break;
|
|
149
|
+
event.preventDefault();
|
|
150
|
+
close();
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
case 'Tab': {
|
|
154
|
+
// No preventDefault: the focus moves on, the popup just closes.
|
|
155
|
+
if (isOpen)
|
|
156
|
+
close(false);
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
case 'Home':
|
|
160
|
+
case 'End': {
|
|
161
|
+
if (options.length === 0)
|
|
162
|
+
break;
|
|
163
|
+
event.preventDefault();
|
|
164
|
+
const targetIndex = event.key === 'Home'
|
|
165
|
+
? findEnabledIndex(options, -1, 1)
|
|
166
|
+
: findEnabledIndex(options, options.length, -1);
|
|
167
|
+
// Closed: open first, the effect picks the index up from the ref.
|
|
168
|
+
if (!isOpen) {
|
|
169
|
+
pendingActiveIndex.current = targetIndex;
|
|
170
|
+
open();
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
setActiveIndex(targetIndex);
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
default:
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
}, [
|
|
180
|
+
isOpen,
|
|
181
|
+
open,
|
|
182
|
+
close,
|
|
183
|
+
move,
|
|
184
|
+
activeIndex,
|
|
185
|
+
selectActiveOption,
|
|
186
|
+
canType,
|
|
187
|
+
openOnEnter,
|
|
188
|
+
options,
|
|
189
|
+
]);
|
|
190
|
+
const activeOptionId = isOpen && activeIndex !== null ? (_a = options[activeIndex]) === null || _a === void 0 ? void 0 : _a.id : undefined;
|
|
191
|
+
/**
|
|
192
|
+
* Scrolls the active option into view. Purely DOM based, so it works for the
|
|
193
|
+
* desktop popover and the bottom sheet alike.
|
|
194
|
+
*/
|
|
195
|
+
useEffect(() => {
|
|
196
|
+
if (!activeOptionId)
|
|
197
|
+
return;
|
|
198
|
+
const frameId = requestAnimationFrame(() => {
|
|
199
|
+
var _a;
|
|
200
|
+
(_a = document
|
|
201
|
+
.getElementById(activeOptionId)) === null || _a === void 0 ? void 0 : _a.scrollIntoView({ block: 'nearest' });
|
|
202
|
+
});
|
|
203
|
+
return () => cancelAnimationFrame(frameId);
|
|
204
|
+
}, [activeOptionId]);
|
|
205
|
+
const comboboxAriaProps = useMemo(() => ({
|
|
206
|
+
role: 'combobox',
|
|
207
|
+
'aria-expanded': isOpen,
|
|
208
|
+
'aria-haspopup': 'listbox',
|
|
209
|
+
'aria-controls': isOpen ? listboxId : undefined,
|
|
210
|
+
'aria-activedescendant': activeOptionId,
|
|
211
|
+
'aria-autocomplete': searchable ? 'list' : 'none',
|
|
212
|
+
}), [isOpen, listboxId, activeOptionId, searchable]);
|
|
213
|
+
const listboxAriaProps = useMemo(() => ({
|
|
214
|
+
role: 'listbox',
|
|
215
|
+
id: listboxId,
|
|
216
|
+
'aria-multiselectable': multiple || undefined,
|
|
217
|
+
}), [listboxId, multiple]);
|
|
218
|
+
return {
|
|
219
|
+
comboboxAriaProps,
|
|
220
|
+
listboxAriaProps,
|
|
221
|
+
onKeyDown,
|
|
222
|
+
activeOptionId,
|
|
223
|
+
activeIndex,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
//# sourceMappingURL=useComboBox.js.map
|
|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AAC;QACL,IAAI,EAAE,SAAS;QACf,EAAE,EAAE,SAAS;QACb,sBAAsB,EAAE,QAAQ,IAAI,SAAS;KAC9C,CAAC,EACF,CAAC,SAAS,EAAE,QAAQ,CAAC,CACtB,CAAA;IAED,OAAO;QACL,iBAAiB;QACjB,gBAAgB;QAChB,SAAS;QACT,cAAc;QACd,WAAW;KACZ,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface UseComboBoxFocusResult {
|
|
2
|
+
/**
|
|
3
|
+
* Ref for the trigger field (SelectInput).
|
|
4
|
+
*
|
|
5
|
+
* `| null` is part of the type parameter: since React 19 `useRef<T>(null)`
|
|
6
|
+
* returns `RefObject<T | null>` instead of the old `RefObject<T>`.
|
|
7
|
+
*/
|
|
8
|
+
triggerRef: React.RefObject<HTMLInputElement | null>;
|
|
9
|
+
/**
|
|
10
|
+
* Callback ref for the search field. Focuses it the moment it is mounted -
|
|
11
|
+
* in the desktop popover as well as in the bottom sheet.
|
|
12
|
+
*/
|
|
13
|
+
searchInputRef: (input: HTMLInputElement | null) => void;
|
|
14
|
+
/** Moves the focus back to the trigger without re-opening the list. */
|
|
15
|
+
returnFocusToTrigger: () => void;
|
|
16
|
+
/**
|
|
17
|
+
* Whether the current focus event on the trigger was caused by
|
|
18
|
+
* `returnFocusToTrigger` and must therefore not open the list.
|
|
19
|
+
*/
|
|
20
|
+
isReturningFocus: () => boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Bundles the focus choreography of the ComboBox:
|
|
24
|
+
*
|
|
25
|
+
* - opening moves the focus into the search field as soon as it mounts,
|
|
26
|
+
* - closing moves it back to the trigger,
|
|
27
|
+
* - the focus handler of the trigger can tell a returning focus from a real
|
|
28
|
+
* user focus and therefore does not re-open the list it just closed.
|
|
29
|
+
*
|
|
30
|
+
* The search field is wired up with a callback ref, so both the popover and the
|
|
31
|
+
* bottom sheet share one implementation and no polling is needed.
|
|
32
|
+
*
|
|
33
|
+
* @returns Refs and helpers for the focus handling
|
|
34
|
+
*/
|
|
35
|
+
export declare function useComboBoxFocus(): UseComboBoxFocusResult;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useCallback, useEffect, useRef } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Bundles the focus choreography of the ComboBox:
|
|
5
|
+
*
|
|
6
|
+
* - opening moves the focus into the search field as soon as it mounts,
|
|
7
|
+
* - closing moves it back to the trigger,
|
|
8
|
+
* - the focus handler of the trigger can tell a returning focus from a real
|
|
9
|
+
* user focus and therefore does not re-open the list it just closed.
|
|
10
|
+
*
|
|
11
|
+
* The search field is wired up with a callback ref, so both the popover and the
|
|
12
|
+
* bottom sheet share one implementation and no polling is needed.
|
|
13
|
+
*
|
|
14
|
+
* @returns Refs and helpers for the focus handling
|
|
15
|
+
*/
|
|
16
|
+
export function useComboBoxFocus() {
|
|
17
|
+
const triggerRef = useRef(null);
|
|
18
|
+
const returningFocus = useRef(false);
|
|
19
|
+
const frameRef = useRef(null);
|
|
20
|
+
useEffect(() => () => {
|
|
21
|
+
if (frameRef.current !== null)
|
|
22
|
+
cancelAnimationFrame(frameRef.current);
|
|
23
|
+
}, []);
|
|
24
|
+
const searchInputRef = useCallback((input) => {
|
|
25
|
+
if (!input)
|
|
26
|
+
return;
|
|
27
|
+
input.focus();
|
|
28
|
+
// One frame later, so Safari does not drop the selection again when
|
|
29
|
+
// `readOnly` changes within the same render.
|
|
30
|
+
requestAnimationFrame(() => {
|
|
31
|
+
var _a;
|
|
32
|
+
(_a = input.setSelectionRange) === null || _a === void 0 ? void 0 : _a.call(input, 0, input.value.length);
|
|
33
|
+
});
|
|
34
|
+
}, []);
|
|
35
|
+
const returnFocusToTrigger = useCallback(() => {
|
|
36
|
+
returningFocus.current = true;
|
|
37
|
+
// Wait for the commit that unmounts the popover / bottom sheet, otherwise
|
|
38
|
+
// the focus would end up on `<body>`.
|
|
39
|
+
frameRef.current = requestAnimationFrame(() => {
|
|
40
|
+
var _a;
|
|
41
|
+
(_a = triggerRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
42
|
+
// `focus()` dispatches synchronously, so the flag has served its purpose.
|
|
43
|
+
returningFocus.current = false;
|
|
44
|
+
});
|
|
45
|
+
}, []);
|
|
46
|
+
const isReturningFocus = useCallback(() => returningFocus.current, []);
|
|
47
|
+
return { triggerRef, searchInputRef, returnFocusToTrigger, isReturningFocus };
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=useComboBoxFocus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useComboBoxFocus.js","sourceRoot":"","sources":["../../src/hooks/useComboBoxFocus.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAwBtD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,gBAAgB;IAC9B,MAAM,UAAU,GAAG,MAAM,CAAmB,IAAI,CAAC,CAAA;IACjD,MAAM,cAAc,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;IACpC,MAAM,QAAQ,GAAG,MAAM,CAAgB,IAAI,CAAC,CAAA;IAE5C,SAAS,CACP,GAAG,EAAE,CAAC,GAAG,EAAE;QACT,IAAI,QAAQ,CAAC,OAAO,KAAK,IAAI;YAAE,oBAAoB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;IACvE,CAAC,EACD,EAAE,CACH,CAAA;IAED,MAAM,cAAc,GAAG,WAAW,CAAC,CAAC,KAA8B,EAAE,EAAE;QACpE,IAAI,CAAC,KAAK;YAAE,OAAM;QAElB,KAAK,CAAC,KAAK,EAAE,CAAA;QAEb,oEAAoE;QACpE,6CAA6C;QAC7C,qBAAqB,CAAC,GAAG,EAAE;;YACzB,MAAA,KAAK,CAAC,iBAAiB,sDAAG,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;QAClD,CAAC,CAAC,CAAA;IACJ,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,MAAM,oBAAoB,GAAG,WAAW,CAAC,GAAG,EAAE;QAC5C,cAAc,CAAC,OAAO,GAAG,IAAI,CAAA;QAE7B,0EAA0E;QAC1E,sCAAsC;QACtC,QAAQ,CAAC,OAAO,GAAG,qBAAqB,CAAC,GAAG,EAAE;;YAC5C,MAAA,UAAU,CAAC,OAAO,0CAAE,KAAK,EAAE,CAAA;YAC3B,0EAA0E;YAC1E,cAAc,CAAC,OAAO,GAAG,KAAK,CAAA;QAChC,CAAC,CAAC,CAAA;IACJ,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,MAAM,gBAAgB,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;IAEtE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,CAAA;AAC/E,CAAC"}
|
|
@@ -1,36 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
import { useSyncExternalStore } from 'react';
|
|
3
|
+
const DESKTOP_MEDIA_QUERY = '(min-width: 960px)';
|
|
2
4
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
+
* Subscribes to the MediaQueryList. Using `change` instead of `resize` means
|
|
6
|
+
* there is only one re-render when the breakpoint is actually crossed.
|
|
5
7
|
*
|
|
6
|
-
* @
|
|
8
|
+
* @param onStoreChange - Callback invoked when the breakpoint match changes
|
|
9
|
+
* @returns An unsubscribe function that removes the listener
|
|
7
10
|
*/
|
|
8
|
-
function
|
|
9
|
-
|
|
11
|
+
function subscribe(onStoreChange) {
|
|
12
|
+
if (typeof window === 'undefined' || !window.matchMedia) {
|
|
13
|
+
return () => { };
|
|
14
|
+
}
|
|
15
|
+
const mediaQueryList = window.matchMedia(DESKTOP_MEDIA_QUERY);
|
|
16
|
+
mediaQueryList.addEventListener('change', onStoreChange);
|
|
17
|
+
return () => mediaQueryList.removeEventListener('change', onStoreChange);
|
|
10
18
|
}
|
|
11
19
|
/**
|
|
12
|
-
*
|
|
20
|
+
* Client snapshot: the current match state of the desktop breakpoint.
|
|
13
21
|
*
|
|
14
|
-
* @returns True if the
|
|
22
|
+
* @returns True if the desktop breakpoint currently matches, false otherwise
|
|
15
23
|
*/
|
|
16
|
-
function
|
|
17
|
-
if (
|
|
18
|
-
return
|
|
19
|
-
|
|
24
|
+
function getSnapshot() {
|
|
25
|
+
if (typeof window === 'undefined' || !window.matchMedia)
|
|
26
|
+
return false;
|
|
27
|
+
return window.matchMedia(DESKTOP_MEDIA_QUERY).matches;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Server snapshot: deliberately `false` (mobile first), so that the server
|
|
31
|
+
* render and the first client render match deterministically.
|
|
32
|
+
*
|
|
33
|
+
* @returns Always false
|
|
34
|
+
*/
|
|
35
|
+
function getServerSnapshot() {
|
|
20
36
|
return false;
|
|
21
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Custom hook that detects whether the viewport width is desktop size (>= 960px).
|
|
40
|
+
*
|
|
41
|
+
* @returns True if the viewport width is 960px or greater, false otherwise
|
|
42
|
+
*/
|
|
22
43
|
export function useIsDesktopScreenWidth() {
|
|
23
|
-
|
|
24
|
-
useEffect(() => {
|
|
25
|
-
const checkScreenSize = () => {
|
|
26
|
-
setIsDesktop(window.innerWidth >= 960);
|
|
27
|
-
};
|
|
28
|
-
checkScreenSize();
|
|
29
|
-
window.addEventListener('resize', checkScreenSize);
|
|
30
|
-
return () => {
|
|
31
|
-
window.removeEventListener('resize', checkScreenSize);
|
|
32
|
-
};
|
|
33
|
-
}, []);
|
|
34
|
-
return isDesktop;
|
|
44
|
+
return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
35
45
|
}
|
|
36
46
|
//# sourceMappingURL=useIsDesktopScreenWidth.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsDesktopScreenWidth.js","sourceRoot":"","sources":["../../src/hooks/useIsDesktopScreenWidth.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"useIsDesktopScreenWidth.js","sourceRoot":"","sources":["../../src/hooks/useIsDesktopScreenWidth.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAA;AAE5C,MAAM,mBAAmB,GAAG,oBAAoB,CAAA;AAEhD;;;;;;GAMG;AACH,SAAS,SAAS,CAAC,aAAyB;IAC1C,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;QACxD,OAAO,GAAG,EAAE,GAAE,CAAC,CAAA;IACjB,CAAC;IAED,MAAM,cAAc,GAAG,MAAM,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAAA;IAC7D,cAAc,CAAC,gBAAgB,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAA;IAExD,OAAO,GAAG,EAAE,CAAC,cAAc,CAAC,mBAAmB,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAA;AAC1E,CAAC;AAED;;;;GAIG;AACH,SAAS,WAAW;IAClB,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,MAAM,CAAC,UAAU;QAAE,OAAO,KAAK,CAAA;IAErE,OAAO,MAAM,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAAC,OAAO,CAAA;AACvD,CAAC;AAED;;;;;GAKG;AACH,SAAS,iBAAiB;IACxB,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,uBAAuB;IACrC,OAAO,oBAAoB,CAAC,SAAS,EAAE,WAAW,EAAE,iBAAiB,CAAC,CAAA;AACxE,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export {
|
|
1
|
+
export { ComboBox, default } from './ComboBox';
|
|
2
|
+
export { ComboBoxOptionsSlot, type ComboBoxOptionsSlotProps } from './partials';
|
|
3
|
+
export { useComboBox, useIsDesktopScreenWidth } from './hooks';
|
|
4
|
+
export type { ComboBoxAriaProps, ComboBoxOption, ComboBoxOptionGroup, ComboBoxOptionItemProps, ComboBoxOptionsInput, ComboBoxOptionsProps, ComboBoxOptionsPanelProps, ComboBoxProps, ListboxAriaProps, } from './types';
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export default ComboBox;
|
|
3
|
-
export * from './types';
|
|
1
|
+
export { ComboBox, default } from './ComboBox';
|
|
4
2
|
export { ComboBoxOptionsSlot } from './partials';
|
|
3
|
+
export { useComboBox, useIsDesktopScreenWidth } from './hooks';
|
|
5
4
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,EAAE,mBAAmB,EAAiC,MAAM,YAAY,CAAA;AAC/E,OAAO,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface ComboBoxNoResultsProps {
|
|
2
|
+
/** Message shown when no option matches the search. */
|
|
3
|
+
text?: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Empty state of the options list.
|
|
7
|
+
*
|
|
8
|
+
* `role="status"` makes screen readers announce the message when the list is
|
|
9
|
+
* filtered down to nothing.
|
|
10
|
+
*
|
|
11
|
+
* @param props - The props for the ComboBoxNoResults component
|
|
12
|
+
* @returns The no-results message
|
|
13
|
+
*/
|
|
14
|
+
export declare function ComboBoxNoResults({ text }: ComboBoxNoResultsProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import Text, { TEXT_VARIANT } from '@pixum/text';
|
|
3
|
+
import styles from '../ComboBox.module.css';
|
|
4
|
+
/**
|
|
5
|
+
* Empty state of the options list.
|
|
6
|
+
*
|
|
7
|
+
* `role="status"` makes screen readers announce the message when the list is
|
|
8
|
+
* filtered down to nothing.
|
|
9
|
+
*
|
|
10
|
+
* @param props - The props for the ComboBoxNoResults component
|
|
11
|
+
* @returns The no-results message
|
|
12
|
+
*/
|
|
13
|
+
export function ComboBoxNoResults({ text }) {
|
|
14
|
+
if (!text)
|
|
15
|
+
return null;
|
|
16
|
+
return (_jsx(Text, { variant: TEXT_VARIANT.SUBHEADLINE, className: styles.noResults, children: text }));
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=ComboBoxNoResults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ComboBoxNoResults.js","sourceRoot":"","sources":["../../src/partials/ComboBoxNoResults.tsx"],"names":[],"mappings":";AAAA,OAAO,IAAI,EAAE,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,MAAM,MAAM,wBAAwB,CAAA;AAO3C;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAAC,EAAE,IAAI,EAA0B;IAChE,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAA;IAEtB,OAAO,CACL,KAAC,IAAI,IAAC,OAAO,EAAE,YAAY,CAAC,WAAW,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,YACjE,IAAI,GACA,CACR,CAAA;AACH,CAAC"}
|
|
@@ -1,10 +1,21 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ComboBoxOptionsPanelProps } from '../types';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Renders the options panel of the ComboBox.
|
|
4
|
+
*
|
|
5
|
+
* The panel is split in two: the `Menu` provides the visible box, the element
|
|
6
|
+
* inside it carries the `listbox` role and is the only part that scrolls. That
|
|
7
|
+
* keeps `optionDetails` a real footer - it stays visible without
|
|
8
|
+
* `position: sticky` and can no longer cover the active option - and it keeps
|
|
9
|
+
* the listbox free of anything that is not an option or a group, as ARIA
|
|
10
|
+
* requires.
|
|
11
|
+
*
|
|
12
|
+
* Flat and grouped options share one render path: the options arrive already
|
|
13
|
+
* normalised, `groupOptions` only splits them into their visual groups again.
|
|
14
|
+
* The listbox is not focusable - the focus stays in the input field, the active
|
|
15
|
+
* option is announced through `aria-activedescendant`.
|
|
5
16
|
*
|
|
6
17
|
* @param props - The props for the ComboBoxOptions component
|
|
7
|
-
* @returns
|
|
18
|
+
* @returns The options panel
|
|
8
19
|
*/
|
|
9
|
-
export declare function ComboBoxOptions({ options,
|
|
20
|
+
export declare function ComboBoxOptions({ options, listboxAriaProps, selectedValues, activeOptionId, leadingType, optionDetails, onOptionClick, }: ComboBoxOptionsPanelProps): import("react/jsx-runtime").JSX.Element;
|
|
10
21
|
export default ComboBoxOptions;
|
|
@@ -1,29 +1,33 @@
|
|
|
1
|
-
import { jsx as _jsx,
|
|
2
|
-
import { useEffect } from 'react';
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
2
|
import Menu from '@pixum/menu';
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
3
|
+
import Text, { TEXT_VARIANT } from '@pixum/text';
|
|
4
|
+
import clsx from 'clsx';
|
|
5
|
+
import { groupOptions } from '../utils';
|
|
6
|
+
import { ComboBoxOptionsGroup } from './ComboBoxOptionsGroup';
|
|
7
|
+
import styles from '../ComboBox.module.css';
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* Renders the options panel of the ComboBox.
|
|
10
|
+
*
|
|
11
|
+
* The panel is split in two: the `Menu` provides the visible box, the element
|
|
12
|
+
* inside it carries the `listbox` role and is the only part that scrolls. That
|
|
13
|
+
* keeps `optionDetails` a real footer - it stays visible without
|
|
14
|
+
* `position: sticky` and can no longer cover the active option - and it keeps
|
|
15
|
+
* the listbox free of anything that is not an option or a group, as ARIA
|
|
16
|
+
* requires.
|
|
17
|
+
*
|
|
18
|
+
* Flat and grouped options share one render path: the options arrive already
|
|
19
|
+
* normalised, `groupOptions` only splits them into their visual groups again.
|
|
20
|
+
* The listbox is not focusable - the focus stays in the input field, the active
|
|
21
|
+
* option is announced through `aria-activedescendant`.
|
|
11
22
|
*
|
|
12
23
|
* @param props - The props for the ComboBoxOptions component
|
|
13
|
-
* @returns
|
|
24
|
+
* @returns The options panel
|
|
14
25
|
*/
|
|
15
|
-
export function ComboBoxOptions({ options,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
// Wait for next browser frame to ensure DOM is fully rendered
|
|
21
|
-
const frameId = requestAnimationFrame(() => {
|
|
22
|
-
scrollOptionToViewport(isDesktop);
|
|
23
|
-
});
|
|
24
|
-
return () => cancelAnimationFrame(frameId);
|
|
25
|
-
}, [isDesktop, selectedOption]);
|
|
26
|
-
return (_jsxs(Menu, { className: "combobox__options scrollable", "data-tappable": "true", children: [optionsWithoutGroup ? (_jsx(ComboBoxOptionsItems, { items: options, selectedOption: selectedOption, onClick: onClick, leadingType: leadingType })) : (_jsx(_Fragment, { children: optionsWithGroup.map(([group, items]) => (_jsx(ComboxBoxOptionsWithGrouping, { group: group, items: items, selectedOption: selectedOption, onClick: onClick, leadingType: leadingType }, `combobox__options-group-${group}`))) })), optionDetails && (_jsx("div", { className: "combobox__option-details text--caption", children: optionDetails }))] }));
|
|
26
|
+
export function ComboBoxOptions({ options, listboxAriaProps, selectedValues, activeOptionId, leadingType, optionDetails, onOptionClick, }) {
|
|
27
|
+
return (_jsxs(Menu, { className: styles.panel, "data-tappable": "true", children: [_jsx("div", Object.assign({ className: clsx(styles.options, 'scrollable'), tabIndex: -1 }, listboxAriaProps, { children: groupOptions(options).map(group => {
|
|
28
|
+
var _a;
|
|
29
|
+
return (_jsx(ComboBoxOptionsGroup, { group: group.group, options: group.options, selectedValues: selectedValues, activeOptionId: activeOptionId, leadingType: leadingType, onOptionClick: onOptionClick }, `combobox__options-group-${(_a = group.group) !== null && _a !== void 0 ? _a : 'default'}`));
|
|
30
|
+
}) })), optionDetails && (_jsx(Text, { variant: TEXT_VARIANT.CAPTION, className: styles.optionDetails, children: optionDetails }))] }));
|
|
27
31
|
}
|
|
28
32
|
export default ComboBoxOptions;
|
|
29
33
|
//# sourceMappingURL=ComboBoxOptions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComboBoxOptions.js","sourceRoot":"","sources":["../../src/partials/ComboBoxOptions.tsx"],"names":[],"mappings":";AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ComboBoxOptions.js","sourceRoot":"","sources":["../../src/partials/ComboBoxOptions.tsx"],"names":[],"mappings":";AAAA,OAAO,IAAI,MAAM,aAAa,CAAA;AAC9B,OAAO,IAAI,EAAE,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvC,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,MAAM,MAAM,wBAAwB,CAAA;AAG3C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,eAAe,CAAC,EAC9B,OAAO,EACP,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,WAAW,EACX,aAAa,EACb,aAAa,GACa;IAC1B,OAAO,CACL,MAAC,IAAI,IAAC,SAAS,EAAE,MAAM,CAAC,KAAK,mBAAgB,MAAM,aACjD,4BACE,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,YAAY,CAAC,EAC7C,QAAQ,EAAE,CAAC,CAAC,IACR,gBAAgB,cAEnB,YAAY,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;;oBAAC,OAAA,CAClC,KAAC,oBAAoB,IAEnB,KAAK,EAAE,KAAK,CAAC,KAAK,EAClB,OAAO,EAAE,KAAK,CAAC,OAAO,EACtB,cAAc,EAAE,cAAc,EAC9B,cAAc,EAAE,cAAc,EAC9B,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa,IANvB,2BAA2B,MAAA,KAAK,CAAC,KAAK,mCAAI,SAAS,EAAE,CAO1D,CACH,CAAA;iBAAA,CAAC,IACE,EAEL,aAAa,IAAI,CAChB,KAAC,IAAI,IAAC,OAAO,EAAE,YAAY,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,aAAa,YACjE,aAAa,GACT,CACR,IACI,CACR,CAAA;AACH,CAAC;AAED,eAAe,eAAe,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ComboBoxOptionsItemsProps } from './ComboBoxOptionsItems';
|
|
2
|
+
export interface ComboBoxOptionsGroupProps extends ComboBoxOptionsItemsProps {
|
|
3
|
+
/** Group headline. Without it the options are rendered without a header. */
|
|
4
|
+
group?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Renders one group of options with an optional sticky headline.
|
|
8
|
+
*
|
|
9
|
+
* Flat lists use the same component with `group` left undefined, so there is
|
|
10
|
+
* only one place that renders options.
|
|
11
|
+
*
|
|
12
|
+
* @param props - The props for the ComboBoxOptionsGroup component
|
|
13
|
+
* @returns A group container with an optional header and its options
|
|
14
|
+
*/
|
|
15
|
+
export declare function ComboBoxOptionsGroup({ group, ...itemProps }: ComboBoxOptionsGroupProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import Text, { TEXT_VARIANT } from '@pixum/text';
|
|
14
|
+
import { ComboBoxOptionsItems } from './ComboBoxOptionsItems';
|
|
15
|
+
import styles from '../ComboBox.module.css';
|
|
16
|
+
/**
|
|
17
|
+
* Renders one group of options with an optional sticky headline.
|
|
18
|
+
*
|
|
19
|
+
* Flat lists use the same component with `group` left undefined, so there is
|
|
20
|
+
* only one place that renders options.
|
|
21
|
+
*
|
|
22
|
+
* @param props - The props for the ComboBoxOptionsGroup component
|
|
23
|
+
* @returns A group container with an optional header and its options
|
|
24
|
+
*/
|
|
25
|
+
export function ComboBoxOptionsGroup(_a) {
|
|
26
|
+
var { group } = _a, itemProps = __rest(_a, ["group"]);
|
|
27
|
+
if (!group)
|
|
28
|
+
return _jsx(ComboBoxOptionsItems, Object.assign({}, itemProps));
|
|
29
|
+
return (_jsxs("div", { role: "group", "aria-label": group, children: [_jsx(Text, { variant: TEXT_VARIANT.HEADLINE, className: styles.stickyHeader, children: group }), _jsx(ComboBoxOptionsItems, Object.assign({}, itemProps))] }));
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=ComboBoxOptionsGroup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ComboBoxOptionsGroup.js","sourceRoot":"","sources":["../../src/partials/ComboBoxOptionsGroup.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,IAAI,EAAE,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,MAAM,MAAM,wBAAwB,CAAA;AAQ3C;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAAC,EAGT;QAHS,EACnC,KAAK,OAEqB,EADvB,SAAS,cAFuB,SAGpC,CADa;IAEZ,IAAI,CAAC,KAAK;QAAE,OAAO,KAAC,oBAAoB,oBAAK,SAAS,EAAI,CAAA;IAE1D,OAAO,CACL,eAAK,IAAI,EAAC,OAAO,gBAAa,KAAK,aACjC,KAAC,IAAI,IAAC,OAAO,EAAE,YAAY,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC,YAAY,YACjE,KAAK,GACD,EACP,KAAC,oBAAoB,oBAAK,SAAS,EAAI,IACnC,CACP,CAAA;AACH,CAAC"}
|