@jobber/components 8.4.0 → 8.6.0

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 (56) hide show
  1. package/dist/Autocomplete/Autocomplete.d.ts +6 -4
  2. package/dist/Autocomplete/Autocomplete.types.d.ts +3 -137
  3. package/dist/Autocomplete/components/FloatingMenu.d.ts +6 -6
  4. package/dist/Autocomplete/components/MenuList.d.ts +4 -4
  5. package/dist/Autocomplete/components/PersistentRegion.d.ts +3 -3
  6. package/dist/Autocomplete/index.cjs +25 -1658
  7. package/dist/Autocomplete/index.d.ts +3 -30
  8. package/dist/Autocomplete/index.mjs +25 -1647
  9. package/dist/Autocomplete/tests/Autocomplete.setup.d.ts +15 -15
  10. package/dist/Autocomplete/useAutocomplete.d.ts +2 -2
  11. package/dist/Autocomplete-cjs.js +1306 -0
  12. package/dist/Autocomplete-es.js +1304 -0
  13. package/dist/FormField/FormFieldTypes.d.ts +0 -7
  14. package/dist/InputDate/InputDate.types.d.ts +1 -1
  15. package/dist/InputEmail/InputEmail.types.d.ts +1 -1
  16. package/dist/InputNumber/InputNumber.types.d.ts +1 -1
  17. package/dist/InputPhoneNumber/InputPhoneNumber.types.d.ts +1 -1
  18. package/dist/InputText/InputText.types.d.ts +1 -5
  19. package/dist/InputTime/InputTime.types.d.ts +1 -1
  20. package/dist/Menu-es.js +1 -1
  21. package/dist/MenuSubmenuTrigger-es.js +1 -1
  22. package/dist/Select/OptionGroup.d.ts +2 -2
  23. package/dist/Select/Select.types.d.ts +1 -1
  24. package/dist/docs/Autocomplete/{AutocompleteV2.md → Autocomplete.md} +13 -107
  25. package/dist/docs/Banner/Banner.md +3 -3
  26. package/dist/docs/Box/Box.md +2 -2
  27. package/dist/docs/Chips/Chips.md +1 -1
  28. package/dist/docs/DataList/DataList.md +1 -1
  29. package/dist/docs/FormField/FormField.md +0 -1
  30. package/dist/docs/Icon/Icon.md +1 -1
  31. package/dist/docs/InputGroup/InputGroup.md +1 -1
  32. package/dist/docs/InputPassword/InputPassword.md +0 -1
  33. package/dist/docs/Menu/Menu.md +1 -1
  34. package/dist/docs/Modal/Modal.md +3 -3
  35. package/dist/docs/MultiSelect/MultiSelect.md +1 -1
  36. package/dist/docs/index.md +1 -2
  37. package/dist/docs/usage-guidelines/usage-guidelines.md +13 -44
  38. package/dist/floating-ui.react-dom-es.js +1 -1
  39. package/dist/floating-ui.react-es.js +1 -1
  40. package/dist/index.cjs +2 -2
  41. package/dist/index.esm-es.js +1 -1
  42. package/dist/index.mjs +1 -1
  43. package/dist/sharedHelpers/types.d.ts +0 -4
  44. package/dist/styles.css +29 -153
  45. package/package.json +2 -2
  46. package/dist/Autocomplete/Autocomplete.rebuilt.d.ts +0 -8
  47. package/dist/Autocomplete/Autocomplete.utils.d.ts +0 -8
  48. package/dist/Autocomplete/Menu/DefaultMenu.d.ts +0 -16
  49. package/dist/Autocomplete/Menu/Menu.d.ts +0 -3
  50. package/dist/Autocomplete/Menu/MenuWrapper.d.ts +0 -23
  51. package/dist/Autocomplete/Option.d.ts +0 -78
  52. package/dist/Autocomplete/V1.docgen.d.ts +0 -4
  53. package/dist/Autocomplete/V2.docgen.d.ts +0 -6
  54. package/dist/Autocomplete/useKeyboardNavigation.d.ts +0 -35
  55. package/dist/Autocomplete/useRepositionMenu.d.ts +0 -10
  56. package/dist/docs/Autocomplete/AutocompleteV1.md +0 -1328
