@salt-ds/lab 1.0.0-alpha.30 → 1.0.0-alpha.32

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 (147) hide show
  1. package/css/salt-lab.css +126 -176
  2. package/dist-cjs/app-header/AppHeader.css.js +1 -1
  3. package/dist-cjs/combo-box-next/ComboBoxNext.js +286 -291
  4. package/dist-cjs/combo-box-next/ComboBoxNext.js.map +1 -1
  5. package/dist-cjs/combo-box-next/useComboBoxNext.js +21 -9
  6. package/dist-cjs/combo-box-next/useComboBoxNext.js.map +1 -1
  7. package/dist-cjs/content-status/internal/StatusIndicator.js +1 -3
  8. package/dist-cjs/content-status/internal/StatusIndicator.js.map +1 -1
  9. package/dist-cjs/dialog/Dialog.css.js +1 -1
  10. package/dist-cjs/dialog/Dialog.js +70 -48
  11. package/dist-cjs/dialog/Dialog.js.map +1 -1
  12. package/dist-cjs/dialog/DialogActions.js.map +1 -1
  13. package/dist-cjs/dialog/DialogContent.css.js +1 -1
  14. package/dist-cjs/dialog/DialogContent.js +17 -8
  15. package/dist-cjs/dialog/DialogContent.js.map +1 -1
  16. package/dist-cjs/dialog/DialogContext.js +4 -1
  17. package/dist-cjs/dialog/DialogContext.js.map +1 -1
  18. package/dist-cjs/dialog/DialogTitle.css.js +1 -1
  19. package/dist-cjs/dialog/DialogTitle.js +21 -8
  20. package/dist-cjs/dialog/DialogTitle.js.map +1 -1
  21. package/dist-cjs/drawer/Drawer.css.js +1 -1
  22. package/dist-cjs/drawer/Drawer.js +61 -36
  23. package/dist-cjs/drawer/Drawer.js.map +1 -1
  24. package/dist-cjs/drawer/DrawerCloseButton.css.js +6 -0
  25. package/dist-cjs/drawer/DrawerCloseButton.css.js.map +1 -0
  26. package/dist-cjs/drawer/DrawerCloseButton.js +44 -0
  27. package/dist-cjs/drawer/DrawerCloseButton.js.map +1 -0
  28. package/dist-cjs/dropdown-next/DropdownNext.js +294 -308
  29. package/dist-cjs/dropdown-next/DropdownNext.js.map +1 -1
  30. package/dist-cjs/index.js +3 -9
  31. package/dist-cjs/index.js.map +1 -1
  32. package/dist-cjs/list-control/ListControlContext.js.map +1 -1
  33. package/dist-cjs/list-control/ListControlState.js +21 -20
  34. package/dist-cjs/list-control/ListControlState.js.map +1 -1
  35. package/dist-cjs/option/Option.js +0 -4
  36. package/dist-cjs/option/Option.js.map +1 -1
  37. package/dist-cjs/option/OptionList.css.js +1 -1
  38. package/dist-cjs/parent-child-layout/ParentChildLayout.css.js +1 -1
  39. package/dist-cjs/parent-child-layout/ParentChildLayout.js +30 -38
  40. package/dist-cjs/parent-child-layout/ParentChildLayout.js.map +1 -1
  41. package/dist-cjs/slider/Slider.css.js +1 -1
  42. package/dist-cjs/stepped-tracker/TrackerConnector/TrackerConnector.css.js +1 -1
  43. package/dist-cjs/tabs-next/TabNext.css.js +1 -1
  44. package/dist-cjs/tabs-next/TabstripNext.css.js +1 -1
  45. package/dist-es/app-header/AppHeader.css.js +1 -1
  46. package/dist-es/combo-box-next/ComboBoxNext.js +287 -292
  47. package/dist-es/combo-box-next/ComboBoxNext.js.map +1 -1
  48. package/dist-es/combo-box-next/useComboBoxNext.js +21 -9
  49. package/dist-es/combo-box-next/useComboBoxNext.js.map +1 -1
  50. package/dist-es/content-status/internal/StatusIndicator.js +1 -3
  51. package/dist-es/content-status/internal/StatusIndicator.js.map +1 -1
  52. package/dist-es/dialog/Dialog.css.js +1 -1
  53. package/dist-es/dialog/Dialog.js +73 -52
  54. package/dist-es/dialog/Dialog.js.map +1 -1
  55. package/dist-es/dialog/DialogActions.js.map +1 -1
  56. package/dist-es/dialog/DialogContent.css.js +1 -1
  57. package/dist-es/dialog/DialogContent.js +19 -10
  58. package/dist-es/dialog/DialogContent.js.map +1 -1
  59. package/dist-es/dialog/DialogContext.js +4 -1
  60. package/dist-es/dialog/DialogContext.js.map +1 -1
  61. package/dist-es/dialog/DialogTitle.css.js +1 -1
  62. package/dist-es/dialog/DialogTitle.js +22 -9
  63. package/dist-es/dialog/DialogTitle.js.map +1 -1
  64. package/dist-es/drawer/Drawer.css.js +1 -1
  65. package/dist-es/drawer/Drawer.js +65 -39
  66. package/dist-es/drawer/Drawer.js.map +1 -1
  67. package/dist-es/drawer/DrawerCloseButton.css.js +4 -0
  68. package/dist-es/drawer/DrawerCloseButton.css.js.map +1 -0
  69. package/dist-es/drawer/DrawerCloseButton.js +36 -0
  70. package/dist-es/drawer/DrawerCloseButton.js.map +1 -0
  71. package/dist-es/dropdown-next/DropdownNext.js +295 -309
  72. package/dist-es/dropdown-next/DropdownNext.js.map +1 -1
  73. package/dist-es/index.js +3 -6
  74. package/dist-es/index.js.map +1 -1
  75. package/dist-es/list-control/ListControlContext.js.map +1 -1
  76. package/dist-es/list-control/ListControlState.js +21 -20
  77. package/dist-es/list-control/ListControlState.js.map +1 -1
  78. package/dist-es/option/Option.js +0 -4
  79. package/dist-es/option/Option.js.map +1 -1
  80. package/dist-es/option/OptionList.css.js +1 -1
  81. package/dist-es/parent-child-layout/ParentChildLayout.css.js +1 -1
  82. package/dist-es/parent-child-layout/ParentChildLayout.js +32 -40
  83. package/dist-es/parent-child-layout/ParentChildLayout.js.map +1 -1
  84. package/dist-es/slider/Slider.css.js +1 -1
  85. package/dist-es/stepped-tracker/TrackerConnector/TrackerConnector.css.js +1 -1
  86. package/dist-es/tabs-next/TabNext.css.js +1 -1
  87. package/dist-es/tabs-next/TabstripNext.css.js +1 -1
  88. package/dist-types/combo-box-next/ComboBoxNext.d.ts +13 -3
  89. package/dist-types/combo-box-next/useComboBoxNext.d.ts +13 -16
  90. package/dist-types/content-status/internal/StatusIndicator.d.ts +1 -1
  91. package/dist-types/dialog/Dialog.d.ts +25 -2
  92. package/dist-types/dialog/DialogContext.d.ts +2 -2
  93. package/dist-types/dialog/DialogTitle.d.ts +19 -5
  94. package/dist-types/drawer/Drawer.d.ts +13 -7
  95. package/dist-types/drawer/DrawerCloseButton.d.ts +2 -0
  96. package/dist-types/drawer/index.d.ts +1 -1
  97. package/dist-types/dropdown-next/DropdownNext.d.ts +13 -3
  98. package/dist-types/index.d.ts +0 -2
  99. package/dist-types/list-control/ListControlContext.d.ts +12 -11
  100. package/dist-types/list-control/ListControlState.d.ts +21 -21
  101. package/dist-types/option/Option.d.ts +1 -1
  102. package/dist-types/parent-child-layout/ParentChildLayout.d.ts +8 -13
  103. package/package.json +2 -2
  104. package/dist-cjs/dialog/useDialog.js +0 -31
  105. package/dist-cjs/dialog/useDialog.js.map +0 -1
  106. package/dist-cjs/drawer/useDrawer.js +0 -31
  107. package/dist-cjs/drawer/useDrawer.js.map +0 -1
  108. package/dist-cjs/parent-child-item/ParentChildItem.css.js +0 -6
  109. package/dist-cjs/parent-child-item/ParentChildItem.css.js.map +0 -1
  110. package/dist-cjs/parent-child-item/ParentChildItem.js +0 -48
  111. package/dist-cjs/parent-child-item/ParentChildItem.js.map +0 -1
  112. package/dist-cjs/progress/CircularProgress/CircularProgress.css.js +0 -6
  113. package/dist-cjs/progress/CircularProgress/CircularProgress.css.js.map +0 -1
  114. package/dist-cjs/progress/CircularProgress/CircularProgress.js +0 -89
  115. package/dist-cjs/progress/CircularProgress/CircularProgress.js.map +0 -1
  116. package/dist-cjs/progress/Info.js +0 -20
  117. package/dist-cjs/progress/Info.js.map +0 -1
  118. package/dist-cjs/progress/LinearProgress/LinearProgress.css.js +0 -6
  119. package/dist-cjs/progress/LinearProgress/LinearProgress.css.js.map +0 -1
  120. package/dist-cjs/progress/LinearProgress/LinearProgress.js +0 -63
  121. package/dist-cjs/progress/LinearProgress/LinearProgress.js.map +0 -1
  122. package/dist-es/dialog/useDialog.js +0 -27
  123. package/dist-es/dialog/useDialog.js.map +0 -1
  124. package/dist-es/drawer/useDrawer.js +0 -27
  125. package/dist-es/drawer/useDrawer.js.map +0 -1
  126. package/dist-es/parent-child-item/ParentChildItem.css.js +0 -4
  127. package/dist-es/parent-child-item/ParentChildItem.css.js.map +0 -1
  128. package/dist-es/parent-child-item/ParentChildItem.js +0 -44
  129. package/dist-es/parent-child-item/ParentChildItem.js.map +0 -1
  130. package/dist-es/progress/CircularProgress/CircularProgress.css.js +0 -4
  131. package/dist-es/progress/CircularProgress/CircularProgress.css.js.map +0 -1
  132. package/dist-es/progress/CircularProgress/CircularProgress.js +0 -85
  133. package/dist-es/progress/CircularProgress/CircularProgress.js.map +0 -1
  134. package/dist-es/progress/Info.js +0 -16
  135. package/dist-es/progress/Info.js.map +0 -1
  136. package/dist-es/progress/LinearProgress/LinearProgress.css.js +0 -4
  137. package/dist-es/progress/LinearProgress/LinearProgress.css.js.map +0 -1
  138. package/dist-es/progress/LinearProgress/LinearProgress.js +0 -59
  139. package/dist-es/progress/LinearProgress/LinearProgress.js.map +0 -1
  140. package/dist-types/dialog/useDialog.d.ts +0 -25
  141. package/dist-types/drawer/useDrawer.d.ts +0 -25
  142. package/dist-types/parent-child-item/ParentChildItem.d.ts +0 -31
  143. package/dist-types/parent-child-item/index.d.ts +0 -1
  144. package/dist-types/progress/CircularProgress/CircularProgress.d.ts +0 -25
  145. package/dist-types/progress/Info.d.ts +0 -6
  146. package/dist-types/progress/LinearProgress/LinearProgress.d.ts +0 -26
  147. package/dist-types/progress/index.d.ts +0 -2
