@proyecto-viviana/solidaria 0.2.2 → 0.2.3

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 (210) hide show
  1. package/dist/autocomplete/createAutocomplete.d.ts +2 -2
  2. package/dist/autocomplete/createAutocomplete.d.ts.map +1 -1
  3. package/dist/index.js +233 -234
  4. package/dist/index.js.map +2 -2
  5. package/dist/index.ssr.js +233 -234
  6. package/dist/index.ssr.js.map +2 -2
  7. package/dist/interactions/PressEvent.d.ts +13 -10
  8. package/dist/interactions/PressEvent.d.ts.map +1 -1
  9. package/dist/interactions/createPress.d.ts.map +1 -1
  10. package/dist/interactions/index.d.ts +1 -1
  11. package/dist/interactions/index.d.ts.map +1 -1
  12. package/dist/select/createHiddenSelect.d.ts.map +1 -1
  13. package/dist/toolbar/createToolbar.d.ts.map +1 -1
  14. package/dist/tooltip/createTooltipTrigger.d.ts.map +1 -1
  15. package/package.json +9 -7
  16. package/src/autocomplete/createAutocomplete.ts +341 -0
  17. package/src/autocomplete/index.ts +9 -0
  18. package/src/breadcrumbs/createBreadcrumbs.ts +196 -0
  19. package/src/breadcrumbs/index.ts +8 -0
  20. package/src/button/createButton.ts +142 -0
  21. package/src/button/createToggleButton.ts +101 -0
  22. package/src/button/index.ts +4 -0
  23. package/src/button/types.ts +78 -0
  24. package/src/calendar/createCalendar.ts +138 -0
  25. package/src/calendar/createCalendarCell.ts +187 -0
  26. package/src/calendar/createCalendarGrid.ts +140 -0
  27. package/src/calendar/createRangeCalendar.ts +136 -0
  28. package/src/calendar/createRangeCalendarCell.ts +186 -0
  29. package/src/calendar/index.ts +34 -0
  30. package/src/checkbox/createCheckbox.ts +135 -0
  31. package/src/checkbox/createCheckboxGroup.ts +137 -0
  32. package/src/checkbox/createCheckboxGroupItem.ts +117 -0
  33. package/src/checkbox/createCheckboxGroupState.ts +193 -0
  34. package/src/checkbox/index.ts +13 -0
  35. package/src/color/createColorArea.ts +314 -0
  36. package/src/color/createColorField.ts +137 -0
  37. package/src/color/createColorSlider.ts +197 -0
  38. package/src/color/createColorSwatch.ts +40 -0
  39. package/src/color/createColorWheel.ts +208 -0
  40. package/src/color/index.ts +24 -0
  41. package/src/color/types.ts +116 -0
  42. package/src/combobox/createComboBox.ts +647 -0
  43. package/src/combobox/index.ts +6 -0
  44. package/src/combobox/intl/en-US.json +7 -0
  45. package/src/combobox/intl/es-ES.json +7 -0
  46. package/src/combobox/intl/index.ts +23 -0
  47. package/src/datepicker/createDateField.ts +154 -0
  48. package/src/datepicker/createDatePicker.ts +206 -0
  49. package/src/datepicker/createDateSegment.ts +229 -0
  50. package/src/datepicker/createTimeField.ts +154 -0
  51. package/src/datepicker/index.ts +28 -0
  52. package/src/dialog/createDialog.ts +120 -0
  53. package/src/dialog/index.ts +2 -0
  54. package/src/dialog/types.ts +19 -0
  55. package/src/disclosure/createDisclosure.ts +131 -0
  56. package/src/disclosure/createDisclosureGroup.ts +62 -0
  57. package/src/disclosure/index.ts +11 -0
  58. package/src/dnd/createDrag.ts +209 -0
  59. package/src/dnd/createDraggableCollection.ts +63 -0
  60. package/src/dnd/createDraggableItem.ts +243 -0
  61. package/src/dnd/createDrop.ts +321 -0
  62. package/src/dnd/createDroppableCollection.ts +293 -0
  63. package/src/dnd/createDroppableItem.ts +213 -0
  64. package/src/dnd/index.ts +47 -0
  65. package/src/dnd/types.ts +89 -0
  66. package/src/dnd/utils.ts +294 -0
  67. package/src/focus/FocusScope.tsx +408 -0
  68. package/src/focus/createAutoFocus.ts +321 -0
  69. package/src/focus/createFocusRestore.ts +313 -0
  70. package/src/focus/createVirtualFocus.ts +396 -0
  71. package/src/focus/index.ts +35 -0
  72. package/src/form/createFormReset.ts +51 -0
  73. package/src/form/createFormValidation.ts +224 -0
  74. package/src/form/index.ts +11 -0
  75. package/src/grid/GridKeyboardDelegate.ts +429 -0
  76. package/src/grid/createGrid.ts +261 -0
  77. package/src/grid/createGridCell.ts +182 -0
  78. package/src/grid/createGridRow.ts +153 -0
  79. package/src/grid/index.ts +18 -0
  80. package/src/grid/types.ts +133 -0
  81. package/src/gridlist/createGridList.ts +185 -0
  82. package/src/gridlist/createGridListItem.ts +180 -0
  83. package/src/gridlist/createGridListSelectionCheckbox.ts +59 -0
  84. package/src/gridlist/index.ts +16 -0
  85. package/src/gridlist/types.ts +81 -0
  86. package/src/i18n/NumberFormatter.ts +266 -0
  87. package/src/i18n/createCollator.ts +79 -0
  88. package/src/i18n/createDateFormatter.ts +83 -0
  89. package/src/i18n/createFilter.ts +131 -0
  90. package/src/i18n/createNumberFormatter.ts +52 -0
  91. package/src/i18n/createStringFormatter.ts +87 -0
  92. package/src/i18n/index.ts +40 -0
  93. package/src/i18n/locale.tsx +188 -0
  94. package/src/i18n/utils.ts +99 -0
  95. package/src/index.ts +670 -0
  96. package/src/interactions/FocusableProvider.tsx +44 -0
  97. package/src/interactions/PressEvent.ts +126 -0
  98. package/src/interactions/createFocus.ts +163 -0
  99. package/src/interactions/createFocusRing.ts +89 -0
  100. package/src/interactions/createFocusWithin.ts +206 -0
  101. package/src/interactions/createFocusable.ts +168 -0
  102. package/src/interactions/createHover.ts +254 -0
  103. package/src/interactions/createInteractionModality.ts +424 -0
  104. package/src/interactions/createKeyboard.ts +82 -0
  105. package/src/interactions/createLongPress.ts +174 -0
  106. package/src/interactions/createMove.ts +289 -0
  107. package/src/interactions/createPress.ts +834 -0
  108. package/src/interactions/index.ts +78 -0
  109. package/src/label/createField.ts +145 -0
  110. package/src/label/createLabel.ts +117 -0
  111. package/src/label/createLabels.ts +50 -0
  112. package/src/label/index.ts +19 -0
  113. package/src/landmark/createLandmark.ts +377 -0
  114. package/src/landmark/index.ts +8 -0
  115. package/src/link/createLink.ts +182 -0
  116. package/src/link/index.ts +1 -0
  117. package/src/listbox/createListBox.ts +269 -0
  118. package/src/listbox/createOption.ts +151 -0
  119. package/src/listbox/index.ts +12 -0
  120. package/src/live-announcer/announce.ts +322 -0
  121. package/src/live-announcer/index.ts +9 -0
  122. package/src/menu/createMenu.ts +396 -0
  123. package/src/menu/createMenuItem.ts +149 -0
  124. package/src/menu/createMenuTrigger.ts +88 -0
  125. package/src/menu/index.ts +18 -0
  126. package/src/meter/createMeter.ts +75 -0
  127. package/src/meter/index.ts +1 -0
  128. package/src/numberfield/createNumberField.ts +268 -0
  129. package/src/numberfield/index.ts +5 -0
  130. package/src/overlays/ariaHideOutside.ts +219 -0
  131. package/src/overlays/createInteractOutside.ts +149 -0
  132. package/src/overlays/createModal.tsx +202 -0
  133. package/src/overlays/createOverlay.ts +155 -0
  134. package/src/overlays/createOverlayTrigger.ts +85 -0
  135. package/src/overlays/createPreventScroll.ts +266 -0
  136. package/src/overlays/index.ts +44 -0
  137. package/src/popover/calculatePosition.ts +766 -0
  138. package/src/popover/createOverlayPosition.ts +356 -0
  139. package/src/popover/createPopover.ts +170 -0
  140. package/src/popover/index.ts +24 -0
  141. package/src/progress/createProgressBar.ts +128 -0
  142. package/src/progress/index.ts +5 -0
  143. package/src/radio/createRadio.ts +287 -0
  144. package/src/radio/createRadioGroup.ts +189 -0
  145. package/src/radio/createRadioGroupState.ts +201 -0
  146. package/src/radio/index.ts +23 -0
  147. package/src/searchfield/createSearchField.ts +186 -0
  148. package/src/searchfield/index.ts +2 -0
  149. package/src/select/createHiddenSelect.tsx +236 -0
  150. package/src/select/createSelect.ts +395 -0
  151. package/src/select/index.ts +14 -0
  152. package/src/selection/createTypeSelect.ts +201 -0
  153. package/src/selection/index.ts +6 -0
  154. package/src/separator/createSeparator.ts +82 -0
  155. package/src/separator/index.ts +6 -0
  156. package/src/slider/createSlider.ts +349 -0
  157. package/src/slider/index.ts +2 -0
  158. package/src/ssr/index.tsx +370 -0
  159. package/src/switch/createSwitch.ts +70 -0
  160. package/src/switch/index.ts +1 -0
  161. package/src/table/createTable.ts +526 -0
  162. package/src/table/createTableCell.ts +147 -0
  163. package/src/table/createTableColumnHeader.ts +115 -0
  164. package/src/table/createTableHeaderRow.ts +40 -0
  165. package/src/table/createTableRow.ts +155 -0
  166. package/src/table/createTableRowGroup.ts +32 -0
  167. package/src/table/createTableSelectAllCheckbox.ts +73 -0
  168. package/src/table/createTableSelectionCheckbox.ts +59 -0
  169. package/src/table/index.ts +30 -0
  170. package/src/table/types.ts +165 -0
  171. package/src/tabs/createTabs.ts +472 -0
  172. package/src/tabs/index.ts +14 -0
  173. package/src/tag/createTag.ts +194 -0
  174. package/src/tag/createTagGroup.ts +154 -0
  175. package/src/tag/index.ts +12 -0
  176. package/src/textfield/createTextField.ts +198 -0
  177. package/src/textfield/index.ts +5 -0
  178. package/src/toast/createToast.ts +118 -0
  179. package/src/toast/createToastRegion.ts +100 -0
  180. package/src/toast/index.ts +11 -0
  181. package/src/toggle/createToggle.ts +223 -0
  182. package/src/toggle/createToggleState.ts +94 -0
  183. package/src/toggle/index.ts +7 -0
  184. package/src/toolbar/createToolbar.ts +369 -0
  185. package/src/toolbar/index.ts +6 -0
  186. package/src/tooltip/createTooltip.ts +79 -0
  187. package/src/tooltip/createTooltipTrigger.ts +222 -0
  188. package/src/tooltip/index.ts +6 -0
  189. package/src/tree/createTree.ts +246 -0
  190. package/src/tree/createTreeItem.ts +233 -0
  191. package/src/tree/createTreeSelectionCheckbox.ts +68 -0
  192. package/src/tree/index.ts +16 -0
  193. package/src/tree/types.ts +87 -0
  194. package/src/utils/createDescription.ts +137 -0
  195. package/src/utils/dom.ts +327 -0
  196. package/src/utils/env.ts +54 -0
  197. package/src/utils/events.ts +106 -0
  198. package/src/utils/filterDOMProps.ts +116 -0
  199. package/src/utils/focus.ts +151 -0
  200. package/src/utils/geometry.ts +115 -0
  201. package/src/utils/globalListeners.ts +142 -0
  202. package/src/utils/index.ts +80 -0
  203. package/src/utils/mergeProps.ts +52 -0
  204. package/src/utils/platform.ts +52 -0
  205. package/src/utils/reactivity.ts +36 -0
  206. package/src/utils/textSelection.ts +114 -0
  207. package/src/visually-hidden/createVisuallyHidden.ts +124 -0
  208. package/src/visually-hidden/index.ts +6 -0
  209. package/dist/index.jsx +0 -15845
  210. package/dist/index.jsx.map +0 -7