@@ -0,0 +1,1306 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+ var floatingUi_react = require('./floating-ui.react-cjs.js');
5
+ var classnames = require('classnames');
6
+ var design = require('@jobber/design');
7
+ var jobberHooks = require('@jobber/hooks');
8
+ var maxHeight = require('./maxHeight-cjs.js');
9
+ var floatingUi_reactDom = require('./floating-ui.react-dom-cjs.js');
10
+ var Heading = require('./Heading-cjs.js');
11
+ var Text = require('./Text-cjs.js');
12
+ var Typography = require('./Typography-cjs.js');
13
+ var Icon = require('./Icon-cjs.js');
14
+ var Glimmer = require('./Glimmer-cjs.js');
15
+ var InputText = require('./InputText-cjs.js');
16
+ var FormFieldWrapper = require('./FormFieldWrapper-cjs.js');
17
+ require('./tslib.es6-cjs.js');
18
+ require('react-hook-form');
19
+ var mergeRefs = require('./mergeRefs-cjs.js');
20
+ require('./Button-cjs.js');
21
+ var filterDataAttributes = require('./filterDataAttributes-cjs.js');
22
+
23
+ /** Stable empty array for cleared/empty selection state. Reuse to avoid reference churn. */
24
+ const EMPTY_SELECTED_VALUES = [];
25
+
26
+ var styles = {"list":"w5g7qggGrr4-","loadingList":"ELlB2Kio7q8-","option":"y9zhi8Wr8QA-","defaultOptionContent":"adJv-3bhYOQ-","icon":"K2phy6IC3TY-","optionActive":"p2CY3TGCdRc-","actionActive":"-tyLeCnCEUI-","action":"dXIHuZjqX84-","section":"gQ86NtBHt-Y-","emptyStateMessage":"uElGEScjH68-","stickyTop":"nXvoRgKgoz8-","scrollRegion":"Ey1zL5E-c74-","persistentHeader":"ei36u5racbA-","persistentFooter":"IDIz9ZHykRw-","textPersistent":"Wx--khA61eA-","multiSelectField":"COW3V1gDtwI-","chipArea":"_1iRpnGn3PaA-","inlineInput":"bHaScorkEaQ-","selectionChip":"sFMc1SJPOSM-","selectionChipActive":"_9Ljs17OW-QM-","selectionChipDisabled":"QYUKkbmNjLE-","chipDismiss":"Wv6D8g2MKPo-","limitText":"UAegmMck3-U-","spinning":"P9cQDL4MZ-s-"};
27
+
28
+ function flattenMenu(menu) {
29
+ const optionItems = [];
30
+ const sections = [];
31
+ const persistentsHeaders = [];
32
+ const persistentsFooters = [];
33
+ menu.forEach(item => {
34
+ if (item.type === "header") {
35
+ persistentsHeaders.push(item);
36
+ return;
37
+ }
38
+ if (item.type === "footer") {
39
+ persistentsFooters.push(item);
40
+ return;
41
+ }
42
+ const group = item;
43
+ sections.push(group);
44
+ optionItems.push(...group.options);
45
+ });
46
+ return { optionItems, sections, persistentsHeaders, persistentsFooters };
47
+ }
48
+ function buildItemsForGroup(group, optionsFilter) {
49
+ var _a;
50
+ const isSection = group.type === "section";
51
+ const filtered = optionsFilter ? optionsFilter(group.options) : group.options;
52
+ const actions = (_a = group.actions) !== null && _a !== void 0 ? _a : [];
53
+ const result = [];
54
+ // Only render a section header when that section has at least one option after filtering
55
+ if (isSection && filtered.length > 0) {
56
+ result.push({
57
+ kind: "section",
58
+ section: group,
59
+ });
60
+ }
61
+ if (filtered.length > 0) {
62
+ result.push(...filtered.map(o => ({
63
+ kind: "option",
64
+ value: o,
65
+ })));
66
+ }
67
+ // Only render actions for a group when that group has at least one option after filtering
68
+ if (actions.length > 0 && filtered.length > 0) {
69
+ result.push(...actions.map(action => ({
70
+ kind: "action",
71
+ action,
72
+ origin: "menu",
73
+ })));
74
+ }
75
+ return result;
76
+ }
77
+ function buildRenderableList(sections, optionsFilter) {
78
+ const items = [];
79
+ for (const group of sections) {
80
+ items.push(...buildItemsForGroup(group, optionsFilter));
81
+ }
82
+ return items;
83
+ }
84
+ function getNavigableItemAtIndex(activeIndex, renderable) {
85
+ if (activeIndex == null)
86
+ return null;
87
+ let navigableIndex = -1;
88
+ for (const item of renderable) {
89
+ // Ignore sections
90
+ if (item.kind === "section")
91
+ continue;
92
+ navigableIndex += 1;
93
+ if (navigableIndex === activeIndex)
94
+ return item;
95
+ }
96
+ return null;
97
+ }
98
+ function findNavigableIndexForValue(renderable, equals, selectedValue) {
99
+ let navigableIndex = -1;
100
+ for (const item of renderable) {
101
+ // Ignore sections
102
+ if (item.kind === "section")
103
+ continue;
104
+ navigableIndex += 1;
105
+ if (item.kind === "option" && equals(item.value, selectedValue)) {
106
+ return navigableIndex;
107
+ }
108
+ }
109
+ return null;
110
+ }
111
+ function invokeActiveItemOnEnter(event, activeIndex, renderable, onSelect, onAction) {
112
+ const activeItem = getNavigableItemAtIndex(activeIndex, renderable);
113
+ if (!activeItem)
114
+ return;
115
+ event.preventDefault();
116
+ if (activeItem.kind === "option") {
117
+ onSelect(activeItem.value);
118
+ }
119
+ else if (activeItem.kind === "action") {
120
+ onAction({
121
+ run: activeItem.action.onClick,
122
+ closeOnRun: activeItem.action.shouldClose,
123
+ });
124
+ }
125
+ }
126
+
127
+ const MENU_OFFSET = design.tokens["space-small"];
128
+ const AUTOCOMPLETE_MAX_HEIGHT = 300;
129
+ function useStableSetReference(refs) {
130
+ const latestRefs = React.useRef(refs);
131
+ latestRefs.current = refs;
132
+ return React.useCallback((el) => latestRefs.current.setReference(el), []);
133
+ }
134
+ function useAutocompleteListNav({ navigableCount, shouldResetActiveIndexOnClose, onMenuOpen, onMenuClose, selectedIndex, readOnly = false, disabled = false, outsidePressExcludeSelector, }) {
135
+ const [open, setOpen] = React.useState(false);
136
+ const [activeIndex, setActiveIndex] = React.useState(null);
137
+ const listRef = React.useRef([]);
138
+ const { refs, floatingStyles, context } = floatingUi_react.useFloating({
139
+ placement: "bottom",
140
+ whileElementsMounted: floatingUi_reactDom.autoUpdate,
141
+ open,
142
+ onOpenChange: (isOpen, _event, reason) => {
143
+ setOpen(isOpen);
144
+ if (isOpen) {
145
+ onMenuOpen === null || onMenuOpen === void 0 ? void 0 : onMenuOpen();
146
+ }
147
+ else {
148
+ if (shouldResetActiveIndexOnClose === null || shouldResetActiveIndexOnClose === void 0 ? void 0 : shouldResetActiveIndexOnClose()) {
149
+ setActiveIndex(null);
150
+ }
151
+ onMenuClose === null || onMenuClose === void 0 ? void 0 : onMenuClose(String(reason !== null && reason !== void 0 ? reason : ""));
152
+ }
153
+ },
154
+ middleware: [
155
+ floatingUi_reactDom.offset(MENU_OFFSET),
156
+ floatingUi_reactDom.flip({ fallbackPlacements: ["top"] }),
157
+ floatingUi_reactDom.size({
158
+ apply({ availableHeight, rects, elements }) {
159
+ const maxHeight$1 = maxHeight.calculateMaxHeight(availableHeight, {
160
+ maxHeight: AUTOCOMPLETE_MAX_HEIGHT,
161
+ });
162
+ Object.assign(elements.floating.style, {
163
+ maxHeight: `${maxHeight$1}px`,
164
+ width: `${rects.reference.width}px`,
165
+ });
166
+ },
167
+ }),
168
+ ],
169
+ });
170
+ const enabled = !readOnly && !disabled;
171
+ const click = floatingUi_react.useClick(context, {
172
+ enabled,
173
+ toggle: false, // Only open, never close on click
174
+ });
175
+ const listNav = floatingUi_react.useListNavigation(context, {
176
+ listRef,
177
+ activeIndex,
178
+ selectedIndex,
179
+ scrollItemIntoView: {
180
+ behavior: "smooth",
181
+ block: "end",
182
+ },
183
+ loop: true,
184
+ onNavigate: setActiveIndex,
185
+ virtual: true,
186
+ enabled: open,
187
+ openOnArrowKeyDown: false,
188
+ focusItemOnOpen: "auto",
189
+ focusItemOnHover: false,
190
+ });
191
+ const dismiss = floatingUi_react.useDismiss(context, {
192
+ outsidePress: outsidePressExcludeSelector
193
+ ? (event) => {
194
+ var _a, _b, _c, _d;
195
+ const target = event.target;
196
+ const insideRef = (_b = (_a = context.elements.domReference) === null || _a === void 0 ? void 0 : _a.contains(target)) !== null && _b !== void 0 ? _b : false;
197
+ const insideFloating = (_d = (_c = context.elements.floating) === null || _c === void 0 ? void 0 : _c.contains(target)) !== null && _d !== void 0 ? _d : false;
198
+ const insideExclude = event.target.closest(outsidePressExcludeSelector);
199
+ return !(insideRef || insideFloating || insideExclude);
200
+ }
201
+ : true,
202
+ escapeKey: true,
203
+ outsidePressEvent: "click",
204
+ });
205
+ const { getReferenceProps, getFloatingProps, getItemProps } = floatingUi_react.useInteractions([click, listNav, dismiss]);
206
+ React.useEffect(() => {
207
+ listRef.current.length = navigableCount;
208
+ setActiveIndex(prev => {
209
+ if (navigableCount <= 0)
210
+ return null;
211
+ if (prev == null)
212
+ return null;
213
+ return prev >= navigableCount ? navigableCount - 1 : prev;
214
+ });
215
+ }, [navigableCount, setActiveIndex, listRef]);
216
+ const setReferenceElement = useStableSetReference(refs);
217
+ return {
218
+ refs,
219
+ floatingStyles,
220
+ context,
221
+ getReferenceProps,
222
+ getFloatingProps,
223
+ getItemProps,
224
+ activeIndex,
225
+ setActiveIndex,
226
+ listRef,
227
+ open,
228
+ setOpen,
229
+ setReferenceElement,
230
+ };
231
+ }
232
+
233
+ /**
234
+ * Handler that prevents default pointer behavior.
235
+ * Used to prevent blur/focus issues when clicking on non-interactive menu elements.
236
+ */
237
+ function preventDefaultPointerDown(e) {
238
+ e.preventDefault();
239
+ }
240
+ /**
241
+ * Creates a handler for pointer down events on interactive menu items (options/actions).
242
+ * Prevents default to avoid blur and sets flag for focus management.
243
+ *
244
+ * @param isHandlingMenuInteractionRef - Ref to track if a menu interaction is in progress
245
+ * @returns A pointer down event handler
246
+ */
247
+ function createInteractionPointerDownHandler(isHandlingMenuInteractionRef) {
248
+ return (e) => {
249
+ e.preventDefault();
250
+ // Set flag to prevent blur/focus handlers from interfering
251
+ isHandlingMenuInteractionRef.current = true;
252
+ };
253
+ }
254
+
255
+ // Keeping this hook cohesive improves readability by centralizing related
256
+ // interactions and state transitions.
257
+ // eslint-disable-next-line max-statements
258
+ function useAutocomplete(props, inputRef) {
259
+ const { menu, emptyActions, getOptionLabel: getOptionLabelProp, isOptionEqualToValue, inputValue, onInputChange, value, onChange, multiple, openOnFocus = true, readOnly = false, disabled = false, debounce: debounceMs = 300, } = props;
260
+ const isHandlingMenuInteractionRef = React.useRef(false);
261
+ // TODO: Clean up the types in these refs by enhancing the type system in useCallbackRef
262
+ const getOptionLabelPropRef = jobberHooks.useCallbackRef((opt) => getOptionLabelProp === null || getOptionLabelProp === void 0 ? void 0 : getOptionLabelProp(opt));
263
+ const getOptionLabel = React.useCallback((opt) => {
264
+ const maybe = getOptionLabelPropRef(opt);
265
+ return maybe !== null && maybe !== void 0 ? maybe : opt.label;
266
+ }, [getOptionLabelPropRef]);
267
+ const isOptionEqualToValueRef = jobberHooks.useCallbackRef((a, b) => isOptionEqualToValue === null || isOptionEqualToValue === void 0 ? void 0 : isOptionEqualToValue(a, b));
268
+ const equals = React.useCallback((a, b) => {
269
+ const custom = isOptionEqualToValueRef(a, b);
270
+ return custom != null ? custom : getOptionLabel(a) === getOptionLabel(b);
271
+ }, [isOptionEqualToValueRef, getOptionLabel]);
272
+ const isOptionSelected = React.useCallback((opt) => {
273
+ var _a;
274
+ if (multiple) {
275
+ const current = (_a = value) !== null && _a !== void 0 ? _a : EMPTY_SELECTED_VALUES;
276
+ return current.some(v => equals(v, opt));
277
+ }
278
+ const current = value;
279
+ return current != null ? equals(current, opt) : false;
280
+ }, [multiple, value, equals]);
281
+ const flatInitial = React.useMemo(() => flattenMenu(menu), [menu]);
282
+ const sections = flatInitial.sections;
283
+ const optionItems = flatInitial.optionItems;
284
+ const persistentsHeaders = flatInitial.persistentsHeaders;
285
+ const persistentsFooters = flatInitial.persistentsFooters;
286
+ // Stable wrappers for function props
287
+ const inputEqualsOptionRef = jobberHooks.useCallbackRef((text, o) => {
288
+ const fn = props.inputEqualsOption;
289
+ return fn ? fn(text, o) : undefined;
290
+ });
291
+ const inputEquals = React.useCallback((text, o) => {
292
+ const custom = inputEqualsOptionRef(text, o);
293
+ return custom != null ? custom : getOptionLabel(o) === text;
294
+ }, [inputEqualsOptionRef, getOptionLabel]);
295
+ // inputValue changes very often, is this worth memoizing?
296
+ const exactLabelMatch = React.useMemo(() => {
297
+ return optionItems.some(o => inputEquals(inputValue, o));
298
+ }, [optionItems, inputEquals, inputValue]);
299
+ const lastInputWasUser = React.useRef(false);
300
+ const [debouncedInputValue, setDebouncedInputValue] = React.useState(inputValue);
301
+ const debouncedSetter = jobberHooks.useDebounce(setDebouncedInputValue, debounceMs);
302
+ React.useEffect(() => {
303
+ // Skip debounce when clearing input for immediate feedback, preventing flickering of last selected item
304
+ if (debounceMs === 0 || inputValue === "") {
305
+ setDebouncedInputValue(inputValue);
306
+ // Cancel any pending debounced call so a stale intermediate value
307
+ // (e.g. "P" while deleting "Pipe…") doesn't overwrite the immediate set.
308
+ debouncedSetter.cancel();
309
+ return;
310
+ }
311
+ debouncedSetter(inputValue);
312
+ }, [inputValue, debounceMs, debouncedSetter]);
313
+ const filterOptionsRef = jobberHooks.useCallbackRef((opts, term) => {
314
+ const fn = (typeof props.filterOptions === "function"
315
+ ? props.filterOptions
316
+ : undefined) || undefined;
317
+ return fn ? fn(opts, term) : undefined;
318
+ });
319
+ const applyFilter = React.useCallback((opts, term) => {
320
+ if (props.filterOptions === false)
321
+ return opts;
322
+ const override = filterOptionsRef(opts, term);
323
+ if (override)
324
+ return override;
325
+ const lowered = term.toLowerCase();
326
+ return opts.filter(opt => getOptionLabel(opt).toLowerCase().includes(lowered));
327
+ }, [props.filterOptions, filterOptionsRef, getOptionLabel]);
328
+ const renderable = React.useMemo(() => {
329
+ const filter = (opts) => {
330
+ if (exactLabelMatch && !lastInputWasUser.current)
331
+ return opts;
332
+ return applyFilter(opts, debouncedInputValue);
333
+ };
334
+ const items = buildRenderableList(sections, filter);
335
+ const hasAnyOptions = items.some(i => i.kind === "option");
336
+ if (!hasAnyOptions) {
337
+ if (emptyActions) {
338
+ const derived = typeof emptyActions === "function"
339
+ ? emptyActions({ inputValue })
340
+ : emptyActions;
341
+ return derived.map(act => ({
342
+ kind: "action",
343
+ action: act,
344
+ origin: "empty",
345
+ }));
346
+ }
347
+ // No options and no emptyActions: render empty state
348
+ return [];
349
+ }
350
+ return items;
351
+ }, [
352
+ sections,
353
+ applyFilter,
354
+ debouncedInputValue,
355
+ exactLabelMatch,
356
+ emptyActions,
357
+ inputValue,
358
+ ]);
359
+ // This is only options
360
+ const optionCount = renderable.reduce((count, item) => count + (item.kind === "option" ? 1 : 0), 0);
361
+ const hasSelection = React.useMemo(() => {
362
+ var _a;
363
+ if (multiple) {
364
+ const current = (_a = value) !== null && _a !== void 0 ? _a : EMPTY_SELECTED_VALUES;
365
+ return Array.isArray(current) && current.length > 0;
366
+ }
367
+ return value != null;
368
+ }, [multiple, value]);
369
+ const headerInteractivePersistents = persistentsHeaders.filter(p => Boolean(p.onClick));
370
+ const footerInteractivePersistents = persistentsFooters.filter(p => Boolean(p.onClick));
371
+ const mainNavigableCount = renderable.reduce((c, i) => c + (i.kind === "section" ? 0 : 1), 0);
372
+ const totalNavigableCount = headerInteractivePersistents.length +
373
+ mainNavigableCount +
374
+ footerInteractivePersistents.length;
375
+ // Compute the currently selected index in the global navigable list (header -> middle -> footer).
376
+ // In multiple mode this is always null — there is no single "selected" index, and
377
+ // floating-ui would otherwise jump the highlight whenever the value array changes.
378
+ const selectedIndex = React.useMemo(() => {
379
+ if (multiple)
380
+ return null;
381
+ const selectedValue = value;
382
+ if (!selectedValue)
383
+ return null;
384
+ const middleIndex = findNavigableIndexForValue(renderable, equals, selectedValue);
385
+ if (middleIndex == null)
386
+ return null;
387
+ return headerInteractivePersistents.length + middleIndex;
388
+ }, [
389
+ multiple,
390
+ value,
391
+ renderable,
392
+ equals,
393
+ headerInteractivePersistents.length,
394
+ ]);
395
+ const { refs, floatingStyles, context, getReferenceProps, getFloatingProps, getItemProps, activeIndex, setActiveIndex, listRef, open, setOpen, setReferenceElement, } = useAutocompleteListNav({
396
+ navigableCount: totalNavigableCount,
397
+ shouldResetActiveIndexOnClose: () => !hasSelection,
398
+ selectedIndex,
399
+ readOnly,
400
+ disabled,
401
+ outsidePressExcludeSelector: multiple
402
+ ? "[data-testid='ATL-Autocomplete-chipArea']"
403
+ : undefined,
404
+ onMenuOpen: () => {
405
+ if (multiple)
406
+ return;
407
+ const selectedValue = value;
408
+ if (selectedValue) {
409
+ const selectedNavigableIndex = findNavigableIndexForValue(renderable, equals, selectedValue);
410
+ if (selectedNavigableIndex != null) {
411
+ setActiveIndex(selectedNavigableIndex);
412
+ return;
413
+ }
414
+ }
415
+ setActiveIndex(null);
416
+ },
417
+ onMenuClose: () => {
418
+ if (props.allowFreeForm !== true) {
419
+ const hasText = inputValue.trim().length > 0;
420
+ if (hasText && !hasSelection) {
421
+ lastInputWasUser.current = false;
422
+ onInputChange === null || onInputChange === void 0 ? void 0 : onInputChange("");
423
+ setActiveIndex(null);
424
+ }
425
+ }
426
+ },
427
+ });
428
+ const prevOpenRef = React.useRef(false);
429
+ // TODO: Leverage FloatingUI useFocus, and onArrowKeyDown to manage open state and allow onOpenChange to be the source of truth
430
+ // JOB-154442
431
+ React.useEffect(() => {
432
+ var _a, _b;
433
+ if (open && !prevOpenRef.current) {
434
+ (_a = props.onOpen) === null || _a === void 0 ? void 0 : _a.call(props);
435
+ }
436
+ else if (!open && prevOpenRef.current) {
437
+ (_b = props.onClose) === null || _b === void 0 ? void 0 : _b.call(props);
438
+ }
439
+ prevOpenRef.current = open;
440
+ }, [open, props.onOpen, props.onClose]);
441
+ function selectOption(option) {
442
+ var _a;
443
+ if (multiple) {
444
+ const current = (_a = value) !== null && _a !== void 0 ? _a : EMPTY_SELECTED_VALUES;
445
+ const exists = current.some(v => equals(v, option));
446
+ const next = exists
447
+ ? current.filter(v => !equals(v, option))
448
+ : [...current, option];
449
+ onChange((next.length === 0 ? EMPTY_SELECTED_VALUES : next));
450
+ lastInputWasUser.current = false;
451
+ onInputChange === null || onInputChange === void 0 ? void 0 : onInputChange("");
452
+ }
453
+ else {
454
+ onChange(option);
455
+ lastInputWasUser.current = false;
456
+ onInputChange === null || onInputChange === void 0 ? void 0 : onInputChange(getOptionLabel(option));
457
+ }
458
+ }
459
+ function reHighlightSelectedItem() {
460
+ const selectedValue = value;
461
+ if (!selectedValue)
462
+ return;
463
+ const idx = findNavigableIndexForValue(renderable, equals, selectedValue);
464
+ if (idx != null)
465
+ setActiveIndex(idx);
466
+ }
467
+ function tryCommitFreeFormOnEnter() {
468
+ if (props.allowFreeForm !== true)
469
+ return false;
470
+ if (open && activeIndex != null)
471
+ return false;
472
+ const inputText = inputValue.trim();
473
+ if (inputText.length === 0)
474
+ return false;
475
+ commitFromInputText(inputText);
476
+ return true;
477
+ }
478
+ const onSelection = React.useCallback((option) => {
479
+ var _a;
480
+ selectOption(option);
481
+ if (!multiple) {
482
+ setOpen(false);
483
+ }
484
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
485
+ }, [selectOption, setOpen, multiple, inputRef]);
486
+ const onAction = React.useCallback((action) => {
487
+ var _a;
488
+ action.run();
489
+ setActiveIndex(null);
490
+ if (action.closeOnRun !== false)
491
+ setOpen(false);
492
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
493
+ }, [setOpen, setActiveIndex, inputRef]);
494
+ /**
495
+ * Handler for mousedown on interactive menu items (options/actions)
496
+ * Prevents default to avoid blur and sets flag for focus management
497
+ */
498
+ const onInteractionPointerDown = React.useMemo(() => createInteractionPointerDownHandler(isHandlingMenuInteractionRef), []);
499
+ function applyFreeFormValue(freeFormCreated) {
500
+ var _a;
501
+ const nextValue = multiple
502
+ ? [...((_a = value) !== null && _a !== void 0 ? _a : EMPTY_SELECTED_VALUES), freeFormCreated]
503
+ : freeFormCreated;
504
+ props.onChange(nextValue);
505
+ if (multiple) {
506
+ lastInputWasUser.current = false;
507
+ onInputChange === null || onInputChange === void 0 ? void 0 : onInputChange("");
508
+ }
509
+ }
510
+ function commitFromInputText(inputText) {
511
+ var _a;
512
+ if (inputText.length === 0)
513
+ return false;
514
+ const match = optionItems.find(o => inputEquals(inputText, o));
515
+ if (match) {
516
+ onSelection(match);
517
+ return true;
518
+ }
519
+ setOpen(false);
520
+ if (props.allowFreeForm !== true)
521
+ return false;
522
+ const freeFormCreated = (_a = props.createFreeFormValue) === null || _a === void 0 ? void 0 : _a.call(props, inputText);
523
+ if (!freeFormCreated)
524
+ return false;
525
+ applyFreeFormValue(freeFormCreated);
526
+ return true;
527
+ }
528
+ const tryRestoreInputToSelectedLabel = React.useCallback(() => {
529
+ if (props.allowFreeForm === true)
530
+ return;
531
+ if (multiple) {
532
+ if (inputValue.trim().length > 0) {
533
+ lastInputWasUser.current = false;
534
+ onInputChange === null || onInputChange === void 0 ? void 0 : onInputChange("");
535
+ }
536
+ return;
537
+ }
538
+ const selectedValue = value;
539
+ if (!selectedValue)
540
+ return;
541
+ const selectedLabel = getOptionLabel(selectedValue);
542
+ if (inputValue === selectedLabel)
543
+ return;
544
+ lastInputWasUser.current = false;
545
+ onInputChange === null || onInputChange === void 0 ? void 0 : onInputChange(selectedLabel);
546
+ }, [
547
+ props.allowFreeForm,
548
+ getOptionLabel,
549
+ inputValue,
550
+ onInputChange,
551
+ multiple,
552
+ value,
553
+ ]);
554
+ const onInputFocus = React.useCallback((event) => {
555
+ var _a;
556
+ if (!readOnly && openOnFocus && !isHandlingMenuInteractionRef.current) {
557
+ setOpen(true);
558
+ }
559
+ // Only call user's onFocus for genuine focus events, not programmatic restorations
560
+ if (!isHandlingMenuInteractionRef.current) {
561
+ (_a = props.onFocus) === null || _a === void 0 ? void 0 : _a.call(props, event);
562
+ }
563
+ isHandlingMenuInteractionRef.current = false;
564
+ }, [props.onFocus, readOnly, openOnFocus, setOpen]);
565
+ const onInputBlur = React.useCallback((event) => {
566
+ var _a, _b;
567
+ if (isHandlingMenuInteractionRef.current) {
568
+ return;
569
+ }
570
+ if (readOnly) {
571
+ (_a = props.onBlur) === null || _a === void 0 ? void 0 : _a.call(props, event);
572
+ return;
573
+ }
574
+ if (props.allowFreeForm === true) {
575
+ const inputText = inputValue.trim();
576
+ if (inputText.length > 0)
577
+ commitFromInputText(inputText);
578
+ }
579
+ else {
580
+ tryRestoreInputToSelectedLabel();
581
+ }
582
+ lastInputWasUser.current = false;
583
+ (_b = props.onBlur) === null || _b === void 0 ? void 0 : _b.call(props, event);
584
+ }, [
585
+ readOnly,
586
+ props.allowFreeForm,
587
+ inputValue,
588
+ props.onBlur,
589
+ tryRestoreInputToSelectedLabel,
590
+ setOpen,
591
+ ]);
592
+ function getRegionByActiveIndex(index) {
593
+ const headerCount = headerInteractivePersistents.length;
594
+ const mainCount = mainNavigableCount;
595
+ if (index < headerCount)
596
+ return { region: "header", regionIndex: index };
597
+ const middleIndex = index - headerCount;
598
+ if (middleIndex < mainCount) {
599
+ return { region: "middle", regionIndex: middleIndex };
600
+ }
601
+ return {
602
+ region: "footer",
603
+ regionIndex: middleIndex - mainCount,
604
+ };
605
+ }
606
+ function computeInitialIndexForArrowUp() {
607
+ // If there are interactive footers, prefer the very last navigable item
608
+ if (footerInteractivePersistents.length > 0) {
609
+ return totalNavigableCount > 0 ? totalNavigableCount - 1 : null;
610
+ }
611
+ // Otherwise, prefer the last OPTION (not action), matching legacy behavior
612
+ let navigable = -1;
613
+ let lastOptionIdx = -1;
614
+ for (const item of renderable) {
615
+ if (item.kind === "section")
616
+ continue;
617
+ navigable += 1;
618
+ if (item.kind === "option")
619
+ lastOptionIdx = navigable;
620
+ }
621
+ if (lastOptionIdx >= 0) {
622
+ return headerInteractivePersistents.length + lastOptionIdx;
623
+ }
624
+ return totalNavigableCount > 0 ? totalNavigableCount - 1 : null;
625
+ }
626
+ function handleArrowNavigation(key, event) {
627
+ if (!open) {
628
+ setOpen(true);
629
+ return;
630
+ }
631
+ if (activeIndex == null) {
632
+ setActiveIndex(key === "ArrowDown" ? 0 : computeInitialIndexForArrowUp());
633
+ event.preventDefault();
634
+ }
635
+ }
636
+ function handleEnterKey(event) {
637
+ if (tryCommitFreeFormOnEnter()) {
638
+ event.preventDefault();
639
+ return;
640
+ }
641
+ if (!open || activeIndex == null)
642
+ return;
643
+ const { region, regionIndex } = getRegionByActiveIndex(activeIndex);
644
+ if (region === "middle") {
645
+ invokeActiveItemOnEnter(event, regionIndex, renderable, onSelection, onAction);
646
+ return;
647
+ }
648
+ const persistent = region === "header"
649
+ ? headerInteractivePersistents[regionIndex]
650
+ : footerInteractivePersistents[regionIndex];
651
+ if (persistent === null || persistent === void 0 ? void 0 : persistent.onClick) {
652
+ onAction({
653
+ run: persistent.onClick,
654
+ closeOnRun: persistent.shouldClose,
655
+ });
656
+ }
657
+ }
658
+ const removeLastSelection = React.useCallback(() => {
659
+ var _a;
660
+ if (!multiple || readOnly)
661
+ return;
662
+ const current = (_a = value) !== null && _a !== void 0 ? _a : EMPTY_SELECTED_VALUES;
663
+ if (current.length > 0) {
664
+ const next = current.slice(0, -1);
665
+ onChange((next.length === 0 ? EMPTY_SELECTED_VALUES : next));
666
+ }
667
+ }, [multiple, readOnly, value, onChange]);
668
+ const removeSelection = React.useCallback((option) => {
669
+ var _a;
670
+ if (readOnly)
671
+ return;
672
+ if (multiple) {
673
+ const current = (_a = value) !== null && _a !== void 0 ? _a : EMPTY_SELECTED_VALUES;
674
+ const next = current.filter(v => !equals(v, option));
675
+ onChange((next.length === 0
676
+ ? EMPTY_SELECTED_VALUES
677
+ : next));
678
+ }
679
+ else {
680
+ const current = value;
681
+ if (current && equals(current, option)) {
682
+ onChange(undefined);
683
+ }
684
+ }
685
+ }, [readOnly, multiple, value, equals, onChange]);
686
+ const onInputKeyDown = React.useCallback((event) => {
687
+ const key = event.key;
688
+ if (key === "Backspace" && multiple && inputValue === "") {
689
+ removeLastSelection();
690
+ return;
691
+ }
692
+ if (key !== "ArrowDown" && key !== "ArrowUp" && key !== "Enter")
693
+ return;
694
+ if (key === "ArrowDown" || key === "ArrowUp") {
695
+ handleArrowNavigation(key, event);
696
+ return;
697
+ }
698
+ handleEnterKey(event);
699
+ }, [open, onSelection, onAction, multiple, inputValue, removeLastSelection]);
700
+ const onInputChangeFromUser = React.useCallback((val) => {
701
+ lastInputWasUser.current = true;
702
+ const isEmpty = val.trim().length === 0;
703
+ if (isEmpty) {
704
+ setActiveIndex(null);
705
+ if (!multiple && hasSelection) {
706
+ onChange === null || onChange === void 0 ? void 0 : onChange(undefined);
707
+ }
708
+ }
709
+ else if (val.length > inputValue.length) {
710
+ setActiveIndex(null);
711
+ }
712
+ else if (val.length < inputValue.length &&
713
+ !multiple &&
714
+ open &&
715
+ hasSelection) {
716
+ reHighlightSelectedItem();
717
+ }
718
+ if (!readOnly) {
719
+ setOpen((!isEmpty && !props.allowFreeForm) || openOnFocus);
720
+ }
721
+ onInputChange === null || onInputChange === void 0 ? void 0 : onInputChange(val);
722
+ }, [
723
+ onInputChange,
724
+ inputValue,
725
+ setActiveIndex,
726
+ readOnly,
727
+ props.allowFreeForm,
728
+ openOnFocus,
729
+ setOpen,
730
+ multiple,
731
+ hasSelection,
732
+ onChange,
733
+ open,
734
+ ]);
735
+ const clearAll = React.useCallback(() => {
736
+ if (multiple) {
737
+ onChange(EMPTY_SELECTED_VALUES);
738
+ }
739
+ else {
740
+ onChange(undefined);
741
+ }
742
+ onInputChangeFromUser("");
743
+ }, [multiple, onChange, onInputChangeFromUser]);
744
+ return {
745
+ // rendering data
746
+ renderable,
747
+ optionCount,
748
+ persistentsHeaders,
749
+ persistentsFooters,
750
+ headerInteractiveCount: headerInteractivePersistents.length,
751
+ middleNavigableCount: mainNavigableCount,
752
+ getOptionLabel,
753
+ isOptionSelected,
754
+ // floating-ui
755
+ refs,
756
+ floatingStyles,
757
+ context,
758
+ getReferenceProps,
759
+ getFloatingProps,
760
+ getItemProps,
761
+ // state
762
+ open,
763
+ setOpen,
764
+ activeIndex,
765
+ setActiveIndex,
766
+ listRef,
767
+ // actions
768
+ onSelection,
769
+ onAction,
770
+ onInteractionPointerDown,
771
+ removeSelection,
772
+ clearAll,
773
+ // input handlers
774
+ onInputChangeFromUser,
775
+ onInputBlur,
776
+ onInputFocus,
777
+ onInputKeyDown,
778
+ // ref attachment
779
+ setReferenceElement,
780
+ };
781
+ }
782
+
783
+ function useChipNavigation({ selectedValues, inputValue, readOnly, removeSelection, onInputKeyDown, onInputBlur, }) {
784
+ const [rawActiveChipIndex, setRawActiveChipIndex] = React.useState(null);
785
+ const [previousInputValue, setPreviousInputValue] = React.useState(inputValue);
786
+ const activeChipIndex = clampActiveIndex(rawActiveChipIndex, selectedValues.length);
787
+ if (previousInputValue !== inputValue) {
788
+ setPreviousInputValue(inputValue);
789
+ if (inputValue !== "" && rawActiveChipIndex !== null) {
790
+ setRawActiveChipIndex(null);
791
+ }
792
+ }
793
+ const handleActiveChipKey = React.useCallback(
794
+ // eslint-disable-next-line max-statements
795
+ (event) => {
796
+ if (activeChipIndex === null)
797
+ return false;
798
+ const { key } = event;
799
+ if (key === "ArrowLeft") {
800
+ event.preventDefault();
801
+ setRawActiveChipIndex(i => Math.max(0, (i !== null && i !== void 0 ? i : 0) - 1));
802
+ return true;
803
+ }
804
+ if (key === "ArrowRight") {
805
+ event.preventDefault();
806
+ setRawActiveChipIndex(activeChipIndex + 1 >= selectedValues.length
807
+ ? null
808
+ : activeChipIndex + 1);
809
+ return true;
810
+ }
811
+ if (key === "Backspace" || key === "Delete") {
812
+ event.preventDefault();
813
+ const option = selectedValues[activeChipIndex];
814
+ const newLen = selectedValues.length - 1;
815
+ if (newLen === 0) {
816
+ setRawActiveChipIndex(null);
817
+ }
818
+ else if (activeChipIndex >= newLen) {
819
+ setRawActiveChipIndex(newLen - 1);
820
+ }
821
+ removeSelection(option);
822
+ return true;
823
+ }
824
+ if (key === "Escape") {
825
+ setRawActiveChipIndex(null);
826
+ return true;
827
+ }
828
+ setRawActiveChipIndex(null);
829
+ return false;
830
+ }, [activeChipIndex, selectedValues, removeSelection]);
831
+ const onKeyDown = React.useCallback((event) => {
832
+ if (handleActiveChipKey(event))
833
+ return;
834
+ if (event.key === "ArrowLeft" &&
835
+ !readOnly &&
836
+ inputValue === "" &&
837
+ selectedValues.length > 0) {
838
+ event.preventDefault();
839
+ setRawActiveChipIndex(selectedValues.length - 1);
840
+ return;
841
+ }
842
+ onInputKeyDown(event);
843
+ }, [handleActiveChipKey, selectedValues, inputValue, readOnly, onInputKeyDown]);
844
+ const onBlur = React.useCallback((event) => {
845
+ setRawActiveChipIndex(null);
846
+ onInputBlur(event);
847
+ }, [onInputBlur]);
848
+ return { activeChipIndex, onKeyDown, onBlur };
849
+ }
850
+ function clampActiveIndex(index, length) {
851
+ if (index === null)
852
+ return null;
853
+ if (length === 0)
854
+ return null;
855
+ if (index >= length)
856
+ return length - 1;
857
+ return index;
858
+ }
859
+
860
+ function MenuList({ items, activeIndex, indexOffset = 0, getItemProps, listRef, listboxId, customRenderOption, customRenderSection, customRenderAction, getOptionLabel, onSelect, onAction, onInteractionPointerDown, isOptionSelected, slotOverrides, }) {
861
+ let navigableIndex = -1;
862
+ function renderItemNode(item) {
863
+ var _a, _b, _c, _d, _e, _f;
864
+ if (item.kind === "section") {
865
+ return handleSectionRendering({
866
+ section: item.section,
867
+ customRenderSection,
868
+ sectionClassName: (_a = slotOverrides === null || slotOverrides === void 0 ? void 0 : slotOverrides.section) === null || _a === void 0 ? void 0 : _a.className,
869
+ sectionStyle: (_b = slotOverrides === null || slotOverrides === void 0 ? void 0 : slotOverrides.section) === null || _b === void 0 ? void 0 : _b.style,
870
+ });
871
+ }
872
+ if (item.kind === "option") {
873
+ const result = handleOptionRendering({
874
+ option: item.value,
875
+ activeIndex,
876
+ navigableIndex,
877
+ getItemProps,
878
+ listRef,
879
+ listboxId,
880
+ isOptionSelected,
881
+ customRenderOption,
882
+ getOptionLabel,
883
+ onSelect,
884
+ onInteractionPointerDown,
885
+ indexOffset,
886
+ optionClassName: (_c = slotOverrides === null || slotOverrides === void 0 ? void 0 : slotOverrides.option) === null || _c === void 0 ? void 0 : _c.className,
887
+ optionStyle: (_d = slotOverrides === null || slotOverrides === void 0 ? void 0 : slotOverrides.option) === null || _d === void 0 ? void 0 : _d.style,
888
+ });
889
+ navigableIndex = result.nextNavigableIndex;
890
+ return result.node;
891
+ }
892
+ const result = handleActionRendering({
893
+ action: item.action,
894
+ activeIndex,
895
+ navigableIndex,
896
+ getItemProps,
897
+ listRef,
898
+ listboxId,
899
+ customRenderAction,
900
+ onAction,
901
+ onInteractionPointerDown,
902
+ indexOffset,
903
+ actionClassName: (_e = slotOverrides === null || slotOverrides === void 0 ? void 0 : slotOverrides.action) === null || _e === void 0 ? void 0 : _e.className,
904
+ actionStyle: (_f = slotOverrides === null || slotOverrides === void 0 ? void 0 : slotOverrides.action) === null || _f === void 0 ? void 0 : _f.style,
905
+ origin: item.origin,
906
+ });
907
+ navigableIndex = result.nextNavigableIndex;
908
+ return result.node;
909
+ }
910
+ return React.createElement(React.Fragment, null, items.map(renderItemNode));
911
+ }
912
+ function handleSectionRendering({ customRenderSection, section, sectionClassName, sectionStyle, }) {
913
+ var _a;
914
+ const headerContent = customRenderSection ? (customRenderSection(section)) : (React.createElement(DefaultSectionContent, { section: section }));
915
+ return (React.createElement("div", { key: `section-${String((_a = section.key) !== null && _a !== void 0 ? _a : section.label)}`, role: "presentation", tabIndex: -1, "data-testid": "ATL-Autocomplete-Section", className: classnames(styles.section, styles.stickyTop, sectionClassName), style: sectionStyle, onPointerDown: preventDefaultPointerDown }, headerContent));
916
+ }
917
+ function DefaultSectionContent({ section, }) {
918
+ return React.createElement(Heading.Heading, { level: 5 }, section.label);
919
+ }
920
+ function handleOptionRendering({ option, activeIndex, navigableIndex, getItemProps, listRef, listboxId, isOptionSelected, customRenderOption, getOptionLabel, onSelect, onInteractionPointerDown, indexOffset = 0, optionClassName, optionStyle, }) {
921
+ var _a;
922
+ const nextNavigableIndex = navigableIndex + 1;
923
+ const isActive = activeIndex === nextNavigableIndex;
924
+ const isSelected = isOptionSelected(option);
925
+ const optionContent = customRenderOption ? (customRenderOption({ value: option, isActive, isSelected })) : (React.createElement(DefaultOptionContent, { isSelected: isSelected, text: getOptionLabel(option) }));
926
+ return {
927
+ node: (React.createElement("div", Object.assign({ key: `option-${String((_a = option.key) !== null && _a !== void 0 ? _a : getOptionLabel(option))}` }, getItemProps({
928
+ ref(node) {
929
+ const idx = nextNavigableIndex + indexOffset;
930
+ if (node)
931
+ listRef.current[idx] = node;
932
+ },
933
+ onClick: () => onSelect(option),
934
+ onPointerDown: onInteractionPointerDown,
935
+ className: classnames(styles.option, isActive && styles.optionActive, optionClassName),
936
+ style: optionStyle,
937
+ }), { role: "option", tabIndex: -1, "aria-selected": isSelected ? true : false, id: `${listboxId}-item-${nextNavigableIndex + indexOffset}`, "data-index": nextNavigableIndex + indexOffset, "data-active": isActive ? true : undefined }), optionContent)),
938
+ nextNavigableIndex,
939
+ };
940
+ }
941
+ function DefaultOptionContent({ isSelected, text, }) {
942
+ return (React.createElement("div", { className: styles.defaultOptionContent },
943
+ React.createElement("div", { className: styles.icon, style: isSelected ? undefined : { visibility: "hidden" } },
944
+ React.createElement(Icon.Icon, { name: "checkmark", size: "small" })),
945
+ React.createElement(Text.Text, null, text)));
946
+ }
947
+ function handleActionRendering({ action, activeIndex, navigableIndex, getItemProps, listRef, listboxId, customRenderAction, onAction, onInteractionPointerDown, indexOffset = 0, actionClassName, actionStyle, origin, }) {
948
+ var _a;
949
+ const nextNavigableIndex = navigableIndex + 1;
950
+ const isActive = activeIndex === nextNavigableIndex;
951
+ const actionContent = customRenderAction ? (customRenderAction({ value: action, isActive, origin })) : (React.createElement(DefaultActionContent, { textContent: action.label }));
952
+ const computedIndex = nextNavigableIndex + indexOffset;
953
+ const itemProps = getItemProps({
954
+ ref(node) {
955
+ if (node) {
956
+ listRef.current[computedIndex] = node;
957
+ }
958
+ },
959
+ onClick: () => {
960
+ onAction({
961
+ run: action.onClick,
962
+ closeOnRun: action.shouldClose,
963
+ });
964
+ },
965
+ onPointerDown: onInteractionPointerDown,
966
+ className: classnames(styles.action, isActive && styles.actionActive, actionClassName),
967
+ style: actionStyle,
968
+ });
969
+ return {
970
+ node: (React.createElement("div", Object.assign({ key: `action-${String((origin !== null && origin !== void 0 ? origin : "menu") + "-" + ((_a = action.key) !== null && _a !== void 0 ? _a : action.label))}` }, itemProps, { role: "button", tabIndex: -1, "data-testid": "ATL-Autocomplete-Action", id: `${listboxId}-item-${computedIndex}`, "data-index": computedIndex, "data-origin": origin, "data-active": isActive ? true : undefined }), actionContent)),
971
+ nextNavigableIndex,
972
+ };
973
+ }
974
+ function DefaultActionContent({ textContent, }) {
975
+ return (React.createElement(Typography.Typography, { textColor: "interactive", fontWeight: "semiBold", underline: "solid color-interactive", UNSAFE_style: {
976
+ textStyle: {
977
+ textDecorationThickness: "var(--border-thick)",
978
+ textUnderlineOffset: "var(--space-smallest)",
979
+ },
980
+ } }, textContent));
981
+ }
982
+
983
+ function PersistentRegion({ items, position, activeIndex, indexOffset, getItemProps, listRef, customRenderHeader, customRenderFooter, className, style, onAction, onInteractionPointerDown, }) {
984
+ if (!items || items.length === 0)
985
+ return null;
986
+ let navigableIndex = -1;
987
+ return (React.createElement("div", { className: className, style: style, "data-region": position, "data-testid": `ATL-Autocomplete-${position}` }, items.map(persistent => {
988
+ const result = handlePersistentRendering({
989
+ persistent,
990
+ position,
991
+ activeIndex,
992
+ indexOffset,
993
+ getItemProps,
994
+ customRenderHeader,
995
+ customRenderFooter,
996
+ listRef,
997
+ onAction,
998
+ onInteractionPointerDown,
999
+ navigableIndex,
1000
+ });
1001
+ navigableIndex = result.nextNavigableIndex;
1002
+ return result.node;
1003
+ })));
1004
+ }
1005
+ function handlePersistentRendering({ persistent, position, activeIndex, indexOffset, getItemProps, customRenderHeader, customRenderFooter, listRef, onAction, onInteractionPointerDown, navigableIndex, }) {
1006
+ const interactive = Boolean(persistent.onClick);
1007
+ if (!interactive) {
1008
+ const node = handleTextPersistentRendering({
1009
+ persistent,
1010
+ position,
1011
+ customRenderHeader,
1012
+ customRenderFooter,
1013
+ });
1014
+ return { node, nextNavigableIndex: navigableIndex };
1015
+ }
1016
+ return handleActionPersistentRendering({
1017
+ persistent,
1018
+ position,
1019
+ activeIndex,
1020
+ indexOffset,
1021
+ getItemProps,
1022
+ customRenderHeader,
1023
+ customRenderFooter,
1024
+ listRef,
1025
+ onAction,
1026
+ onInteractionPointerDown,
1027
+ navigableIndex,
1028
+ });
1029
+ }
1030
+ function handleTextPersistentRendering({ persistent, position, customRenderHeader, customRenderFooter, }) {
1031
+ var _a;
1032
+ let content;
1033
+ if (position === "header" && customRenderHeader) {
1034
+ content = customRenderHeader({ value: persistent });
1035
+ }
1036
+ else if (position === "footer" && customRenderFooter) {
1037
+ content = customRenderFooter({ value: persistent });
1038
+ }
1039
+ else {
1040
+ content = React.createElement(DefaultTextPersistentContent, { persistent: persistent });
1041
+ }
1042
+ return (React.createElement("div", { key: `persistent-${position}-${String((_a = persistent.key) !== null && _a !== void 0 ? _a : persistent.label)}`, role: "presentation", tabIndex: -1, className: styles.textPersistent, onPointerDown: preventDefaultPointerDown }, content));
1043
+ }
1044
+ function handleActionPersistentRendering({ persistent, position, activeIndex, indexOffset, getItemProps, customRenderHeader, customRenderFooter, listRef, onAction, onInteractionPointerDown, navigableIndex, }) {
1045
+ var _a;
1046
+ const nextNavigableIndex = navigableIndex + 1;
1047
+ const isActive = activeIndex === indexOffset + nextNavigableIndex;
1048
+ let content;
1049
+ if (position === "header" && customRenderHeader) {
1050
+ content = customRenderHeader({
1051
+ value: persistent,
1052
+ isActive,
1053
+ });
1054
+ }
1055
+ else if (position === "footer" && customRenderFooter) {
1056
+ content = customRenderFooter({
1057
+ value: persistent,
1058
+ isActive,
1059
+ });
1060
+ }
1061
+ else {
1062
+ content = React.createElement(DefaultActionContent, { textContent: persistent.label });
1063
+ }
1064
+ return {
1065
+ node: (React.createElement("div", Object.assign({ key: `persistent-${position}-${String((_a = persistent.key) !== null && _a !== void 0 ? _a : persistent.label)}`, "data-index": indexOffset + nextNavigableIndex, id: `${position}-persistent-${indexOffset + nextNavigableIndex}`, "data-active": isActive ? true : undefined }, getItemProps({
1066
+ ref(persistNode) {
1067
+ const idx = indexOffset + nextNavigableIndex;
1068
+ if (persistNode)
1069
+ listRef.current[idx] = persistNode;
1070
+ },
1071
+ onClick: () => {
1072
+ onAction({
1073
+ run: () => {
1074
+ var _a;
1075
+ (_a = persistent.onClick) === null || _a === void 0 ? void 0 : _a.call(persistent);
1076
+ },
1077
+ closeOnRun: persistent.shouldClose,
1078
+ });
1079
+ },
1080
+ onPointerDown: onInteractionPointerDown,
1081
+ className: classnames(styles.action, isActive && styles.actionActive),
1082
+ }), { role: "button", tabIndex: -1 }), content)),
1083
+ nextNavigableIndex,
1084
+ };
1085
+ }
1086
+ function DefaultTextPersistentContent({ persistent, }) {
1087
+ return React.createElement("div", { className: styles.textPersistent }, persistent.label);
1088
+ }
1089
+
1090
+ function FloatingMenu({ context, getFloatingProps, refs, listboxId, className, floatingStyles, transitionStyles, menuStyle, renderable, persistentsHeaders, persistentsFooters, activeIndex, headerInteractiveCount, middleNavigableCount, getItemProps, listRef, onSelection, onAction, onInteractionPointerDown, getOptionLabel, isOptionSelected, loading, showEmptyStateMessage, emptyStateMessage, customRenderLoading, customRenderOption, customRenderSection, customRenderAction, customRenderHeader, customRenderFooter, slotOverrides, }) {
1091
+ var _a, _b, _c, _d;
1092
+ const activeIndexForMiddle = activeIndex != null ? activeIndex - headerInteractiveCount : null;
1093
+ return (React.createElement(floatingUi_react.FloatingPortal, null,
1094
+ React.createElement(floatingUi_react.FloatingFocusManager, { context: context, modal: false, initialFocus: -1, closeOnFocusOut: true, returnFocus: false },
1095
+ React.createElement("div", Object.assign({}, getFloatingProps({
1096
+ ref(node) {
1097
+ if (node)
1098
+ refs.setFloating(node);
1099
+ },
1100
+ id: listboxId,
1101
+ role: "listbox",
1102
+ className,
1103
+ style: Object.assign(Object.assign(Object.assign({}, floatingStyles), transitionStyles), menuStyle),
1104
+ })),
1105
+ React.createElement(PersistentRegion, { items: persistentsHeaders, position: "header", activeIndex: activeIndex, indexOffset: 0, listboxId: listboxId, getItemProps: getItemProps, listRef: listRef, customRenderHeader: customRenderHeader, customRenderFooter: customRenderFooter, onAction: onAction, onInteractionPointerDown: onInteractionPointerDown, className: classnames(styles.persistentHeader, (_a = slotOverrides === null || slotOverrides === void 0 ? void 0 : slotOverrides.header) === null || _a === void 0 ? void 0 : _a.className), style: (_b = slotOverrides === null || slotOverrides === void 0 ? void 0 : slotOverrides.header) === null || _b === void 0 ? void 0 : _b.style }),
1106
+ React.createElement("div", { className: styles.scrollRegion }, loading ? (customRenderLoading !== null && customRenderLoading !== void 0 ? customRenderLoading : React.createElement(LoadingContent, null)) : (React.createElement(React.Fragment, null,
1107
+ showEmptyStateMessage && (React.createElement(EmptyStateMessage, { emptyState: emptyStateMessage })),
1108
+ renderable.length > 0 && (React.createElement(MenuList, { items: renderable, activeIndex: activeIndexForMiddle, indexOffset: headerInteractiveCount, listboxId: listboxId, getItemProps: getItemProps, listRef: listRef, customRenderOption: customRenderOption, customRenderSection: customRenderSection, customRenderAction: customRenderAction, getOptionLabel: getOptionLabel, onSelect: onSelection, onAction: onAction, onInteractionPointerDown: onInteractionPointerDown, isOptionSelected: isOptionSelected, slotOverrides: slotOverrides }))))),
1109
+ React.createElement(PersistentRegion, { items: persistentsFooters, position: "footer", activeIndex: activeIndex, indexOffset: headerInteractiveCount + middleNavigableCount, listboxId: listboxId, getItemProps: getItemProps, listRef: listRef, customRenderHeader: customRenderHeader, customRenderFooter: customRenderFooter, onAction: onAction, onInteractionPointerDown: onInteractionPointerDown, className: classnames(styles.persistentFooter, (_c = slotOverrides === null || slotOverrides === void 0 ? void 0 : slotOverrides.footer) === null || _c === void 0 ? void 0 : _c.className), style: (_d = slotOverrides === null || slotOverrides === void 0 ? void 0 : slotOverrides.footer) === null || _d === void 0 ? void 0 : _d.style })))));
1110
+ }
1111
+ function LoadingContent() {
1112
+ return (React.createElement("div", { className: styles.loadingList, onPointerDown: preventDefaultPointerDown },
1113
+ React.createElement(Glimmer.Glimmer, { shape: "rectangle", size: "base" }),
1114
+ React.createElement(Glimmer.Glimmer, { shape: "rectangle", size: "base" }),
1115
+ React.createElement(Glimmer.Glimmer, { shape: "rectangle", size: "base" })));
1116
+ }
1117
+ function EmptyStateMessage({ emptyState, }) {
1118
+ const emptyStateDefault = "No options";
1119
+ const emptyStateContent = emptyState !== null && emptyState !== void 0 ? emptyState : emptyStateDefault;
1120
+ return (React.createElement("div", { className: styles.emptyStateMessage, onPointerDown: preventDefaultPointerDown }, emptyStateContent));
1121
+ }
1122
+
1123
+ const Autocomplete = React.forwardRef(AutocompleteInternal);
1124
+ // eslint-disable-next-line max-statements
1125
+ function AutocompleteInternal(props, forwardedRef) {
1126
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
1127
+ const { inputValue, placeholder, disabled, error, invalid, description, size: sizeProp, loading = false, } = props;
1128
+ const formFieldRef = React.useRef(null);
1129
+ // Ref for the multi-select input element, where we cannot use refs.domReference
1130
+ // since it is not attached to the literal input element, whereas single + InputText only offers a
1131
+ // ref to the literal input element.
1132
+ const internalInputRef = React.useRef(null);
1133
+ const { renderable, optionCount, persistentsHeaders, persistentsFooters, headerInteractiveCount, middleNavigableCount, getOptionLabel, isOptionSelected, refs, floatingStyles, context, getReferenceProps, getFloatingProps, getItemProps, activeIndex, open, listRef, onSelection, onAction, onInteractionPointerDown, removeSelection, onInputChangeFromUser, onInputBlur, onInputFocus, onInputKeyDown, setReferenceElement, clearAll, } = useAutocomplete(props, internalInputRef);
1134
+ const listboxId = React.useId();
1135
+ // Provides mount/unmount-aware transition styles for the floating element
1136
+ const { isMounted, styles: transitionStyles } = floatingUi_react.useTransitionStyles(context, {
1137
+ initial: { opacity: 0 },
1138
+ open: { opacity: 1 },
1139
+ close: { opacity: 0 },
1140
+ duration: { open: design.tokens["timing-base"], close: design.tokens["timing-base"] },
1141
+ });
1142
+ const [positionRefEl, setPositionRefEl] = React.useState(null);
1143
+ const inputId = React.useId();
1144
+ const descriptionId = `descriptionUUID--${inputId}`;
1145
+ const selectedValues = props.multiple
1146
+ ? ((_a = props.value) !== null && _a !== void 0 ? _a : EMPTY_SELECTED_VALUES)
1147
+ : EMPTY_SELECTED_VALUES;
1148
+ const { activeChipIndex, onKeyDown: chipKeyDown, onBlur: chipBlur, } = useChipNavigation({
1149
+ selectedValues,
1150
+ inputValue,
1151
+ readOnly: props.readOnly,
1152
+ removeSelection,
1153
+ onInputKeyDown,
1154
+ onInputBlur,
1155
+ });
1156
+ const focusInputOnPointerDown = React.useCallback((e) => {
1157
+ var _a;
1158
+ const target = e.target;
1159
+ if (target.closest("input, button"))
1160
+ return;
1161
+ e.preventDefault();
1162
+ (_a = internalInputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
1163
+ }, []);
1164
+ const composedReferenceProps = getReferenceProps(Object.assign({ onKeyDown: props.multiple ? chipKeyDown : onInputKeyDown, onFocus: onInputFocus, onBlur: props.multiple ? chipBlur : onInputBlur }, (props.multiple ? { onPointerDown: focusInputOnPointerDown } : {})));
1165
+ const dataAttrs = filterDataAttributes.filterDataAttributes(props);
1166
+ const ariaProps = {
1167
+ role: "combobox",
1168
+ "aria-autocomplete": "list",
1169
+ "aria-expanded": open ? true : false,
1170
+ "aria-controls": listboxId,
1171
+ "aria-activedescendant": activeChipIndex === null && open && activeIndex != null
1172
+ ? `${listboxId}-item-${activeIndex}`
1173
+ : undefined,
1174
+ };
1175
+ const inputProps = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ value: inputValue, onChange: props.readOnly ? undefined : onInputChangeFromUser }, (props.readOnly ? { onFocus: onInputFocus, onBlur: onInputBlur } : {})), { placeholder,
1176
+ disabled, readOnly: props.readOnly, error: error !== null && error !== void 0 ? error : undefined, name: props.name, invalid, clearable: props.clearable, autoComplete: "off", autoFocus: props.autoFocus, description, size: sizeProp ? sizeProp : undefined, prefix: props.prefix, suffix: props.suffix }), (props.readOnly ? {} : composedReferenceProps)), ariaProps), dataAttrs);
1177
+ const chipAreaRef = React.useCallback((node) => {
1178
+ if (!node)
1179
+ return;
1180
+ // In multiple mode, we use the input as the reference so floating-ui's
1181
+ // useListNavigation treats it as a typeable combobox and allows Space.
1182
+ // Only use chipArea for positioning/sizing.
1183
+ if (!props.multiple) {
1184
+ setReferenceElement(node);
1185
+ }
1186
+ const multiContainer = node.closest("[data-testid='ATL-Autocomplete-multiSelectContainer']");
1187
+ if (multiContainer) {
1188
+ setPositionRefEl(multiContainer);
1189
+ }
1190
+ }, [setReferenceElement, props.multiple]);
1191
+ const referenceInputRef = React.useCallback((node) => {
1192
+ setReferenceElement(node);
1193
+ if (!props.multiple) {
1194
+ // Workaround to get the visual InputText element, which is not the same
1195
+ // as the literal input reference element when props like suffix/prefix
1196
+ // are present. Used to set the position reference for the floating menu.
1197
+ const visualInputTextElement = node === null || node === void 0 ? void 0 : node.closest("[data-testid='Form-Field-Wrapper']");
1198
+ if (visualInputTextElement) {
1199
+ setPositionRefEl(visualInputTextElement);
1200
+ }
1201
+ }
1202
+ }, [setReferenceElement, props.multiple]);
1203
+ const mergedInputRef = React.useMemo(() => mergeRefs.mergeRefs([
1204
+ referenceInputRef,
1205
+ internalInputRef,
1206
+ forwardedRef,
1207
+ ]), [referenceInputRef, forwardedRef]);
1208
+ React.useEffect(() => {
1209
+ if (!positionRefEl)
1210
+ return;
1211
+ refs.setPositionReference(positionRefEl);
1212
+ }, [positionRefEl, refs]);
1213
+ const menuClassName = classnames(styles.list, (_b = props.UNSAFE_className) === null || _b === void 0 ? void 0 : _b.menu);
1214
+ const showEmptyStateMessage = optionCount === 0 && props.emptyStateMessage !== false;
1215
+ const floatingMenu = isMounted && !props.readOnly && !disabled && (React.createElement(FloatingMenu, { context: context, getFloatingProps: getFloatingProps, refs: refs, listboxId: listboxId, className: menuClassName, floatingStyles: floatingStyles, transitionStyles: transitionStyles, menuStyle: (_c = props.UNSAFE_styles) === null || _c === void 0 ? void 0 : _c.menu, renderable: renderable, persistentsHeaders: persistentsHeaders, persistentsFooters: persistentsFooters, activeIndex: activeIndex, headerInteractiveCount: headerInteractiveCount, middleNavigableCount: middleNavigableCount, getItemProps: getItemProps, listRef: listRef, onSelection: onSelection, onAction: onAction, onInteractionPointerDown: onInteractionPointerDown, getOptionLabel: getOptionLabel, isOptionSelected: isOptionSelected, loading: loading, showEmptyStateMessage: showEmptyStateMessage, emptyStateMessage: props.emptyStateMessage, customRenderLoading: props.customRenderLoading, customRenderOption: props.customRenderOption, customRenderSection: props.customRenderSection, customRenderAction: props.customRenderAction, customRenderHeader: props.customRenderHeader, customRenderFooter: props.customRenderFooter, slotOverrides: {
1216
+ option: {
1217
+ className: (_d = props.UNSAFE_className) === null || _d === void 0 ? void 0 : _d.option,
1218
+ style: (_e = props.UNSAFE_styles) === null || _e === void 0 ? void 0 : _e.option,
1219
+ },
1220
+ action: {
1221
+ className: (_f = props.UNSAFE_className) === null || _f === void 0 ? void 0 : _f.action,
1222
+ style: (_g = props.UNSAFE_styles) === null || _g === void 0 ? void 0 : _g.action,
1223
+ },
1224
+ section: {
1225
+ className: (_h = props.UNSAFE_className) === null || _h === void 0 ? void 0 : _h.section,
1226
+ style: (_j = props.UNSAFE_styles) === null || _j === void 0 ? void 0 : _j.section,
1227
+ },
1228
+ header: {
1229
+ className: (_k = props.UNSAFE_className) === null || _k === void 0 ? void 0 : _k.header,
1230
+ style: (_l = props.UNSAFE_styles) === null || _l === void 0 ? void 0 : _l.header,
1231
+ },
1232
+ footer: {
1233
+ className: (_m = props.UNSAFE_className) === null || _m === void 0 ? void 0 : _m.footer,
1234
+ style: (_o = props.UNSAFE_styles) === null || _o === void 0 ? void 0 : _o.footer,
1235
+ },
1236
+ } }));
1237
+ if (props.customRenderInput) {
1238
+ return (React.createElement("div", { "data-testid": "ATL-Autocomplete" },
1239
+ props.customRenderInput({ inputRef: mergedInputRef, inputProps }),
1240
+ floatingMenu));
1241
+ }
1242
+ if (props.multiple) {
1243
+ return (React.createElement(MultipleSelectionLayout, { selectedValues: selectedValues, inputValue: inputValue, disabled: disabled, error: error, invalid: invalid, sizeProp: sizeProp, inputId: inputId, descriptionId: descriptionId, description: description, placeholder: placeholder, clearable: props.clearable, prefix: props.prefix, suffix: props.suffix, readOnly: props.readOnly, name: props.name, autoFocus: props.autoFocus, formFieldRef: formFieldRef, chipAreaRef: chipAreaRef, mergedInputRef: mergedInputRef, internalInputRef: internalInputRef, activeChipIndex: activeChipIndex, getOptionLabel: getOptionLabel, customRenderValue: props.customRenderValue, removeSelection: removeSelection, clearAll: clearAll, onInputChangeFromUser: onInputChangeFromUser, chipAreaEventProps: props.readOnly
1244
+ ? { onFocus: onInputFocus, onBlur: chipBlur }
1245
+ : composedReferenceProps, inputAriaProps: ariaProps, inputDataAttrs: dataAttrs, limitVisibleSelections: props.limitVisibleSelections, limitSelectionText: props.limitSelectionText, unsafeClassName: (_p = props.UNSAFE_className) === null || _p === void 0 ? void 0 : _p.selection, unsafeStyle: (_q = props.UNSAFE_styles) === null || _q === void 0 ? void 0 : _q.selection }, floatingMenu));
1246
+ }
1247
+ return (React.createElement("div", { "data-testid": "ATL-Autocomplete" },
1248
+ React.createElement(InputText.InputText, Object.assign({ ref: mergedInputRef }, inputProps)),
1249
+ floatingMenu));
1250
+ }
1251
+ function SelectionChip({ value, active, disabled, getOptionLabel, customRenderValue, canDismiss, onDismiss, unsafeClassName, unsafeStyle, }) {
1252
+ return (React.createElement("span", { "data-selection-disabled": disabled, className: classnames(styles.selectionChip, {
1253
+ [styles.selectionChipActive]: active,
1254
+ [styles.selectionChipDisabled]: disabled,
1255
+ }, unsafeClassName), style: unsafeStyle, "data-testid": "ATL-Autocomplete-chip", onPointerDown: preventDefaultPointerDown },
1256
+ customRenderValue ? (customRenderValue({ value, getOptionLabel })) : (React.createElement(Typography.Typography, { size: "small" }, getOptionLabel(value))),
1257
+ canDismiss && (React.createElement("button", { type: "button", disabled: disabled, className: styles.chipDismiss, onClick: onDismiss, onPointerDown: preventDefaultPointerDown, "aria-label": `Remove ${getOptionLabel(value)}`, tabIndex: -1 },
1258
+ React.createElement(Icon.Icon, { size: "small", name: "remove" })))));
1259
+ }
1260
+ function SelectionChipsList({ selectedValues, isFocused, limitVisibleSelections = 6, limitSelectionText = (count) => `+${count}`, activeChipIndex, disabled, getOptionLabel, customRenderValue, canDismiss, removeSelection, unsafeClassName, unsafeStyle, }) {
1261
+ const shouldLimit = !isFocused &&
1262
+ limitVisibleSelections !== -1 &&
1263
+ selectedValues.length > limitVisibleSelections;
1264
+ const visibleValues = shouldLimit
1265
+ ? selectedValues.slice(0, limitVisibleSelections)
1266
+ : selectedValues;
1267
+ const hiddenCount = shouldLimit
1268
+ ? selectedValues.length - limitVisibleSelections
1269
+ : 0;
1270
+ return (React.createElement(React.Fragment, null,
1271
+ visibleValues.map((v, i) => {
1272
+ var _a;
1273
+ return (React.createElement(SelectionChip, { key: (_a = v.key) !== null && _a !== void 0 ? _a : getOptionLabel(v), value: v, active: activeChipIndex === i, disabled: disabled, getOptionLabel: getOptionLabel, customRenderValue: customRenderValue, canDismiss: canDismiss, onDismiss: () => removeSelection(v), unsafeClassName: unsafeClassName, unsafeStyle: unsafeStyle }));
1274
+ }),
1275
+ hiddenCount > 0 && (React.createElement("span", { className: styles.limitText, "data-testid": "ATL-Autocomplete-limitText" },
1276
+ React.createElement(Typography.Typography, { size: "small", element: "span" }, limitSelectionText(hiddenCount))))));
1277
+ }
1278
+ function MultipleSelectionLayout({ selectedValues, inputValue, disabled, error, invalid, sizeProp, inputId, descriptionId, description, placeholder, clearable, prefix, suffix, readOnly, name, autoFocus, formFieldRef, chipAreaRef, mergedInputRef, internalInputRef, activeChipIndex, getOptionLabel, customRenderValue, removeSelection, clearAll, onInputChangeFromUser, chipAreaEventProps, inputAriaProps, inputDataAttrs, limitVisibleSelections, limitSelectionText, unsafeClassName, unsafeStyle, children, }) {
1279
+ var _a;
1280
+ const [isFocused, setIsFocused] = React.useState(false);
1281
+ const hasValue = selectedValues.length > 0 || inputValue;
1282
+ const canDismissChip = !disabled && !readOnly;
1283
+ const handleFocusIn = React.useCallback(() => {
1284
+ setIsFocused(true);
1285
+ }, []);
1286
+ const handleFocusOut = React.useCallback((e) => {
1287
+ if (!e.currentTarget.contains(e.relatedTarget)) {
1288
+ setIsFocused(false);
1289
+ }
1290
+ }, []);
1291
+ return (React.createElement("div", { "data-testid": "ATL-Autocomplete", onFocus: handleFocusIn, onBlur: handleFocusOut },
1292
+ React.createElement("div", { className: styles.multiSelectField, "data-testid": "ATL-Autocomplete-multiSelectContainer" },
1293
+ React.createElement(FormFieldWrapper.FormFieldWrapper, { disabled: disabled, size: sizeProp ? sizeProp : undefined, error: (_a = error) !== null && _a !== void 0 ? _a : "", invalid: Boolean(error || invalid), identifier: inputId, descriptionIdentifier: descriptionId, description: description, clearable: clearable !== null && clearable !== void 0 ? clearable : "never", onClear: () => {
1294
+ var _a;
1295
+ clearAll();
1296
+ (_a = internalInputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
1297
+ }, type: "text", placeholder: placeholder, value: hasValue ? "has-value" : "", prefix: prefix, suffix: suffix, wrapperRef: formFieldRef },
1298
+ React.createElement("div", Object.assign({ ref: chipAreaRef, className: styles.chipArea, "data-testid": "ATL-Autocomplete-chipArea" }, chipAreaEventProps),
1299
+ React.createElement(SelectionChipsList, { selectedValues: selectedValues, isFocused: isFocused, limitVisibleSelections: limitVisibleSelections, limitSelectionText: limitSelectionText, activeChipIndex: activeChipIndex, disabled: disabled, getOptionLabel: getOptionLabel, customRenderValue: customRenderValue, canDismiss: canDismissChip, removeSelection: removeSelection, unsafeClassName: unsafeClassName, unsafeStyle: unsafeStyle }),
1300
+ React.createElement("input", Object.assign({ ref: mergedInputRef, className: styles.inlineInput, id: inputId, value: inputValue, onChange: readOnly
1301
+ ? undefined
1302
+ : e => onInputChangeFromUser(e.target.value), disabled: disabled, readOnly: readOnly, name: name, autoComplete: "off", autoFocus: autoFocus }, inputAriaProps, inputDataAttrs))))),
1303
+ children));
1304
+ }
1305
+
1306
+ exports.Autocomplete = Autocomplete;