@@ -3,7 +3,7 @@ import { forwardRef, useRef, useEffect } from 'react';
3
3
  import { useListControl } from '../list-control/ListControlState.js';
4
4
  import { ChevronUpIcon, ChevronDownIcon } from '@salt-ds/icons';
5
5
  import { makePrefixer, useFormFieldProps, useFloatingComponent, useFloatingUI, useForkRef, useId, StatusAdornment } from '@salt-ds/core';
6
- import { size, flip } from '@floating-ui/react';
6
+ import { size, flip, useInteractions, useDismiss, useFocus, useClick } from '@floating-ui/react';
7
7
  import { clsx } from 'clsx';
8
8
  import { useWindow } from '@salt-ds/window';
9
9
  import { useComponentCssInjection } from '@salt-ds/styles';
@@ -19,328 +19,314 @@ function ExpandIcon({ open }) {
19
19
  });
20
20
  }
21
21
  const withBaseName = makePrefixer("saltDropdownNext");
22
- const DropdownNext = forwardRef(
23
- function DropdownNext2(props, ref) {
24
- var _a, _b;
25
- const {
26
- "aria-labelledby": ariaLabelledBy,
27
- "aria-describedby": ariaDescribedBy,
28
- children,
29
- className,
30
- disabled: disabledProp,
31
- emptyReadOnlyMarker = "\u2014",
32
- readOnly: readOnlyProp,
33
- multiselect,
34
- onSelectionChange,
35
- selected,
36
- defaultSelected,
37
- defaultOpen,
38
- defaultValue: defaultValueProp,
39
- value,
40
- onOpenChange,
41
- open,
42
- placeholder,
43
- startAdornment,
44
- required: requiredProp,
45
- variant = "primary",
46
- validationStatus: validationStatusProp,
47
- onClick,
48
- onKeyDown,
49
- onFocus,
50
- onBlur,
51
- ...rest
52
- } = props;
53
- const targetWindow = useWindow();
54
- useComponentCssInjection({
55
- testId: "salt-DropdownNext",
56
- css: css_248z,
57
- window: targetWindow
58
- });
59
- const {
60
- a11yProps: {
61
- "aria-describedby": formFieldDescribedBy,
62
- "aria-labelledby": formFieldLabelledBy
63
- } = {},
64
- disabled: formFieldDisabled,
65
- readOnly: formFieldReadOnly,
66
- necessity: formFieldRequired,
67
- validationStatus: formFieldValidationStatus
68
- } = useFormFieldProps();
69
- const disabled = Boolean(disabledProp) || formFieldDisabled;
70
- const readOnly = Boolean(readOnlyProp) || formFieldReadOnly;
71
- const validationStatus = validationStatusProp != null ? validationStatusProp : formFieldValidationStatus;
72
- const required = formFieldRequired ? ["required", "asterisk"].includes(formFieldRequired) : requiredProp;
73
- const isEmptyReadOnly = readOnly && !defaultValueProp && !value;
74
- const defaultValue = isEmptyReadOnly ? emptyReadOnlyMarker : defaultValueProp;
75
- const listControl = useListControl({
76
- open,
77
- defaultOpen,
78
- onOpenChange,
79
- multiselect,
80
- defaultSelected,
81
- selected,
82
- onSelectionChange,
83
- defaultValue,
84
- value
85
- });
86
- const {
87
- activeState,
88
- setActive,
89
- openState,
90
- setOpen,
91
- openKey,
92
- getOptionAtIndex,
93
- getIndexOfOption,
94
- getOptionsMatching,
95
- getOptionFromSearch,
96
- options,
97
- selectedState,
98
- select,
99
- valueState,
100
- setFocusVisibleState,
101
- focusedState,
102
- setFocusedState,
103
- listRef
104
- } = listControl;
105
- const { Component: FloatingComponent } = useFloatingComponent();
106
- const { x, y, strategy, elements, floating, reference } = useFloatingUI({
107
- open,
108
- placement: "bottom-start",
109
- middleware: [
110
- size({
111
- apply({ rects, elements: elements2, availableHeight }) {
112
- Object.assign(elements2.floating.style, {
113
- minWidth: `${rects.reference.width}px`,
114
- maxHeight: `max(calc((var(--salt-size-base) + var(--salt-spacing-100)) * 5), calc(${availableHeight}px - var(--salt-spacing-100)))`
115
- });
116
- }
117
- }),
118
- flip({ fallbackStrategy: "initialPlacement" })
119
- ]
120
- });
121
- const buttonRef = useRef(null);
122
- const handleTriggerRef = useForkRef(
123
- reference,
124
- buttonRef
125
- );
126
- const handleButtonRef = useForkRef(handleTriggerRef, ref);
127
- const handleClick = (event) => {
128
- if (!readOnly) {
129
- setFocusVisibleState(false);
130
- setOpen(event, !openState);
131
- }
132
- onClick == null ? void 0 : onClick(event);
133
- };
134
- const typeaheadString = useRef("");
135
- const typeaheadTimeout = useRef();
136
- const handleTypeahead = (event) => {
137
- if (typeaheadTimeout.current) {
138
- clearTimeout(typeaheadTimeout.current);
139
- }
140
- typeaheadString.current += event.key;
141
- typeaheadTimeout.current = window.setTimeout(() => {
142
- typeaheadString.current = "";
143
- }, 500);
144
- if (!openState) {
145
- setOpen(event, true);
146
- }
147
- let newOption = getOptionFromSearch(typeaheadString.current, activeState);
148
- if (!newOption) {
149
- newOption = getOptionFromSearch(typeaheadString.current);
150
- }
151
- if (newOption) {
152
- setActive(newOption);
153
- setFocusVisibleState(true);
154
- }
155
- };
156
- const handleKeyDown = (event) => {
157
- const currentIndex = activeState ? getIndexOfOption(activeState) : -1;
158
- const count = options.length - 1;
159
- if (readOnly) {
22
+ const DropdownNext = forwardRef(function DropdownNext2(props, ref) {
23
+ var _a, _b;
24
+ const {
25
+ "aria-labelledby": ariaLabelledBy,
26
+ "aria-describedby": ariaDescribedBy,
27
+ children,
28
+ className,
29
+ disabled: disabledProp,
30
+ emptyReadOnlyMarker = "\u2014",
31
+ readOnly: readOnlyProp,
32
+ multiselect,
33
+ onSelectionChange,
34
+ selected,
35
+ defaultSelected,
36
+ defaultOpen,
37
+ defaultValue: defaultValueProp,
38
+ value,
39
+ onOpenChange,
40
+ open,
41
+ placeholder,
42
+ startAdornment,
43
+ required: requiredProp,
44
+ variant = "primary",
45
+ validationStatus: validationStatusProp,
46
+ onKeyDown,
47
+ onFocus,
48
+ onBlur,
49
+ ...rest
50
+ } = props;
51
+ const targetWindow = useWindow();
52
+ useComponentCssInjection({
53
+ testId: "salt-DropdownNext",
54
+ css: css_248z,
55
+ window: targetWindow
56
+ });
57
+ const {
58
+ a11yProps: {
59
+ "aria-describedby": formFieldDescribedBy,
60
+ "aria-labelledby": formFieldLabelledBy
61
+ } = {},
62
+ disabled: formFieldDisabled,
63
+ readOnly: formFieldReadOnly,
64
+ necessity: formFieldRequired,
65
+ validationStatus: formFieldValidationStatus
66
+ } = useFormFieldProps();
67
+ const disabled = Boolean(disabledProp) || formFieldDisabled;
68
+ const readOnly = Boolean(readOnlyProp) || formFieldReadOnly;
69
+ const validationStatus = validationStatusProp != null ? validationStatusProp : formFieldValidationStatus;
70
+ const required = formFieldRequired ? ["required", "asterisk"].includes(formFieldRequired) : requiredProp;
71
+ const isEmptyReadOnly = readOnly && !defaultValueProp && !value;
72
+ const defaultValue = isEmptyReadOnly ? emptyReadOnlyMarker : defaultValueProp;
73
+ const listControl = useListControl({
74
+ open,
75
+ defaultOpen,
76
+ onOpenChange,
77
+ multiselect,
78
+ defaultSelected,
79
+ selected,
80
+ onSelectionChange,
81
+ defaultValue,
82
+ value
83
+ });
84
+ const {
85
+ activeState,
86
+ setActive,
87
+ openState,
88
+ setOpen,
89
+ openKey,
90
+ getOptionAtIndex,
91
+ getIndexOfOption,
92
+ getOptionsMatching,
93
+ getOptionFromSearch,
94
+ options,
95
+ selectedState,
96
+ select,
97
+ valueState,
98
+ setFocusVisibleState,
99
+ focusedState,
100
+ setFocusedState,
101
+ listRef
102
+ } = listControl;
103
+ const { Component: FloatingComponent } = useFloatingComponent();
104
+ const handleOpenChange = (newOpen, _event, reason) => {
105
+ const focusNotBlur = reason === "focus" && newOpen;
106
+ if (readOnly || focusNotBlur)
107
+ return;
108
+ setOpen(newOpen);
109
+ };
110
+ const { x, y, strategy, elements, floating, reference, context } = useFloatingUI({
111
+ open: openState && !readOnly && children != void 0,
112
+ onOpenChange: handleOpenChange,
113
+ placement: "bottom-start",
114
+ middleware: [
115
+ size({
116
+ apply({ rects, elements: elements2, availableHeight }) {
117
+ Object.assign(elements2.floating.style, {
118
+ minWidth: `${rects.reference.width}px`,
119
+ maxHeight: `max(calc((var(--salt-size-base) + var(--salt-spacing-100)) * 5), calc(${availableHeight}px - var(--salt-spacing-100)))`
120
+ });
121
+ }
122
+ }),
123
+ flip({ fallbackStrategy: "initialPlacement" })
124
+ ]
125
+ });
126
+ const { getReferenceProps, getFloatingProps } = useInteractions([
127
+ useDismiss(context),
128
+ useFocus(context),
129
+ useClick(context)
130
+ ]);
131
+ const buttonRef = useRef(null);
132
+ const handleTriggerRef = useForkRef(reference, buttonRef);
133
+ const handleButtonRef = useForkRef(handleTriggerRef, ref);
134
+ const typeaheadString = useRef("");
135
+ const typeaheadTimeout = useRef();
136
+ const handleTypeahead = (event) => {
137
+ if (typeaheadTimeout.current) {
138
+ clearTimeout(typeaheadTimeout.current);
139
+ }
140
+ typeaheadString.current += event.key;
141
+ typeaheadTimeout.current = window.setTimeout(() => {
142
+ typeaheadString.current = "";
143
+ }, 500);
144
+ if (!openState) {
145
+ setOpen(true, "input");
146
+ }
147
+ let newOption = getOptionFromSearch(typeaheadString.current, activeState);
148
+ if (!newOption) {
149
+ newOption = getOptionFromSearch(typeaheadString.current);
150
+ }
151
+ if (newOption) {
152
+ setActive(newOption);
153
+ setFocusVisibleState(true);
154
+ }
155
+ };
156
+ const handleKeyDown = (event) => {
157
+ const currentIndex = activeState ? getIndexOfOption(activeState) : -1;
158
+ const count = options.length - 1;
159
+ if (readOnly) {
160
+ return;
161
+ }
162
+ if (!openState) {
163
+ if (event.key === "ArrowDown" || event.key === "ArrowUp") {
164
+ setOpen(true, void 0, event.key);
160
165
  return;
161
166
  }
162
- if (!openState) {
163
- if (event.key === "ArrowDown" || event.key === "ArrowUp") {
164
- setOpen(event, true);
167
+ }
168
+ if (event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey) {
169
+ event.preventDefault();
170
+ event.stopPropagation();
171
+ handleTypeahead(event);
172
+ }
173
+ let newActive;
174
+ switch (event.key) {
175
+ case "ArrowDown":
176
+ newActive = getOptionAtIndex(Math.min(count, currentIndex + 1));
177
+ break;
178
+ case "ArrowUp":
179
+ newActive = getOptionAtIndex(Math.max(0, currentIndex - 1));
180
+ break;
181
+ case "Home":
182
+ newActive = getOptionAtIndex(0);
183
+ break;
184
+ case "End":
185
+ newActive = getOptionAtIndex(count);
186
+ break;
187
+ case "PageUp":
188
+ newActive = getOptionAtIndex(Math.max(0, currentIndex - 10));
189
+ break;
190
+ case "PageDown":
191
+ newActive = getOptionAtIndex(Math.min(count, currentIndex + 10));
192
+ break;
193
+ case "Enter":
194
+ case " ":
195
+ if (openState && Boolean(activeState == null ? void 0 : activeState.disabled) || typeaheadString.current.trim().length > 0 && event.key === " ") {
196
+ event.preventDefault();
197
+ return;
198
+ }
199
+ if (!openState || !activeState) {
165
200
  return;
166
201
  }
167
- }
168
- if (event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey) {
169
202
  event.preventDefault();
170
- event.stopPropagation();
171
- handleTypeahead(event);
172
- }
173
- let newActive;
174
- switch (event.key) {
175
- case "ArrowDown":
176
- newActive = getOptionAtIndex(Math.min(count, currentIndex + 1));
177
- break;
178
- case "ArrowUp":
179
- newActive = getOptionAtIndex(Math.max(0, currentIndex - 1));
180
- break;
181
- case "Home":
182
- newActive = getOptionAtIndex(0);
183
- break;
184
- case "End":
185
- newActive = getOptionAtIndex(count);
186
- break;
187
- case "PageUp":
188
- newActive = getOptionAtIndex(Math.max(0, currentIndex - 10));
189
- break;
190
- case "PageDown":
191
- newActive = getOptionAtIndex(Math.min(count, currentIndex + 10));
192
- break;
193
- case "Enter":
194
- case " ":
195
- if (openState && Boolean(activeState == null ? void 0 : activeState.disabled) || typeaheadString.current.trim().length > 0 && event.key === " ") {
196
- event.preventDefault();
197
- return;
198
- }
199
- if (!openState || !activeState) {
200
- return;
201
- }
202
- event.preventDefault();
203
+ select(event, activeState);
204
+ break;
205
+ case "Tab":
206
+ if (!multiselect && activeState) {
203
207
  select(event, activeState);
204
- if (!multiselect) {
205
- setOpen(event, false);
206
- }
207
- break;
208
- case "Escape":
209
- setOpen(event, false);
210
- break;
211
- case "Tab":
212
- if (!multiselect && activeState) {
213
- select(event, activeState);
214
- }
215
- break;
216
- }
217
- if (newActive && (newActive == null ? void 0 : newActive.id) != (activeState == null ? void 0 : activeState.id)) {
218
- event.preventDefault();
219
- setActive(newActive);
220
- setFocusVisibleState(true);
221
- }
222
- onKeyDown == null ? void 0 : onKeyDown(event);
223
- };
224
- const handleFocus = (event) => {
225
- setFocusedState(true);
226
- onFocus == null ? void 0 : onFocus(event);
227
- };
228
- const ignoreBlur = useRef(false);
229
- const handleBlur = (event) => {
230
- if (!ignoreBlur.current) {
231
- setOpen(event, false);
232
- }
233
- ignoreBlur.current = false;
234
- setFocusedState(false);
235
- onBlur == null ? void 0 : onBlur(event);
236
- };
237
- const handleListMouseOver = () => {
238
- setFocusVisibleState(false);
239
- };
240
- const handleListMouseDown = () => {
241
- ignoreBlur.current = true;
242
- };
243
- const handleListFocus = () => {
244
- var _a2;
245
- (_a2 = buttonRef.current) == null ? void 0 : _a2.focus();
246
- };
247
- const handleListClick = () => {
248
- var _a2;
249
- (_a2 = buttonRef.current) == null ? void 0 : _a2.focus();
250
- };
251
- useEffect(() => {
252
- const activeIndex = activeState ? getIndexOfOption(activeState) : -1;
253
- if (openState && activeIndex < 0) {
254
- if (openKey.current.key === "ArrowDown") {
255
- setActive(getOptionAtIndex(0));
256
- } else if (openKey.current.key === "ArrowUp") {
257
- setActive(getOptionAtIndex(options.length - 1));
258
- } else {
259
- if (selectedState.length > 0) {
260
- const selected2 = getOptionsMatching(
261
- (option) => option.value === selectedState[0]
262
- ).pop();
263
- if (selected2) {
264
- setActive(selected2);
265
- }
266
- } else {
267
- setActive(getOptionAtIndex(0));
268
- }
269
208
  }
270
- } else if (!openState) {
271
- setActive(void 0);
209
+ break;
210
+ }
211
+ if (newActive && (newActive == null ? void 0 : newActive.id) != (activeState == null ? void 0 : activeState.id)) {
212
+ event.preventDefault();
213
+ setActive(newActive);
214
+ setFocusVisibleState(true);
215
+ }
216
+ onKeyDown == null ? void 0 : onKeyDown(event);
217
+ };
218
+ const handleFocus = (event) => {
219
+ setFocusedState(true);
220
+ onFocus == null ? void 0 : onFocus(event);
221
+ };
222
+ const handleBlur = (event) => {
223
+ setFocusedState(false);
224
+ onBlur == null ? void 0 : onBlur(event);
225
+ };
226
+ const handleListMouseOver = () => {
227
+ setFocusVisibleState(false);
228
+ };
229
+ const handleFocusButton = () => {
230
+ var _a2;
231
+ (_a2 = buttonRef.current) == null ? void 0 : _a2.focus();
232
+ };
233
+ useEffect(() => {
234
+ const activeIndex = activeState ? getIndexOfOption(activeState) : -1;
235
+ let newActive = void 0;
236
+ if (activeIndex > 0) {
237
+ return;
238
+ }
239
+ if (!openState) {
240
+ setActive(void 0);
241
+ return;
242
+ }
243
+ if (selectedState.length > 0) {
244
+ newActive = getOptionsMatching(
245
+ (option) => option.value === selectedState[0]
246
+ ).pop();
247
+ }
248
+ if (!newActive) {
249
+ if (openKey.current === "ArrowDown") {
250
+ newActive = getOptionAtIndex(0);
251
+ } else if (openKey.current === "ArrowUp") {
252
+ newActive = getOptionAtIndex(options.length - 1);
272
253
  }
273
- }, [openState, children]);
274
- const listId = useId();
275
- return /* @__PURE__ */ jsxs(ListControlContext.Provider, {
276
- value: listControl,
277
- children: [
278
- /* @__PURE__ */ jsxs("button", {
279
- className: clsx(
280
- withBaseName(),
281
- withBaseName(variant),
282
- {
283
- [withBaseName("disabled")]: disabled,
284
- [withBaseName(validationStatus != null ? validationStatus : "")]: validationStatus
285
- },
286
- className
287
- ),
288
- ref: handleButtonRef,
289
- onClick: handleClick,
254
+ }
255
+ if (!newActive) {
256
+ newActive = getOptionAtIndex(0);
257
+ }
258
+ setActive(newActive);
259
+ }, [openState, children]);
260
+ const listId = useId();
261
+ return /* @__PURE__ */ jsxs(ListControlContext.Provider, {
262
+ value: listControl,
263
+ children: [
264
+ /* @__PURE__ */ jsxs("button", {
265
+ className: clsx(
266
+ withBaseName(),
267
+ withBaseName(variant),
268
+ {
269
+ [withBaseName("disabled")]: disabled,
270
+ [withBaseName(validationStatus != null ? validationStatus : "")]: validationStatus
271
+ },
272
+ className
273
+ ),
274
+ ref: handleButtonRef,
275
+ role: "combobox",
276
+ type: "button",
277
+ disabled,
278
+ "aria-readonly": readOnly ? "true" : void 0,
279
+ "aria-required": required ? "true" : void 0,
280
+ "aria-expanded": openState,
281
+ "aria-activedescendant": activeState == null ? void 0 : activeState.id,
282
+ "aria-labelledby": clsx(formFieldLabelledBy, ariaLabelledBy) || void 0,
283
+ "aria-describedby": clsx(formFieldDescribedBy, ariaDescribedBy) || void 0,
284
+ "aria-multiselectable": multiselect,
285
+ "aria-controls": openState ? listId : void 0,
286
+ ...getReferenceProps({
290
287
  onKeyDown: handleKeyDown,
291
288
  onFocus: handleFocus,
292
289
  onBlur: handleBlur,
293
- role: "combobox",
294
- type: "button",
295
- disabled,
296
- "aria-readonly": readOnly ? "true" : void 0,
297
- "aria-required": required ? "true" : void 0,
298
- "aria-expanded": openState,
299
- "aria-activedescendant": activeState == null ? void 0 : activeState.id,
300
- "aria-labelledby": clsx(formFieldLabelledBy, ariaLabelledBy) || void 0,
301
- "aria-describedby": clsx(formFieldDescribedBy, ariaDescribedBy) || void 0,
302
- "aria-multiselectable": multiselect,
303
- "aria-controls": openState ? listId : void 0,
304
- ...rest,
305
- children: [
306
- startAdornment,
307
- /* @__PURE__ */ jsx("span", {
308
- className: clsx(withBaseName("content"), {
309
- [withBaseName("placeholder")]: !valueState
310
- }),
311
- children: valueState != null ? valueState : placeholder
312
- }),
313
- validationStatus && /* @__PURE__ */ jsx(StatusAdornment, {
314
- status: validationStatus
315
- }),
316
- !readOnly && /* @__PURE__ */ jsx(ExpandIcon, {
317
- open: openState
318
- })
319
- ]
290
+ ...rest
320
291
  }),
321
- /* @__PURE__ */ jsx(FloatingComponent, {
322
- open: (openState || focusedState) && !readOnly,
323
- left: x != null ? x : 0,
324
- top: y != null ? y : 0,
325
- position: strategy,
326
- width: (_a = elements.floating) == null ? void 0 : _a.offsetWidth,
327
- height: (_b = elements.floating) == null ? void 0 : _b.offsetHeight,
328
- ref: floating,
329
- children: /* @__PURE__ */ jsx(OptionList, {
330
- id: listId,
331
- collapsed: !openState,
332
- onMouseOver: handleListMouseOver,
333
- onMouseDown: handleListMouseDown,
334
- onFocus: handleListFocus,
335
- onClick: handleListClick,
336
- ref: listRef,
337
- children
292
+ children: [
293
+ startAdornment,
294
+ /* @__PURE__ */ jsx("span", {
295
+ className: clsx(withBaseName("content"), {
296
+ [withBaseName("placeholder")]: !valueState
297
+ }),
298
+ children: !valueState ? placeholder : valueState
299
+ }),
300
+ validationStatus && /* @__PURE__ */ jsx(StatusAdornment, {
301
+ status: validationStatus
302
+ }),
303
+ !readOnly && /* @__PURE__ */ jsx(ExpandIcon, {
304
+ open: openState
338
305
  })
306
+ ]
307
+ }),
308
+ /* @__PURE__ */ jsx(FloatingComponent, {
309
+ open: (openState || focusedState) && !readOnly && children != void 0,
310
+ ...getFloatingProps(),
311
+ left: x != null ? x : 0,
312
+ top: y != null ? y : 0,
313
+ position: strategy,
314
+ width: (_a = elements.floating) == null ? void 0 : _a.offsetWidth,
315
+ height: (_b = elements.floating) == null ? void 0 : _b.offsetHeight,
316
+ ref: floating,
317
+ children: /* @__PURE__ */ jsx(OptionList, {
318
+ id: listId,
319
+ collapsed: !openState,
320
+ onMouseOver: handleListMouseOver,
321
+ onFocus: handleFocusButton,
322
+ onClick: handleFocusButton,
323
+ ref: listRef,
324
+ children
339
325
  })
340
- ]
341
- });
342
- }
343
- );
326
+ })
327
+ ]
328
+ });
329
+ });
344
330
 
345
331
  export { DropdownNext };
346
332
  //# sourceMappingURL=DropdownNext.js.map