@@ -0,0 +1,395 @@
1
+ /**
2
+ * Provides the behavior and accessibility implementation for a select component.
3
+ * A select displays a collapsible list of options and allows a user to select one of them.
4
+ * Based on @react-aria/select useSelect.
5
+ */
6
+
7
+ import { type JSX, type Accessor, createEffect, onCleanup } from 'solid-js';
8
+ import { createPress } from '../interactions/createPress';
9
+ import { createFocusRing } from '../interactions/createFocusRing';
10
+ import { createLabel } from '../label/createLabel';
11
+ import { createTypeSelect } from '../selection/createTypeSelect';
12
+ import { filterDOMProps } from '../utils/filterDOMProps';
13
+ import { mergeProps } from '../utils/mergeProps';
14
+ import { createId } from '../ssr';
15
+ import { access, type MaybeAccessor } from '../utils/reactivity';
16
+ import type { SelectState, CollectionNode } from '@proyecto-viviana/solid-stately';
17
+
18
+ export interface AriaSelectProps {
19
+ /** An ID for the select. */
20
+ id?: string;
21
+ /** Whether the select is disabled. */
22
+ isDisabled?: boolean;
23
+ /** Whether the select is required. */
24
+ isRequired?: boolean;
25
+ /** The label for the select. */
26
+ label?: JSX.Element;
27
+ /** An accessible label for the select when no visible label is provided. */
28
+ 'aria-label'?: string;
29
+ /** The ID of an element that labels the select. */
30
+ 'aria-labelledby'?: string;
31
+ /** The ID of an element that describes the select. */
32
+ 'aria-describedby'?: string;
33
+ /** Placeholder text when no option is selected. */
34
+ placeholder?: string;
35
+ /** Whether the select should be auto-focused. */
36
+ autoFocus?: boolean;
37
+ /** Handler called when focus moves to the select. */
38
+ onFocus?: (e: FocusEvent) => void;
39
+ /** Handler called when focus moves away from the select. */
40
+ onBlur?: (e: FocusEvent) => void;
41
+ /** Handler called when the focus state changes. */
42
+ onFocusChange?: (isFocused: boolean) => void;
43
+ /** The name of the select, used when submitting an HTML form. */
44
+ name?: string;
45
+ /** Whether type-to-select is disabled. @default false */
46
+ disallowTypeAhead?: boolean;
47
+ }
48
+
49
+ export interface SelectAria<T> {
50
+ /** Props for the label element. */
51
+ labelProps: JSX.HTMLAttributes<HTMLElement>;
52
+ /** Props for the trigger button element. */
53
+ triggerProps: JSX.HTMLAttributes<HTMLElement>;
54
+ /** Props for the value display element. */
55
+ valueProps: JSX.HTMLAttributes<HTMLElement>;
56
+ /** Props for the listbox/menu popup. */
57
+ menuProps: JSX.HTMLAttributes<HTMLElement>;
58
+ /** Props for the description element, if any. */
59
+ descriptionProps: JSX.HTMLAttributes<HTMLElement>;
60
+ /** Props for the error message element, if any. */
61
+ errorMessageProps: JSX.HTMLAttributes<HTMLElement>;
62
+ /** Whether the select is currently focused. */
63
+ isFocused: Accessor<boolean>;
64
+ /** Whether the select has keyboard focus. */
65
+ isFocusVisible: Accessor<boolean>;
66
+ /** Whether the select is currently open. */
67
+ isOpen: Accessor<boolean>;
68
+ /** The currently selected item. */
69
+ selectedItem: Accessor<CollectionNode<T> | null>;
70
+ }
71
+
72
+ // Shared data between select and options
73
+ const selectData = new WeakMap<object, SelectData>();
74
+
75
+ interface SelectData {
76
+ id: string;
77
+ }
78
+
79
+ export function getSelectData(state: SelectState): SelectData | undefined {
80
+ return selectData.get(state);
81
+ }
82
+
83
+ /**
84
+ * Provides the behavior and accessibility implementation for a select component.
85
+ */
86
+ export function createSelect<T>(
87
+ props: MaybeAccessor<AriaSelectProps>,
88
+ state: SelectState<T>,
89
+ _ref?: () => HTMLElement | null
90
+ ): SelectAria<T> {
91
+ const getProps = () => access(props);
92
+ const id = createId(getProps().id);
93
+
94
+ // Generate IDs for associated elements
95
+ const buttonId = `${id}-button`;
96
+ const listBoxId = `${id}-listbox`;
97
+ const valueId = `${id}-value`;
98
+ const descriptionId = `${id}-description`;
99
+ const errorMessageId = `${id}-error`;
100
+
101
+ // Filter DOM props
102
+ const domProps = () =>
103
+ filterDOMProps(getProps() as unknown as Record<string, unknown>, { labelable: true });
104
+
105
+ // Share data with child options
106
+ createEffect(() => {
107
+ selectData.set(state, { id });
108
+
109
+ onCleanup(() => {
110
+ selectData.delete(state);
111
+ });
112
+ });
113
+
114
+ // Label handling
115
+ const { labelProps, fieldProps } = createLabel({
116
+ get id() {
117
+ return buttonId;
118
+ },
119
+ get label() {
120
+ return getProps().label;
121
+ },
122
+ get 'aria-label'() {
123
+ return getProps()['aria-label'];
124
+ },
125
+ get 'aria-labelledby'() {
126
+ return getProps()['aria-labelledby'];
127
+ },
128
+ labelElementType: 'span',
129
+ });
130
+
131
+ // Focus ring for keyboard focus styling
132
+ const { isFocusVisible, focusProps } = createFocusRing({
133
+ get autoFocus() {
134
+ return getProps().autoFocus;
135
+ },
136
+ });
137
+
138
+ // Track focus state
139
+ const isFocused = state.isFocused;
140
+
141
+ // Handle press on trigger
142
+ const { pressProps } = createPress({
143
+ get isDisabled() {
144
+ return getProps().isDisabled ?? state.isDisabled;
145
+ },
146
+ onPress() {
147
+ state.toggle();
148
+ },
149
+ });
150
+
151
+ // Helper to find next non-disabled key
152
+ const findNextKey = (fromKey: string | number | null, direction: 'forward' | 'backward'): string | number | null => {
153
+ const collection = state.collection();
154
+ let key = fromKey;
155
+
156
+ if (key == null) {
157
+ return direction === 'forward' ? collection.getFirstKey() : collection.getLastKey();
158
+ }
159
+
160
+ const getNext = direction === 'forward'
161
+ ? (k: string | number) => collection.getKeyAfter(k)
162
+ : (k: string | number) => collection.getKeyBefore(k);
163
+
164
+ let next = getNext(key);
165
+ while (next != null) {
166
+ // Check if item is disabled via state.isKeyDisabled or item.isDisabled
167
+ const isDisabled = state.isKeyDisabled?.(next) || collection.getItem(next)?.isDisabled;
168
+ if (!isDisabled) {
169
+ return next;
170
+ }
171
+ next = getNext(next);
172
+ }
173
+
174
+ return null;
175
+ };
176
+
177
+ // Helper to check if key is disabled
178
+ const isKeyDisabled = (key: string | number): boolean => {
179
+ const collection = state.collection();
180
+ return state.isKeyDisabled?.(key) || collection.getItem(key)?.isDisabled || false;
181
+ };
182
+
183
+ // Type-to-select - for Select, typing directly selects items when closed
184
+ const { typeSelectProps } = createTypeSelect({
185
+ collection: () => state.collection(),
186
+ focusedKey: () => state.selectedKey(), // Use selectedKey as the "focused" key for closed Select
187
+ onFocusedKeyChange: (key) => {
188
+ // When closed, type-to-select directly changes selection
189
+ if (!state.isOpen()) {
190
+ state.setSelectedKey(key);
191
+ } else {
192
+ // When open, update focused key (listbox handles selection)
193
+ state.setFocusedKey(key);
194
+ }
195
+ },
196
+ isKeyDisabled,
197
+ get isDisabled() {
198
+ return getProps().disallowTypeAhead ?? false;
199
+ },
200
+ });
201
+
202
+ // Keyboard navigation
203
+ const onKeyDown: JSX.EventHandler<HTMLElement, KeyboardEvent> = (e) => {
204
+ if (getProps().isDisabled) return;
205
+
206
+ const collection = state.collection();
207
+ const currentKey = state.selectedKey();
208
+
209
+ switch (e.key) {
210
+ case 'Enter':
211
+ case ' ':
212
+ e.preventDefault();
213
+ state.toggle();
214
+ break;
215
+
216
+ case 'ArrowDown':
217
+ e.preventDefault();
218
+ if (!state.isOpen()) {
219
+ // ArrowDown: Open the dropdown and focus first/selected item
220
+ state.open();
221
+ const focusKey = currentKey ?? collection.getFirstKey();
222
+ if (focusKey) {
223
+ state.setFocusedKey(focusKey);
224
+ }
225
+ }
226
+ // When open, navigation is handled by the listbox
227
+ break;
228
+
229
+ case 'ArrowUp':
230
+ e.preventDefault();
231
+ if (!state.isOpen()) {
232
+ // ArrowUp: Open the dropdown and focus last/selected item
233
+ state.open();
234
+ const focusKey = currentKey ?? collection.getLastKey();
235
+ if (focusKey) {
236
+ state.setFocusedKey(focusKey);
237
+ }
238
+ }
239
+ // When open, navigation is handled by the listbox
240
+ break;
241
+
242
+ case 'ArrowRight':
243
+ // ArrowRight: Select next option (for horizontal keyboard navigation pattern)
244
+ if (!state.isOpen()) {
245
+ e.preventDefault();
246
+ const nextKey = findNextKey(currentKey, 'forward');
247
+ if (nextKey != null) {
248
+ state.setSelectedKey(nextKey);
249
+ }
250
+ }
251
+ break;
252
+
253
+ case 'ArrowLeft':
254
+ // ArrowLeft: Select previous option (for horizontal keyboard navigation pattern)
255
+ if (!state.isOpen()) {
256
+ e.preventDefault();
257
+ const prevKey = findNextKey(currentKey, 'backward');
258
+ if (prevKey != null) {
259
+ state.setSelectedKey(prevKey);
260
+ }
261
+ }
262
+ break;
263
+
264
+ case 'Home':
265
+ // Home: Select first option
266
+ if (!state.isOpen()) {
267
+ e.preventDefault();
268
+ const firstKey = collection.getFirstKey();
269
+ if (firstKey != null) {
270
+ // Find first non-disabled key
271
+ const item = collection.getItem(firstKey);
272
+ if (item && !item.isDisabled) {
273
+ state.setSelectedKey(firstKey);
274
+ } else {
275
+ const nextKey = findNextKey(firstKey, 'forward');
276
+ if (nextKey != null) {
277
+ state.setSelectedKey(nextKey);
278
+ }
279
+ }
280
+ }
281
+ }
282
+ break;
283
+
284
+ case 'End':
285
+ // End: Select last option
286
+ if (!state.isOpen()) {
287
+ e.preventDefault();
288
+ const lastKey = collection.getLastKey();
289
+ if (lastKey != null) {
290
+ // Find last non-disabled key
291
+ const item = collection.getItem(lastKey);
292
+ if (item && !item.isDisabled) {
293
+ state.setSelectedKey(lastKey);
294
+ } else {
295
+ const prevKey = findNextKey(lastKey, 'backward');
296
+ if (prevKey != null) {
297
+ state.setSelectedKey(prevKey);
298
+ }
299
+ }
300
+ }
301
+ }
302
+ break;
303
+
304
+ case 'Escape':
305
+ if (state.isOpen()) {
306
+ e.preventDefault();
307
+ state.close();
308
+ }
309
+ break;
310
+ }
311
+ };
312
+
313
+ // Handle focus events
314
+ const handleFocus = (e: FocusEvent) => {
315
+ state.setFocused(true);
316
+ getProps().onFocus?.(e);
317
+ getProps().onFocusChange?.(true);
318
+ };
319
+
320
+ const handleBlur = (e: FocusEvent) => {
321
+ state.setFocused(false);
322
+ getProps().onBlur?.(e);
323
+ getProps().onFocusChange?.(false);
324
+ };
325
+
326
+ return {
327
+ get labelProps() {
328
+ return labelProps as JSX.HTMLAttributes<HTMLElement>;
329
+ },
330
+ get triggerProps() {
331
+ const p = getProps();
332
+ const isOpen = state.isOpen();
333
+ const isDisabled = p.isDisabled ?? state.isDisabled;
334
+
335
+ const baseProps = mergeProps(
336
+ domProps(),
337
+ pressProps as Record<string, unknown>,
338
+ focusProps as Record<string, unknown>,
339
+ fieldProps as Record<string, unknown>,
340
+ {
341
+ id: buttonId,
342
+ role: 'combobox',
343
+ type: 'button',
344
+ tabIndex: isDisabled ? undefined : 0,
345
+ 'aria-haspopup': 'listbox',
346
+ 'aria-expanded': isOpen,
347
+ 'aria-controls': isOpen ? listBoxId : undefined,
348
+ 'aria-disabled': isDisabled || undefined,
349
+ 'aria-required': p.isRequired || undefined,
350
+ 'aria-describedby': p['aria-describedby'] || undefined,
351
+ onKeyDown,
352
+ onFocus: handleFocus,
353
+ onBlur: handleBlur,
354
+ 'data-open': isOpen || undefined,
355
+ 'data-disabled': isDisabled || undefined,
356
+ 'data-focus-visible': isFocusVisible() || undefined,
357
+ } as Record<string, unknown>
358
+ );
359
+
360
+ // Add type-select props if enabled
361
+ if (!p.disallowTypeAhead) {
362
+ return mergeProps(baseProps, typeSelectProps as Record<string, unknown>) as JSX.HTMLAttributes<HTMLElement>;
363
+ }
364
+
365
+ return baseProps as JSX.HTMLAttributes<HTMLElement>;
366
+ },
367
+ get valueProps() {
368
+ return {
369
+ id: valueId,
370
+ } as JSX.HTMLAttributes<HTMLElement>;
371
+ },
372
+ get menuProps() {
373
+ return {
374
+ id: listBoxId,
375
+ role: 'listbox',
376
+ 'aria-labelledby': buttonId,
377
+ tabIndex: -1,
378
+ } as JSX.HTMLAttributes<HTMLElement>;
379
+ },
380
+ get descriptionProps() {
381
+ return {
382
+ id: descriptionId,
383
+ } as JSX.HTMLAttributes<HTMLElement>;
384
+ },
385
+ get errorMessageProps() {
386
+ return {
387
+ id: errorMessageId,
388
+ } as JSX.HTMLAttributes<HTMLElement>;
389
+ },
390
+ isFocused,
391
+ isFocusVisible: () => isFocused() && isFocusVisible(),
392
+ isOpen: state.isOpen,
393
+ selectedItem: state.selectedItem,
394
+ };
395
+ }
@@ -0,0 +1,14 @@
1
+ export {
2
+ createSelect,
3
+ getSelectData,
4
+ type AriaSelectProps,
5
+ type SelectAria,
6
+ } from './createSelect';
7
+
8
+ export {
9
+ createHiddenSelect,
10
+ HiddenSelect,
11
+ type AriaHiddenSelectProps,
12
+ type HiddenSelectAria,
13
+ type HiddenSelectProps,
14
+ } from './createHiddenSelect.jsx';
@@ -0,0 +1,201 @@
1
+ /**
2
+ * createTypeSelect - Handles typeahead interactions with collections.
3
+ * Based on @react-aria/selection useTypeSelect.
4
+ *
5
+ * Allows users to navigate to items by typing characters that match
6
+ * item text values. Supports multi-character search with debouncing.
7
+ */
8
+
9
+ import type { JSX, Accessor } from 'solid-js';
10
+ import type { Key, Collection, CollectionNode } from '@proyecto-viviana/solid-stately';
11
+
12
+ /**
13
+ * Controls how long to wait before clearing the typeahead buffer.
14
+ */
15
+ const TYPEAHEAD_DEBOUNCE_WAIT_MS = 1000; // 1 second
16
+
17
+ export interface TypeSelectOptions<T> {
18
+ /** The collection to search through. */
19
+ collection: Accessor<Collection<T>>;
20
+ /** The currently focused key. */
21
+ focusedKey: Accessor<Key | null>;
22
+ /** Callback to set the focused key when a match is found. */
23
+ onFocusedKeyChange: (key: Key) => void;
24
+ /** Callback when an item is focused by typing. */
25
+ onTypeSelect?: (key: Key) => void;
26
+ /** Function to check if a key is disabled. */
27
+ isKeyDisabled?: (key: Key) => boolean;
28
+ /** Whether type-to-select is disabled. */
29
+ isDisabled?: boolean;
30
+ }
31
+
32
+ export interface TypeSelectAria {
33
+ /** Props to spread on the collection element. */
34
+ typeSelectProps: JSX.HTMLAttributes<HTMLElement>;
35
+ }
36
+
37
+ // Internal state for tracking the search buffer
38
+ interface TypeSelectState {
39
+ search: string;
40
+ timeout: ReturnType<typeof setTimeout> | undefined;
41
+ }
42
+
43
+ /**
44
+ * Get a printable character from a key event.
45
+ * Returns the character if it's a single printable character,
46
+ * or empty string for non-printable keys.
47
+ */
48
+ function getStringForKey(key: string): string {
49
+ // If the key is of length 1, it is an ASCII value.
50
+ // Otherwise, if there are no ASCII characters in the key name,
51
+ // it is a Unicode character.
52
+ // See https://www.w3.org/TR/uievents-key/
53
+ if (key.length === 1 || !/^[A-Z]/i.test(key)) {
54
+ return key;
55
+ }
56
+ return '';
57
+ }
58
+
59
+ /**
60
+ * Search for a key in the collection that matches the search string.
61
+ * Starts searching from the key after `fromKey`, wrapping around if needed.
62
+ */
63
+ function getKeyForSearch<T>(
64
+ collection: Collection<T>,
65
+ search: string,
66
+ fromKey: Key | null,
67
+ isKeyDisabled?: (key: Key) => boolean
68
+ ): Key | null {
69
+ const searchLower = search.toLowerCase();
70
+
71
+ // Collect all items in order
72
+ const items: CollectionNode<T>[] = [];
73
+ for (const item of collection) {
74
+ if (item.type === 'item') {
75
+ items.push(item);
76
+ }
77
+ }
78
+
79
+ if (items.length === 0) return null;
80
+
81
+ // Find the starting index
82
+ let startIndex = 0;
83
+ if (fromKey != null) {
84
+ const fromIndex = items.findIndex(item => item.key === fromKey);
85
+ if (fromIndex !== -1) {
86
+ // Start searching from the item AFTER the current one
87
+ startIndex = (fromIndex + 1) % items.length;
88
+ }
89
+ }
90
+
91
+ // Search from startIndex, wrapping around
92
+ for (let i = 0; i < items.length; i++) {
93
+ const index = (startIndex + i) % items.length;
94
+ const item = items[index];
95
+
96
+ // Skip disabled items
97
+ if (item.isDisabled || (isKeyDisabled && isKeyDisabled(item.key))) {
98
+ continue;
99
+ }
100
+
101
+ // Check if the text value starts with the search string
102
+ const textValue = item.textValue || '';
103
+ if (textValue.toLowerCase().startsWith(searchLower)) {
104
+ return item.key;
105
+ }
106
+ }
107
+
108
+ return null;
109
+ }
110
+
111
+ /**
112
+ * Creates typeahead/type-to-select functionality for a collection.
113
+ *
114
+ * @example
115
+ * ```tsx
116
+ * const { typeSelectProps } = createTypeSelect({
117
+ * collection: () => state.collection(),
118
+ * focusedKey: () => state.focusedKey(),
119
+ * onFocusedKeyChange: (key) => state.setFocusedKey(key),
120
+ * });
121
+ *
122
+ * return <ul {...mergeProps(listBoxProps, typeSelectProps)}>...</ul>;
123
+ * ```
124
+ */
125
+ export function createTypeSelect<T>(options: TypeSelectOptions<T>): TypeSelectAria {
126
+ // Create mutable state object to persist across keystrokes
127
+ const state: TypeSelectState = {
128
+ search: '',
129
+ timeout: undefined,
130
+ };
131
+
132
+ const onKeyDownCapture: JSX.EventHandler<HTMLElement, KeyboardEvent> = (e) => {
133
+ if (options.isDisabled) return;
134
+
135
+ const character = getStringForKey(e.key);
136
+
137
+ // Ignore non-printable characters, modifier key combos,
138
+ // and events that didn't originate from within the element
139
+ if (
140
+ !character ||
141
+ e.ctrlKey ||
142
+ e.metaKey ||
143
+ e.altKey ||
144
+ !e.currentTarget.contains(e.target as HTMLElement)
145
+ ) {
146
+ return;
147
+ }
148
+
149
+ // Don't start search with space (common action key)
150
+ if (state.search.length === 0 && character === ' ') {
151
+ return;
152
+ }
153
+
154
+ // If there's already search text and the user types a space,
155
+ // prevent it from triggering selection and include it in the search
156
+ if (character === ' ' && state.search.trim().length > 0) {
157
+ e.preventDefault();
158
+ e.stopPropagation();
159
+ }
160
+
161
+ // Append to the search buffer
162
+ state.search += character;
163
+
164
+ // Find a matching key
165
+ const collection = options.collection();
166
+ const currentKey = options.focusedKey();
167
+
168
+ // First, try to find a match starting after the current key
169
+ let key = getKeyForSearch(collection, state.search, currentKey, options.isKeyDisabled);
170
+
171
+ // If no match found, try from the beginning
172
+ if (key == null && currentKey != null) {
173
+ key = getKeyForSearch(collection, state.search, null, options.isKeyDisabled);
174
+ }
175
+
176
+ if (key != null) {
177
+ options.onFocusedKeyChange(key);
178
+ options.onTypeSelect?.(key);
179
+ }
180
+
181
+ // Reset the debounce timer
182
+ if (state.timeout !== undefined) {
183
+ clearTimeout(state.timeout);
184
+ }
185
+ state.timeout = setTimeout(() => {
186
+ state.search = '';
187
+ }, TYPEAHEAD_DEBOUNCE_WAIT_MS);
188
+ };
189
+
190
+ // Handler for bubble phase (used in test environments and as fallback)
191
+ const onKeyDown: JSX.EventHandler<HTMLElement, KeyboardEvent> = onKeyDownCapture;
192
+
193
+ return {
194
+ typeSelectProps: {
195
+ // Use capture phase to handle spacebar before other handlers in production
196
+ onKeyDownCapture,
197
+ // Also attach to bubble phase for test environments
198
+ onKeyDown,
199
+ } as JSX.HTMLAttributes<HTMLElement>,
200
+ };
201
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Selection utilities for managing typeahead and keyboard navigation
3
+ * in collection components.
4
+ */
5
+
6
+ export { createTypeSelect, type TypeSelectOptions, type TypeSelectAria } from './createTypeSelect';
@@ -0,0 +1,82 @@
1
+ /**
2
+ * createSeparator - SolidJS implementation of React Aria's useSeparator
3
+ *
4
+ * A separator is a visual divider between two groups of content,
5
+ * e.g. groups of menu items or sections of a page.
6
+ */
7
+
8
+ import type { JSX } from 'solid-js';
9
+ import { access, type MaybeAccessor } from '../utils';
10
+ import { filterDOMProps } from '../utils';
11
+
12
+ // ============================================
13
+ // TYPES
14
+ // ============================================
15
+
16
+ export type Orientation = 'horizontal' | 'vertical';
17
+
18
+ export interface AriaSeparatorProps {
19
+ /**
20
+ * The orientation of the separator.
21
+ * @default 'horizontal'
22
+ */
23
+ orientation?: Orientation;
24
+ /**
25
+ * The HTML element type that will be used to render the separator.
26
+ * @default 'hr'
27
+ */
28
+ elementType?: string;
29
+ /** An accessibility label for the separator. */
30
+ 'aria-label'?: string;
31
+ /** Identifies the element(s) that labels the separator. */
32
+ 'aria-labelledby'?: string;
33
+ /** The element's unique identifier. */
34
+ id?: string;
35
+ }
36
+
37
+ export interface SeparatorAria {
38
+ /** Props for the separator element. */
39
+ separatorProps: JSX.HTMLAttributes<HTMLElement>;
40
+ }
41
+
42
+ // ============================================
43
+ // CREATE SEPARATOR
44
+ // ============================================
45
+
46
+ /**
47
+ * Provides the accessibility implementation for a separator.
48
+ * A separator is a visual divider between two groups of content,
49
+ * e.g. groups of menu items or sections of a page.
50
+ */
51
+ export function createSeparator(
52
+ props: MaybeAccessor<AriaSeparatorProps> = {}
53
+ ): SeparatorAria {
54
+ const getSeparatorProps = (): JSX.HTMLAttributes<HTMLElement> => {
55
+ const p = access(props);
56
+ const domProps = filterDOMProps(p as Record<string, unknown>, { labelable: true });
57
+
58
+ // if orientation is horizontal, aria-orientation default is horizontal, so we leave it undefined
59
+ // if it's vertical, we need to specify it
60
+ let ariaOrientation: 'vertical' | undefined;
61
+ if (p.orientation === 'vertical') {
62
+ ariaOrientation = 'vertical';
63
+ }
64
+
65
+ // hr elements implicitly have role = separator and a horizontal orientation
66
+ if (p.elementType !== 'hr') {
67
+ return {
68
+ ...domProps,
69
+ role: 'separator',
70
+ 'aria-orientation': ariaOrientation,
71
+ };
72
+ }
73
+
74
+ return domProps;
75
+ };
76
+
77
+ return {
78
+ get separatorProps() {
79
+ return getSeparatorProps();
80
+ },
81
+ };
82
+ }
@@ -0,0 +1,6 @@
1
+ export {
2
+ createSeparator,
3
+ type AriaSeparatorProps,
4
+ type SeparatorAria,
5
+ type Orientation,
6
+ } from './createSeparator';