@gridui/select 0.0.0-stage → 0.0.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.
package/dist/index.js ADDED
@@ -0,0 +1,1575 @@
1
+ // src/shared/style.ts
2
+ import { dropdownContentStyles, dropdownItemStyles } from "@gridui/dropdown-menu";
3
+ import { cn } from "@gridui/style-utils";
4
+ import { cva } from "class-variance-authority";
5
+ var selectItemStyles = cva(cn(dropdownItemStyles(), "min-w-0"));
6
+ var selectIconStyles = cva("inline-flex shrink-0 items-center [&_svg]:size-gridui-16");
7
+ var selectOptionContentStyles = cva("min-w-0 flex-1 whitespace-normal wrap-anywhere");
8
+ var selectOptionDescriptionStyles = cva("block text-muted type-caption mt-gridui-4");
9
+ var selectListStyles = cva("min-h-0 overflow-y-auto");
10
+ var selectEmptyStyles = cva("p-gridui-8 text-muted type-caption");
11
+ var selectActionsStyles = cva("shrink-0 border-t border-border pt-gridui-4");
12
+ var selectActionStyles = cva(cn(
13
+ selectItemStyles(),
14
+ "w-full text-start whitespace-normal wrap-anywhere hover:bg-surface focus-visible:bg-surface"
15
+ ));
16
+ var comboboxContentStyles = cva(cn(
17
+ dropdownContentStyles(),
18
+ "gridui-combobox-content box-border flex flex-col overflow-hidden min-w-0 w-(--anchor-width) max-h-(--available-height) max-w-(--available-width)"
19
+ ));
20
+
21
+ // src/shared/combobox-options.tsx
22
+ import { dropdownIndicatorStyles, dropdownLabelStyles } from "@gridui/dropdown-menu";
23
+ import { Check } from "lucide-react";
24
+ import { jsx, jsxs } from "react/jsx-runtime";
25
+ var ComboboxOptions = (props) => {
26
+ const { id, label, options, selected, multiple, active, optionId, onSelect, onHighlight } = props;
27
+ const renderOption = (option) => {
28
+ const itemId = optionId(option.value);
29
+ const checked = typeof selected === "string" ? selected === option.value : selected.includes(option.value);
30
+ return /* @__PURE__ */ jsxs(
31
+ "div",
32
+ {
33
+ id: itemId,
34
+ role: "option",
35
+ "aria-selected": checked,
36
+ "aria-disabled": option.disabled,
37
+ "aria-labelledby": `${itemId}-label`,
38
+ "aria-describedby": option.description ? `${itemId}-description` : void 0,
39
+ "data-disabled": option.disabled ? "" : void 0,
40
+ "data-highlighted": active === option.value ? "" : void 0,
41
+ className: selectItemStyles(),
42
+ onPointerMove: () => {
43
+ onHighlight(option.value);
44
+ },
45
+ onPointerDown: (event) => {
46
+ event.preventDefault();
47
+ },
48
+ onClick: () => {
49
+ if (!option.disabled) {
50
+ onSelect(option);
51
+ }
52
+ },
53
+ children: [
54
+ /* @__PURE__ */ jsx(
55
+ "span",
56
+ {
57
+ className: dropdownIndicatorStyles(),
58
+ "aria-hidden": "true",
59
+ children: checked && /* @__PURE__ */ jsx(
60
+ Check,
61
+ {
62
+ size: 16
63
+ }
64
+ )
65
+ }
66
+ ),
67
+ option.icon && /* @__PURE__ */ jsx(
68
+ "span",
69
+ {
70
+ className: selectIconStyles(),
71
+ "aria-hidden": "true",
72
+ children: option.icon
73
+ }
74
+ ),
75
+ /* @__PURE__ */ jsxs(
76
+ "span",
77
+ {
78
+ className: selectOptionContentStyles(),
79
+ children: [
80
+ /* @__PURE__ */ jsx(
81
+ "span",
82
+ {
83
+ id: `${itemId}-label`,
84
+ children: option.label
85
+ }
86
+ ),
87
+ option.description && /* @__PURE__ */ jsx(
88
+ "span",
89
+ {
90
+ id: `${itemId}-description`,
91
+ className: selectOptionDescriptionStyles(),
92
+ children: option.description
93
+ }
94
+ )
95
+ ]
96
+ }
97
+ )
98
+ ]
99
+ },
100
+ option.value
101
+ );
102
+ };
103
+ return /* @__PURE__ */ jsx(
104
+ "div",
105
+ {
106
+ id,
107
+ role: "listbox",
108
+ "aria-multiselectable": multiple || void 0,
109
+ "aria-label": label,
110
+ className: selectListStyles(),
111
+ children: options.map((entry, index) => {
112
+ return "options" in entry ? /* @__PURE__ */ jsxs(
113
+ "div",
114
+ {
115
+ role: "group",
116
+ "aria-labelledby": `${id}-group-${index}`,
117
+ children: [
118
+ /* @__PURE__ */ jsx(
119
+ "div",
120
+ {
121
+ id: `${id}-group-${index}`,
122
+ className: dropdownLabelStyles(),
123
+ children: entry.label
124
+ }
125
+ ),
126
+ entry.options.map(renderOption)
127
+ ]
128
+ },
129
+ entry.label
130
+ ) : renderOption(entry);
131
+ })
132
+ }
133
+ );
134
+ };
135
+
136
+ // src/shared/selection-actions.tsx
137
+ import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
138
+ var SelectionActions = (props) => {
139
+ const { actions, onAction } = props;
140
+ return /* @__PURE__ */ jsx2(Fragment, { children: actions.length > 0 && /* @__PURE__ */ jsx2(
141
+ "div",
142
+ {
143
+ className: selectActionsStyles(),
144
+ children: actions.map((action) => {
145
+ const content = /* @__PURE__ */ jsxs2(Fragment, { children: [
146
+ action.icon && /* @__PURE__ */ jsx2(
147
+ "span",
148
+ {
149
+ className: selectIconStyles(),
150
+ "aria-hidden": "true",
151
+ children: action.icon
152
+ }
153
+ ),
154
+ action.label
155
+ ] });
156
+ const actionClass = selectActionStyles();
157
+ if (action.href !== void 0) {
158
+ return /* @__PURE__ */ jsx2(
159
+ "a",
160
+ {
161
+ href: action.disabled ? void 0 : action.href,
162
+ target: action.target,
163
+ rel: action.rel,
164
+ "aria-disabled": action.disabled || void 0,
165
+ "data-disabled": action.disabled ? "" : void 0,
166
+ tabIndex: action.disabled ? -1 : void 0,
167
+ className: actionClass,
168
+ onClick: (event) => {
169
+ if (action.disabled) {
170
+ event.preventDefault();
171
+ return;
172
+ }
173
+ if (!onAction(action)) {
174
+ event.preventDefault();
175
+ }
176
+ },
177
+ children: content
178
+ },
179
+ action.id
180
+ );
181
+ }
182
+ return /* @__PURE__ */ jsx2(
183
+ "button",
184
+ {
185
+ type: "button",
186
+ disabled: action.disabled,
187
+ "data-disabled": action.disabled ? "" : void 0,
188
+ className: actionClass,
189
+ onClick: () => {
190
+ onAction(action);
191
+ },
192
+ children: content
193
+ },
194
+ action.id
195
+ );
196
+ })
197
+ }
198
+ ) });
199
+ };
200
+
201
+ // src/shared/selection-form.tsx
202
+ import { useEffect, useLayoutEffect, useRef } from "react";
203
+ import { flushSync } from "react-dom";
204
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
205
+ var SelectionForm = (props) => {
206
+ const {
207
+ name,
208
+ form,
209
+ required,
210
+ disabled,
211
+ selectedValue,
212
+ allOptions,
213
+ onValueChange,
214
+ onReset,
215
+ onInvalid
216
+ } = props;
217
+ const nativeRef = useRef(null);
218
+ const resetSelection = useRef(onReset);
219
+ const currentValue = useRef(selectedValue);
220
+ useLayoutEffect(() => {
221
+ resetSelection.current = onReset;
222
+ currentValue.current = selectedValue;
223
+ }, [
224
+ onReset,
225
+ selectedValue
226
+ ]);
227
+ useEffect(() => {
228
+ const owner = nativeRef.current?.form;
229
+ let mounted = true;
230
+ const reset = (event) => {
231
+ setTimeout(() => {
232
+ if (mounted && !event.defaultPrevented) {
233
+ flushSync(() => {
234
+ resetSelection.current();
235
+ });
236
+ if (nativeRef.current) {
237
+ nativeRef.current.value = currentValue.current;
238
+ }
239
+ }
240
+ }, 0);
241
+ };
242
+ owner?.addEventListener("reset", reset);
243
+ return () => {
244
+ mounted = false;
245
+ owner?.removeEventListener("reset", reset);
246
+ };
247
+ }, [form]);
248
+ return /* @__PURE__ */ jsxs3(
249
+ "select",
250
+ {
251
+ ref: nativeRef,
252
+ "aria-hidden": "true",
253
+ tabIndex: -1,
254
+ className: "sr-only",
255
+ name,
256
+ form,
257
+ required,
258
+ disabled,
259
+ value: selectedValue,
260
+ onChange: (event) => {
261
+ onValueChange(event.currentTarget.value);
262
+ },
263
+ onInvalid: (event) => {
264
+ event.preventDefault();
265
+ onInvalid();
266
+ },
267
+ children: [
268
+ !allOptions.some((option) => {
269
+ return option.value === "";
270
+ }) && /* @__PURE__ */ jsx3(
271
+ "option",
272
+ {
273
+ value: ""
274
+ }
275
+ ),
276
+ selectedValue !== "" && !allOptions.some((option) => {
277
+ return option.value === selectedValue;
278
+ }) && /* @__PURE__ */ jsx3(
279
+ "option",
280
+ {
281
+ value: selectedValue,
282
+ children: selectedValue
283
+ }
284
+ ),
285
+ allOptions.map((option) => {
286
+ return /* @__PURE__ */ jsx3(
287
+ "option",
288
+ {
289
+ value: option.value,
290
+ disabled: option.disabled,
291
+ children: option.label
292
+ },
293
+ option.value
294
+ );
295
+ })
296
+ ]
297
+ }
298
+ );
299
+ };
300
+
301
+ // src/shared/options.ts
302
+ var flattenOptions = (options) => {
303
+ return options.flatMap((entry) => {
304
+ return "options" in entry ? entry.options : [entry];
305
+ });
306
+ };
307
+ var filterOptions = (options, query) => {
308
+ const term = query.trim().normalize("NFKC").toLowerCase();
309
+ if (!term) {
310
+ return options;
311
+ }
312
+ const matches = (option) => {
313
+ return `${option.label} ${option.description ?? ""}`.normalize("NFKC").toLowerCase().includes(term);
314
+ };
315
+ return options.flatMap((entry) => {
316
+ if ("options" in entry) {
317
+ const items = entry.options.filter(matches);
318
+ return items.length ? [
319
+ {
320
+ ...entry,
321
+ options: items
322
+ }
323
+ ] : [];
324
+ }
325
+ return matches(entry) ? [entry] : [];
326
+ });
327
+ };
328
+
329
+ // src/shared/scroll-option.ts
330
+ var scrollOption = (id) => {
331
+ const option = document.getElementById(id);
332
+ const list = option?.closest('[role="listbox"]');
333
+ if (!option || !list) {
334
+ return;
335
+ }
336
+ const itemBounds = option.getBoundingClientRect();
337
+ const listBounds = list.getBoundingClientRect();
338
+ if (itemBounds.top < listBounds.top) {
339
+ list.scrollTop += itemBounds.top - listBounds.top;
340
+ } else if (itemBounds.bottom > listBounds.bottom) {
341
+ list.scrollTop += itemBounds.bottom - listBounds.bottom;
342
+ }
343
+ };
344
+
345
+ // src/shared/use-search-options.ts
346
+ import { useEffect as useEffect2, useState } from "react";
347
+ var INITIAL_SEARCH = {
348
+ query: null,
349
+ highlighted: null
350
+ };
351
+ var useSearchOptions = (options, selected, listId, open) => {
352
+ const [
353
+ search,
354
+ setSearch
355
+ ] = useState(INITIAL_SEARCH);
356
+ const query = open ? search.query : null;
357
+ const all = flattenOptions(options);
358
+ const filtered = filterOptions(options, query ?? "");
359
+ const visible = flattenOptions(filtered);
360
+ const highlighted = visible.find((option) => {
361
+ return option.value === search.highlighted;
362
+ });
363
+ const selectedOption = query === null ? visible.find((option) => {
364
+ return selected.includes(option.value);
365
+ }) : void 0;
366
+ const active = highlighted ?? selectedOption ?? visible[0];
367
+ const activeValue = active?.value ?? null;
368
+ const optionId = (value) => {
369
+ return `${listId}-${all.findIndex((option) => {
370
+ return option.value === value;
371
+ })}`;
372
+ };
373
+ const activeOptionId = active ? optionId(active.value) : void 0;
374
+ useEffect2(() => {
375
+ if (!open) {
376
+ setSearch(INITIAL_SEARCH);
377
+ }
378
+ }, [open]);
379
+ useEffect2(() => {
380
+ if (open && activeOptionId !== void 0) {
381
+ scrollOption(activeOptionId);
382
+ }
383
+ }, [
384
+ open,
385
+ activeOptionId
386
+ ]);
387
+ const highlight = (value) => {
388
+ setSearch((current) => {
389
+ return {
390
+ ...current,
391
+ highlighted: value
392
+ };
393
+ });
394
+ };
395
+ return {
396
+ all,
397
+ filtered,
398
+ visible,
399
+ query,
400
+ active: activeValue,
401
+ activeOption: active,
402
+ activeOptionId,
403
+ optionId,
404
+ highlight,
405
+ changeQuery: (text) => {
406
+ setSearch({
407
+ query: text,
408
+ highlighted: null
409
+ });
410
+ },
411
+ moveActive: (direction) => {
412
+ const index = visible.findIndex((option) => {
413
+ return option.value === activeValue;
414
+ });
415
+ const next = visible[Math.max(0, Math.min(visible.length - 1, index + direction))];
416
+ if (next) {
417
+ highlight(next.value);
418
+ }
419
+ }
420
+ };
421
+ };
422
+
423
+ // src/shared/use-selection-popup.ts
424
+ import { useEffect as useEffect3, useRef as useRef2, useState as useState2 } from "react";
425
+ import { flushSync as flushSync2 } from "react-dom";
426
+ var useSelectionPopup = ({ disabled, readOnly, controlRef }) => {
427
+ const [
428
+ localOpen,
429
+ setLocalOpen
430
+ ] = useState2(false);
431
+ const popupRef = useRef2(null);
432
+ const restoreFocus = useRef2(true);
433
+ const unavailable = Boolean(disabled || readOnly);
434
+ useEffect3(() => {
435
+ if (unavailable) {
436
+ setLocalOpen(false);
437
+ }
438
+ }, [unavailable]);
439
+ const available = () => {
440
+ return !unavailable && !controlRef.current?.matches(":disabled");
441
+ };
442
+ const changeOpen = (next) => {
443
+ if (next && !available()) {
444
+ return;
445
+ }
446
+ if (next) {
447
+ restoreFocus.current = true;
448
+ }
449
+ setLocalOpen(next);
450
+ };
451
+ const close = () => {
452
+ restoreFocus.current = false;
453
+ setLocalOpen(false);
454
+ };
455
+ const focus = () => {
456
+ controlRef.current?.focus();
457
+ };
458
+ const finalFocus = () => {
459
+ const control = controlRef.current;
460
+ if (!restoreFocus.current || !control) {
461
+ return false;
462
+ }
463
+ const active = control.ownerDocument.activeElement;
464
+ if (active && active !== control.ownerDocument.body && active !== control && !popupRef.current?.contains(active)) {
465
+ return false;
466
+ }
467
+ return control;
468
+ };
469
+ const runAction = (action) => {
470
+ if (action.disabled || !available()) {
471
+ return false;
472
+ }
473
+ if (action.closeOnAction !== false) {
474
+ flushSync2(close);
475
+ focus();
476
+ }
477
+ action.onAction?.();
478
+ return true;
479
+ };
480
+ return {
481
+ open: localOpen && !unavailable,
482
+ popupRef,
483
+ available,
484
+ changeOpen,
485
+ close,
486
+ focus,
487
+ finalFocus,
488
+ runAction
489
+ };
490
+ };
491
+
492
+ // src/shared/use-selection-value.ts
493
+ import { useRef as useRef3, useState as useState3 } from "react";
494
+ var useSelectionValue = (props, available) => {
495
+ const { value, defaultValue = "", onValueChange } = props;
496
+ const [
497
+ localValue,
498
+ setLocalValue
499
+ ] = useState3(defaultValue);
500
+ const selectedValue = value ?? localValue;
501
+ const initialValue = useRef3(selectedValue);
502
+ const update = (next) => {
503
+ if (next === selectedValue) {
504
+ return;
505
+ }
506
+ if (value === void 0) {
507
+ setLocalValue(next);
508
+ }
509
+ onValueChange?.(next);
510
+ };
511
+ return {
512
+ selectedValue,
513
+ change: (next) => {
514
+ if (next !== null && available()) {
515
+ update(next);
516
+ }
517
+ },
518
+ reset: () => {
519
+ update(initialValue.current);
520
+ }
521
+ };
522
+ };
523
+
524
+ // src/combobox/style.ts
525
+ import { cva as cva2 } from "class-variance-authority";
526
+ var comboboxInputStyles = cva2("pr-11 text-ellipsis");
527
+ var comboboxTriggerStyles = cva2("absolute inset-y-0 right-0 flex w-9 items-center justify-center rounded-control text-foreground cursor-pointer disabled:cursor-not-allowed disabled:opacity-50");
528
+
529
+ // src/combobox/combobox.tsx
530
+ import { controlVariants } from "@gridui/input";
531
+ import { cn as cn2 } from "@gridui/style-utils";
532
+ import * as Primitive from "@radix-ui/react-popover";
533
+ import { ChevronDown, X } from "lucide-react";
534
+ import { useId, useRef as useRef4 } from "react";
535
+ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
536
+ var Combobox = (props) => {
537
+ const {
538
+ options,
539
+ actions = [],
540
+ value,
541
+ defaultValue = "",
542
+ onValueChange,
543
+ controlSize = "standard",
544
+ clearLabel,
545
+ required,
546
+ disabled,
547
+ readOnly,
548
+ name,
549
+ form,
550
+ dir,
551
+ portalContainer,
552
+ className,
553
+ ref,
554
+ searchLabel,
555
+ emptyLabel,
556
+ placeholder,
557
+ onKeyDown,
558
+ onClick,
559
+ ...restProps
560
+ } = props;
561
+ const controlRef = useRef4(null);
562
+ const { open, popupRef, available, changeOpen, close, focus, runAction, finalFocus } = useSelectionPopup({
563
+ disabled,
564
+ readOnly,
565
+ controlRef
566
+ });
567
+ const { selectedValue, change, reset } = useSelectionValue({
568
+ value,
569
+ defaultValue,
570
+ onValueChange
571
+ }, available);
572
+ const inputId = useId();
573
+ const listId = `${inputId}-list`;
574
+ const search = useSearchOptions(options, [selectedValue], listId, open);
575
+ const { all: allOptions, filtered, visible, query, active, optionId, activeOptionId } = search;
576
+ const selected = allOptions.find((option) => {
577
+ return option.value === selectedValue;
578
+ });
579
+ const text = query ?? selected?.label ?? selectedValue;
580
+ const show = () => {
581
+ changeOpen(true);
582
+ };
583
+ const choose = (option) => {
584
+ if (option.disabled || !available()) {
585
+ return;
586
+ }
587
+ change(option.value);
588
+ close();
589
+ focus();
590
+ };
591
+ return /* @__PURE__ */ jsxs4(
592
+ Primitive.Root,
593
+ {
594
+ open,
595
+ onOpenChange: changeOpen,
596
+ children: [
597
+ /* @__PURE__ */ jsxs4(
598
+ "div",
599
+ {
600
+ className: "relative flex min-w-0 w-full items-stretch gap-gridui-4",
601
+ dir,
602
+ children: [
603
+ /* @__PURE__ */ jsx4(
604
+ Primitive.Anchor,
605
+ {
606
+ asChild: true,
607
+ children: /* @__PURE__ */ jsxs4(
608
+ "div",
609
+ {
610
+ className: "relative flex min-w-0 flex-1 items-stretch",
611
+ children: [
612
+ /* @__PURE__ */ jsx4(
613
+ "input",
614
+ {
615
+ ...restProps,
616
+ id: restProps.id ?? inputId,
617
+ type: "text",
618
+ role: "combobox",
619
+ ref: (element) => {
620
+ controlRef.current = element;
621
+ if (typeof ref === "function") {
622
+ return ref(element);
623
+ }
624
+ if (ref) {
625
+ ref.current = element;
626
+ }
627
+ },
628
+ "aria-label": restProps["aria-label"] ?? (restProps.id ? void 0 : searchLabel),
629
+ "aria-required": required,
630
+ "aria-autocomplete": "list",
631
+ "aria-expanded": open,
632
+ "aria-controls": open ? listId : void 0,
633
+ "aria-activedescendant": open ? activeOptionId : void 0,
634
+ placeholder: placeholder ?? searchLabel,
635
+ autoComplete: "off",
636
+ form,
637
+ disabled,
638
+ readOnly,
639
+ className: cn2(controlVariants({ size: controlSize }), comboboxInputStyles(), className),
640
+ value: text,
641
+ onClick: (event) => {
642
+ onClick?.(event);
643
+ if (!event.defaultPrevented && !open) {
644
+ show();
645
+ }
646
+ },
647
+ onChange: (event) => {
648
+ if (readOnly) {
649
+ return;
650
+ }
651
+ search.changeQuery(event.target.value);
652
+ changeOpen(true);
653
+ },
654
+ onKeyDown: (event) => {
655
+ onKeyDown?.(event);
656
+ if (event.defaultPrevented || readOnly) {
657
+ return;
658
+ }
659
+ if (event.nativeEvent.isComposing) {
660
+ if (event.key === "Enter" || event.key === "Escape") {
661
+ event.stopPropagation();
662
+ }
663
+ return;
664
+ }
665
+ if (event.key === "Escape" && open) {
666
+ event.preventDefault();
667
+ event.stopPropagation();
668
+ close();
669
+ }
670
+ if (event.key === "ArrowDown" || event.key === "ArrowUp") {
671
+ event.preventDefault();
672
+ if (!open) {
673
+ show();
674
+ return;
675
+ }
676
+ search.moveActive(event.key === "ArrowDown" ? 1 : -1);
677
+ }
678
+ if (event.key === "Enter" && open) {
679
+ event.preventDefault();
680
+ const option = search.activeOption;
681
+ if (option) {
682
+ choose(option);
683
+ }
684
+ }
685
+ if (event.key === "Tab" && open) {
686
+ const action = !event.shiftKey && popupRef.current?.querySelector("button:not(:disabled), a[href]");
687
+ if (action) {
688
+ event.preventDefault();
689
+ action.focus();
690
+ } else {
691
+ close();
692
+ }
693
+ }
694
+ }
695
+ }
696
+ ),
697
+ /* @__PURE__ */ jsx4(
698
+ "button",
699
+ {
700
+ type: "button",
701
+ "aria-label": searchLabel,
702
+ disabled: disabled || readOnly,
703
+ className: comboboxTriggerStyles(),
704
+ onClick: () => {
705
+ if (open) {
706
+ close();
707
+ } else {
708
+ show();
709
+ }
710
+ focus();
711
+ },
712
+ children: /* @__PURE__ */ jsx4(
713
+ ChevronDown,
714
+ {
715
+ size: 16,
716
+ "aria-hidden": "true"
717
+ }
718
+ )
719
+ }
720
+ )
721
+ ]
722
+ }
723
+ )
724
+ }
725
+ ),
726
+ clearLabel && /* @__PURE__ */ jsx4(
727
+ "button",
728
+ {
729
+ type: "button",
730
+ disabled: disabled || readOnly || required || selectedValue === "",
731
+ "aria-label": clearLabel,
732
+ onClick: () => {
733
+ change("");
734
+ close();
735
+ focus();
736
+ },
737
+ className: cn2(controlVariants({ size: controlSize }), "flex w-auto shrink-0 items-center justify-center min-w-11 cursor-pointer hover:enabled:bg-surface"),
738
+ children: /* @__PURE__ */ jsx4(
739
+ X,
740
+ {
741
+ size: 16,
742
+ "aria-hidden": "true"
743
+ }
744
+ )
745
+ }
746
+ ),
747
+ /* @__PURE__ */ jsx4(
748
+ SelectionForm,
749
+ {
750
+ name,
751
+ form,
752
+ required,
753
+ disabled,
754
+ selectedValue,
755
+ allOptions,
756
+ onValueChange: change,
757
+ onReset: () => {
758
+ reset();
759
+ close();
760
+ },
761
+ onInvalid: focus
762
+ }
763
+ )
764
+ ]
765
+ }
766
+ ),
767
+ /* @__PURE__ */ jsx4(
768
+ Primitive.Portal,
769
+ {
770
+ container: portalContainer,
771
+ children: /* @__PURE__ */ jsxs4(
772
+ Primitive.Content,
773
+ {
774
+ ref: popupRef,
775
+ role: "presentation",
776
+ sideOffset: 8,
777
+ align: "start",
778
+ collisionPadding: 16,
779
+ className: comboboxContentStyles(),
780
+ dir,
781
+ onOpenAutoFocus: (event) => {
782
+ event.preventDefault();
783
+ },
784
+ onCloseAutoFocus: (event) => {
785
+ event.preventDefault();
786
+ const target = finalFocus();
787
+ if (target) {
788
+ target.focus();
789
+ }
790
+ },
791
+ onInteractOutside: (event) => {
792
+ if (controlRef.current?.parentElement?.contains(event.target)) {
793
+ event.preventDefault();
794
+ } else {
795
+ close();
796
+ }
797
+ },
798
+ onEscapeKeyDown: (event) => {
799
+ event.preventDefault();
800
+ event.stopPropagation();
801
+ if (!event.isComposing) {
802
+ close();
803
+ focus();
804
+ }
805
+ },
806
+ onKeyDown: (event) => {
807
+ if (event.key === "Escape") {
808
+ event.stopPropagation();
809
+ }
810
+ },
811
+ children: [
812
+ visible.length === 0 && /* @__PURE__ */ jsx4(
813
+ "div",
814
+ {
815
+ role: "status",
816
+ className: selectEmptyStyles(),
817
+ children: emptyLabel
818
+ }
819
+ ),
820
+ /* @__PURE__ */ jsx4(
821
+ ComboboxOptions,
822
+ {
823
+ id: listId,
824
+ label: searchLabel,
825
+ options: filtered,
826
+ selected: selectedValue,
827
+ active,
828
+ optionId,
829
+ onSelect: choose,
830
+ onHighlight: search.highlight
831
+ }
832
+ ),
833
+ /* @__PURE__ */ jsx4(
834
+ SelectionActions,
835
+ {
836
+ actions,
837
+ onAction: runAction
838
+ }
839
+ )
840
+ ]
841
+ }
842
+ )
843
+ }
844
+ )
845
+ ]
846
+ }
847
+ );
848
+ };
849
+
850
+ // src/multi-select/multi-select.tsx
851
+ import { useListField } from "@gridui/form";
852
+ import { controlVariants as controlVariants2 } from "@gridui/input";
853
+ import { cn as cn3 } from "@gridui/style-utils";
854
+ import * as Primitive2 from "@radix-ui/react-popover";
855
+ import { ChevronDown as ChevronDown2, X as X2 } from "lucide-react";
856
+ import { useId as useId2, useRef as useRef5 } from "react";
857
+ import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
858
+ var MultiSelect = (props) => {
859
+ const {
860
+ value,
861
+ defaultValue,
862
+ onValueChange,
863
+ options,
864
+ placeholder,
865
+ searchLabel,
866
+ emptyLabel,
867
+ clearLabel,
868
+ required,
869
+ disabled,
870
+ readOnly,
871
+ name,
872
+ form,
873
+ portalContainer,
874
+ className,
875
+ ref,
876
+ onKeyDown,
877
+ ...restProps
878
+ } = props;
879
+ const search = useRef5(null);
880
+ const id = useId2();
881
+ const { selected, native, control, change } = useListField({
882
+ value,
883
+ defaultValue,
884
+ onValueChange,
885
+ disabled,
886
+ readOnly,
887
+ form
888
+ }, () => {
889
+ close();
890
+ });
891
+ const { open, popupRef: popup, available, changeOpen, close, focus, finalFocus } = useSelectionPopup({
892
+ disabled,
893
+ readOnly,
894
+ controlRef: control
895
+ });
896
+ const searchOptions = useSearchOptions(options, selected, `${id}-list`, open);
897
+ const { all, filtered, visible, query, active, optionId, activeOptionId } = searchOptions;
898
+ const choose = (option) => {
899
+ if (option.disabled || !available()) {
900
+ return;
901
+ }
902
+ change(selected.includes(option.value) ? selected.filter((entry) => {
903
+ return entry !== option.value;
904
+ }) : [
905
+ ...selected,
906
+ option.value
907
+ ]);
908
+ search.current?.focus({ preventScroll: true });
909
+ };
910
+ return /* @__PURE__ */ jsxs5(
911
+ Primitive2.Root,
912
+ {
913
+ open,
914
+ onOpenChange: changeOpen,
915
+ children: [
916
+ /* @__PURE__ */ jsxs5(
917
+ "div",
918
+ {
919
+ className: "flex min-w-0 items-stretch gap-gridui-4",
920
+ dir: restProps.dir,
921
+ children: [
922
+ /* @__PURE__ */ jsx5(
923
+ Primitive2.Trigger,
924
+ {
925
+ asChild: true,
926
+ children: /* @__PURE__ */ jsxs5(
927
+ "button",
928
+ {
929
+ ...restProps,
930
+ type: "button",
931
+ form,
932
+ disabled,
933
+ "aria-readonly": readOnly,
934
+ "aria-required": required,
935
+ ref: (element) => {
936
+ control.current = element;
937
+ if (typeof ref === "function") {
938
+ return ref(element);
939
+ }
940
+ if (ref) {
941
+ ref.current = element;
942
+ }
943
+ },
944
+ className: cn3(controlVariants2(), "flex flex-1 items-center gap-gridui-8 text-start", className),
945
+ onKeyDown: (event) => {
946
+ onKeyDown?.(event);
947
+ if (!event.defaultPrevented && (event.key === "ArrowDown" || event.key === "ArrowUp")) {
948
+ event.preventDefault();
949
+ changeOpen(true);
950
+ }
951
+ },
952
+ children: [
953
+ /* @__PURE__ */ jsx5(
954
+ "span",
955
+ {
956
+ className: "min-w-0 flex-1 wrap-anywhere",
957
+ children: selected.length ? selected.map((entry) => {
958
+ return all.find((option) => {
959
+ return option.value === entry;
960
+ })?.label ?? entry;
961
+ }).join(", ") : placeholder
962
+ }
963
+ ),
964
+ /* @__PURE__ */ jsx5(
965
+ ChevronDown2,
966
+ {
967
+ size: 16,
968
+ "aria-hidden": "true"
969
+ }
970
+ )
971
+ ]
972
+ }
973
+ )
974
+ }
975
+ ),
976
+ clearLabel && /* @__PURE__ */ jsx5(
977
+ "button",
978
+ {
979
+ type: "button",
980
+ "aria-label": clearLabel,
981
+ disabled: disabled || readOnly || required || !selected.length,
982
+ className: cn3(controlVariants2(), "flex w-auto shrink-0 items-center justify-center min-w-11 cursor-pointer hover:enabled:bg-surface"),
983
+ onClick: () => {
984
+ change([]);
985
+ control.current?.focus();
986
+ },
987
+ children: /* @__PURE__ */ jsx5(
988
+ X2,
989
+ {
990
+ size: 16,
991
+ "aria-hidden": "true"
992
+ }
993
+ )
994
+ }
995
+ ),
996
+ /* @__PURE__ */ jsxs5(
997
+ "select",
998
+ {
999
+ ref: native,
1000
+ multiple: true,
1001
+ className: "sr-only",
1002
+ "aria-hidden": "true",
1003
+ tabIndex: -1,
1004
+ name,
1005
+ form,
1006
+ required,
1007
+ disabled,
1008
+ value: selected,
1009
+ onChange: (event) => {
1010
+ change(Array.from(event.currentTarget.selectedOptions, (option) => {
1011
+ return option.value;
1012
+ }));
1013
+ },
1014
+ onInvalid: (event) => {
1015
+ event.preventDefault();
1016
+ control.current?.focus();
1017
+ },
1018
+ children: [
1019
+ all.map((option) => {
1020
+ return /* @__PURE__ */ jsx5(
1021
+ "option",
1022
+ {
1023
+ value: option.value,
1024
+ disabled: option.disabled,
1025
+ children: option.label
1026
+ },
1027
+ option.value
1028
+ );
1029
+ }),
1030
+ selected.filter((entry) => {
1031
+ return !all.some((option) => {
1032
+ return option.value === entry;
1033
+ });
1034
+ }).map((entry) => {
1035
+ return /* @__PURE__ */ jsx5(
1036
+ "option",
1037
+ {
1038
+ value: entry,
1039
+ children: entry
1040
+ },
1041
+ entry
1042
+ );
1043
+ })
1044
+ ]
1045
+ }
1046
+ )
1047
+ ]
1048
+ }
1049
+ ),
1050
+ /* @__PURE__ */ jsx5(
1051
+ Primitive2.Portal,
1052
+ {
1053
+ container: portalContainer,
1054
+ children: /* @__PURE__ */ jsxs5(
1055
+ Primitive2.Content,
1056
+ {
1057
+ ref: popup,
1058
+ "aria-label": searchLabel,
1059
+ sideOffset: 8,
1060
+ align: "start",
1061
+ collisionPadding: 16,
1062
+ dir: restProps.dir,
1063
+ className: comboboxContentStyles(),
1064
+ onOpenAutoFocus: (event) => {
1065
+ event.preventDefault();
1066
+ search.current?.focus({ preventScroll: true });
1067
+ },
1068
+ onCloseAutoFocus: (event) => {
1069
+ event.preventDefault();
1070
+ const target = finalFocus();
1071
+ if (target) {
1072
+ target.focus();
1073
+ }
1074
+ },
1075
+ onEscapeKeyDown: (event) => {
1076
+ event.preventDefault();
1077
+ event.stopPropagation();
1078
+ if (!event.isComposing) {
1079
+ close();
1080
+ focus();
1081
+ }
1082
+ },
1083
+ children: [
1084
+ /* @__PURE__ */ jsx5(
1085
+ "input",
1086
+ {
1087
+ ref: search,
1088
+ type: "text",
1089
+ role: "combobox",
1090
+ "aria-label": searchLabel,
1091
+ "aria-expanded": "true",
1092
+ "aria-autocomplete": "list",
1093
+ "aria-controls": `${id}-list`,
1094
+ "aria-activedescendant": activeOptionId,
1095
+ value: query ?? "",
1096
+ className: cn3(controlVariants2({ size: "small" }), "mb-gridui-4 shrink-0"),
1097
+ onChange: (event) => {
1098
+ searchOptions.changeQuery(event.target.value);
1099
+ },
1100
+ onKeyDown: (event) => {
1101
+ if (event.nativeEvent.isComposing) {
1102
+ event.stopPropagation();
1103
+ return;
1104
+ }
1105
+ if (event.key === "ArrowDown" || event.key === "ArrowUp") {
1106
+ event.preventDefault();
1107
+ searchOptions.moveActive(event.key === "ArrowDown" ? 1 : -1);
1108
+ }
1109
+ if (event.key === "Enter") {
1110
+ event.preventDefault();
1111
+ const option = searchOptions.activeOption;
1112
+ if (option) {
1113
+ choose(option);
1114
+ }
1115
+ }
1116
+ }
1117
+ }
1118
+ ),
1119
+ /* @__PURE__ */ jsx5(
1120
+ ComboboxOptions,
1121
+ {
1122
+ id: `${id}-list`,
1123
+ label: searchLabel,
1124
+ options: filtered,
1125
+ selected,
1126
+ multiple: true,
1127
+ active,
1128
+ optionId,
1129
+ onSelect: choose,
1130
+ onHighlight: searchOptions.highlight
1131
+ }
1132
+ ),
1133
+ !visible.length && /* @__PURE__ */ jsx5(
1134
+ "div",
1135
+ {
1136
+ role: "status",
1137
+ className: selectEmptyStyles(),
1138
+ children: emptyLabel
1139
+ }
1140
+ )
1141
+ ]
1142
+ }
1143
+ )
1144
+ }
1145
+ )
1146
+ ]
1147
+ }
1148
+ );
1149
+ };
1150
+
1151
+ // src/select/style.ts
1152
+ import { dropdownContentStyles as dropdownContentStyles2 } from "@gridui/dropdown-menu";
1153
+ import { cn as cn4 } from "@gridui/style-utils";
1154
+ import { cva as cva3 } from "class-variance-authority";
1155
+ var selectContentStyles = cva3(cn4(
1156
+ dropdownContentStyles2(),
1157
+ "gridui-select-content box-border relative flex flex-col overflow-hidden min-w-0 w-(--anchor-width) max-w-(--available-width) max-h-(--available-height)"
1158
+ ));
1159
+ var selectMenuItemStyles = cva3(cn4(selectItemStyles(), "relative px-gridui-4 pr-9"));
1160
+ var selectIndicatorStyles = cva3("absolute inset-y-0 right-gridui-4 flex w-gridui-16 items-center justify-center text-foreground");
1161
+ var selectScrollArrowStyles = cva3("absolute inset-x-0 z-(--gridui-z-content) flex h-gridui-24 items-center justify-center bg-background text-foreground", {
1162
+ variants: {
1163
+ direction: {
1164
+ up: "top-0",
1165
+ down: "bottom-0"
1166
+ }
1167
+ }
1168
+ });
1169
+
1170
+ // src/select/select-options.tsx
1171
+ import { dropdownLabelStyles as dropdownLabelStyles2 } from "@gridui/dropdown-menu";
1172
+ import * as Primitive3 from "@radix-ui/react-select";
1173
+ import { Check as Check2 } from "lucide-react";
1174
+ import { useId as useId3 } from "react";
1175
+ import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
1176
+ var SelectOptions = (props) => {
1177
+ const { options, id, label } = props;
1178
+ return /* @__PURE__ */ jsx6(
1179
+ Primitive3.Viewport,
1180
+ {
1181
+ className: selectListStyles(),
1182
+ role: "listbox",
1183
+ id,
1184
+ "aria-label": label,
1185
+ children: options.map((entry) => {
1186
+ if (!("options" in entry)) {
1187
+ return /* @__PURE__ */ jsx6(
1188
+ SelectOptionItem,
1189
+ {
1190
+ option: entry
1191
+ },
1192
+ entry.value
1193
+ );
1194
+ }
1195
+ return /* @__PURE__ */ jsxs6(
1196
+ Primitive3.Group,
1197
+ {
1198
+ children: [
1199
+ /* @__PURE__ */ jsx6(
1200
+ Primitive3.Label,
1201
+ {
1202
+ className: dropdownLabelStyles2(),
1203
+ children: entry.label
1204
+ }
1205
+ ),
1206
+ entry.options.map((option) => {
1207
+ return /* @__PURE__ */ jsx6(
1208
+ SelectOptionItem,
1209
+ {
1210
+ option
1211
+ },
1212
+ option.value
1213
+ );
1214
+ })
1215
+ ]
1216
+ },
1217
+ entry.label
1218
+ );
1219
+ })
1220
+ }
1221
+ );
1222
+ };
1223
+ var SelectOptionItem = (props) => {
1224
+ const { option } = props;
1225
+ const labelId = useId3();
1226
+ const descriptionId = `${labelId}-description`;
1227
+ return /* @__PURE__ */ jsxs6(
1228
+ Primitive3.Item,
1229
+ {
1230
+ value: `gridui:${option.value}`,
1231
+ "aria-labelledby": labelId,
1232
+ "aria-describedby": option.description ? descriptionId : void 0,
1233
+ textValue: option.label,
1234
+ disabled: option.disabled,
1235
+ className: selectMenuItemStyles(),
1236
+ children: [
1237
+ option.icon && /* @__PURE__ */ jsx6(
1238
+ "span",
1239
+ {
1240
+ className: selectIconStyles(),
1241
+ "aria-hidden": "true",
1242
+ children: option.icon
1243
+ }
1244
+ ),
1245
+ /* @__PURE__ */ jsxs6(
1246
+ "span",
1247
+ {
1248
+ className: selectOptionContentStyles(),
1249
+ children: [
1250
+ /* @__PURE__ */ jsx6(
1251
+ Primitive3.ItemText,
1252
+ {
1253
+ id: labelId,
1254
+ children: option.label
1255
+ }
1256
+ ),
1257
+ option.description && /* @__PURE__ */ jsx6(
1258
+ "span",
1259
+ {
1260
+ id: descriptionId,
1261
+ className: selectOptionDescriptionStyles(),
1262
+ children: option.description
1263
+ }
1264
+ )
1265
+ ]
1266
+ }
1267
+ ),
1268
+ /* @__PURE__ */ jsx6(
1269
+ Primitive3.ItemIndicator,
1270
+ {
1271
+ className: selectIndicatorStyles(),
1272
+ "aria-hidden": "true",
1273
+ children: /* @__PURE__ */ jsx6(
1274
+ Check2,
1275
+ {
1276
+ size: 16
1277
+ }
1278
+ )
1279
+ }
1280
+ )
1281
+ ]
1282
+ }
1283
+ );
1284
+ };
1285
+
1286
+ // src/select/select.tsx
1287
+ import { controlVariants as controlVariants3 } from "@gridui/input";
1288
+ import { cn as cn5 } from "@gridui/style-utils";
1289
+ import * as Primitive4 from "@radix-ui/react-select";
1290
+ import { ChevronDown as ChevronDown3, ChevronUp, X as X3 } from "lucide-react";
1291
+ import { useId as useId4, useRef as useRef6, useState as useState4 } from "react";
1292
+ import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
1293
+ var Select = (props) => {
1294
+ const {
1295
+ options,
1296
+ actions = [],
1297
+ value,
1298
+ defaultValue = "",
1299
+ onValueChange,
1300
+ placeholder,
1301
+ controlSize = "standard",
1302
+ position = "popper",
1303
+ clearLabel,
1304
+ required,
1305
+ disabled,
1306
+ name,
1307
+ form,
1308
+ dir,
1309
+ portalContainer,
1310
+ className,
1311
+ ref,
1312
+ ...restProps
1313
+ } = props;
1314
+ const controlRef = useRef6(null);
1315
+ const {
1316
+ open,
1317
+ popupRef,
1318
+ available,
1319
+ changeOpen,
1320
+ close,
1321
+ focus,
1322
+ runAction,
1323
+ finalFocus
1324
+ } = useSelectionPopup({
1325
+ disabled,
1326
+ controlRef
1327
+ });
1328
+ const { selectedValue, change, reset } = useSelectionValue({
1329
+ value,
1330
+ defaultValue,
1331
+ onValueChange
1332
+ }, available);
1333
+ const listId = useId4();
1334
+ const [
1335
+ triggerWidth,
1336
+ setTriggerWidth
1337
+ ] = useState4();
1338
+ const allOptions = flattenOptions(options);
1339
+ const selected = allOptions.find((option) => {
1340
+ return option.value === selectedValue;
1341
+ });
1342
+ const fallback = selectedValue === "" ? placeholder ?? "" : selectedValue;
1343
+ const display = selected?.label ?? fallback;
1344
+ return /* @__PURE__ */ jsxs7(
1345
+ Primitive4.Root,
1346
+ {
1347
+ form: `${listId}-detached`,
1348
+ value: selected ? `gridui:${selectedValue}` : "",
1349
+ disabled,
1350
+ open,
1351
+ onOpenChange: (next) => {
1352
+ if (next) {
1353
+ setTriggerWidth(controlRef.current?.getBoundingClientRect().width);
1354
+ }
1355
+ changeOpen(next);
1356
+ },
1357
+ onValueChange: (next) => {
1358
+ change(next.slice(7));
1359
+ },
1360
+ dir: dir === "rtl" ? "rtl" : "ltr",
1361
+ children: [
1362
+ /* @__PURE__ */ jsxs7(
1363
+ "div",
1364
+ {
1365
+ className: "relative flex min-w-0 w-full items-stretch gap-gridui-4",
1366
+ dir,
1367
+ children: [
1368
+ /* @__PURE__ */ jsxs7(
1369
+ Primitive4.Trigger,
1370
+ {
1371
+ ...restProps,
1372
+ form,
1373
+ "aria-controls": open ? listId : void 0,
1374
+ "aria-required": required,
1375
+ ref: (element) => {
1376
+ controlRef.current = element;
1377
+ if (typeof ref === "function") {
1378
+ return ref(element);
1379
+ }
1380
+ if (ref) {
1381
+ ref.current = element;
1382
+ }
1383
+ },
1384
+ className: cn5(controlVariants3({ size: controlSize }), "flex flex-1 items-center gap-gridui-8 text-start", className),
1385
+ children: [
1386
+ selected?.icon && /* @__PURE__ */ jsx7(
1387
+ "span",
1388
+ {
1389
+ className: selectIconStyles(),
1390
+ "aria-hidden": "true",
1391
+ children: selected.icon
1392
+ }
1393
+ ),
1394
+ /* @__PURE__ */ jsx7(
1395
+ "span",
1396
+ {
1397
+ className: "min-w-0 flex-1 whitespace-normal wrap-anywhere",
1398
+ children: /* @__PURE__ */ jsx7(
1399
+ Primitive4.Value,
1400
+ {
1401
+ placeholder: display,
1402
+ children: display
1403
+ }
1404
+ )
1405
+ }
1406
+ ),
1407
+ /* @__PURE__ */ jsx7(Primitive4.Icon, { children: /* @__PURE__ */ jsx7(
1408
+ ChevronDown3,
1409
+ {
1410
+ size: 16,
1411
+ className: "shrink-0",
1412
+ "aria-hidden": "true"
1413
+ }
1414
+ ) })
1415
+ ]
1416
+ }
1417
+ ),
1418
+ clearLabel && /* @__PURE__ */ jsx7(
1419
+ "button",
1420
+ {
1421
+ type: "button",
1422
+ disabled: disabled || required || selectedValue === "",
1423
+ "aria-label": clearLabel,
1424
+ onClick: () => {
1425
+ change("");
1426
+ controlRef.current?.focus();
1427
+ },
1428
+ className: cn5(controlVariants3({ size: controlSize }), "flex w-auto shrink-0 items-center justify-center min-w-11 cursor-pointer hover:enabled:bg-surface"),
1429
+ children: /* @__PURE__ */ jsx7(
1430
+ X3,
1431
+ {
1432
+ size: 16,
1433
+ "aria-hidden": "true"
1434
+ }
1435
+ )
1436
+ }
1437
+ ),
1438
+ /* @__PURE__ */ jsx7(
1439
+ SelectionForm,
1440
+ {
1441
+ name,
1442
+ form,
1443
+ required,
1444
+ disabled,
1445
+ selectedValue,
1446
+ allOptions,
1447
+ onValueChange: change,
1448
+ onReset: () => {
1449
+ reset();
1450
+ close();
1451
+ },
1452
+ onInvalid: focus
1453
+ }
1454
+ )
1455
+ ]
1456
+ }
1457
+ ),
1458
+ /* @__PURE__ */ jsx7(
1459
+ Primitive4.Portal,
1460
+ {
1461
+ container: portalContainer,
1462
+ children: /* @__PURE__ */ jsxs7(
1463
+ Primitive4.Content,
1464
+ {
1465
+ position,
1466
+ align: "start",
1467
+ sideOffset: 8,
1468
+ collisionPadding: 16,
1469
+ ref: popupRef,
1470
+ role: "presentation",
1471
+ ...position === "item-aligned" ? {
1472
+ "data-side": "none",
1473
+ style: { width: triggerWidth }
1474
+ } : {},
1475
+ className: selectContentStyles(),
1476
+ dir,
1477
+ onCloseAutoFocus: (event) => {
1478
+ event.preventDefault();
1479
+ const target = finalFocus();
1480
+ if (target) {
1481
+ target.focus();
1482
+ }
1483
+ },
1484
+ onPointerDownOutside: () => {
1485
+ close();
1486
+ },
1487
+ onEscapeKeyDown: (event) => {
1488
+ event.preventDefault();
1489
+ event.stopPropagation();
1490
+ changeOpen(false);
1491
+ },
1492
+ onKeyDown: (event) => {
1493
+ if (event.key === "Escape") {
1494
+ event.stopPropagation();
1495
+ }
1496
+ if (event.key === "Tab") {
1497
+ event.preventDefault();
1498
+ const controls = Array.from(event.currentTarget.querySelectorAll("button:not(:disabled), a[href]"));
1499
+ const active = controls.indexOf(event.target);
1500
+ const next = controls[active + (event.shiftKey ? -1 : 1)];
1501
+ if (next) {
1502
+ next.focus();
1503
+ } else {
1504
+ popupRef.current?.querySelector('[role="option"][data-state="checked"]')?.focus();
1505
+ }
1506
+ }
1507
+ if (event.target.closest("button, a") && event.key !== "Tab") {
1508
+ event.stopPropagation();
1509
+ }
1510
+ },
1511
+ children: [
1512
+ /* @__PURE__ */ jsxs7(
1513
+ "div",
1514
+ {
1515
+ className: "relative flex min-h-0 flex-col",
1516
+ children: [
1517
+ /* @__PURE__ */ jsx7(
1518
+ Primitive4.ScrollUpButton,
1519
+ {
1520
+ className: selectScrollArrowStyles({ direction: "up" }),
1521
+ children: /* @__PURE__ */ jsx7(
1522
+ ChevronUp,
1523
+ {
1524
+ size: 16,
1525
+ "aria-hidden": "true"
1526
+ }
1527
+ )
1528
+ }
1529
+ ),
1530
+ /* @__PURE__ */ jsx7(
1531
+ SelectOptions,
1532
+ {
1533
+ options,
1534
+ id: listId,
1535
+ label: restProps["aria-label"]
1536
+ }
1537
+ ),
1538
+ /* @__PURE__ */ jsx7(
1539
+ Primitive4.ScrollDownButton,
1540
+ {
1541
+ className: selectScrollArrowStyles({ direction: "down" }),
1542
+ children: /* @__PURE__ */ jsx7(
1543
+ ChevronDown3,
1544
+ {
1545
+ size: 16,
1546
+ "aria-hidden": "true"
1547
+ }
1548
+ )
1549
+ }
1550
+ )
1551
+ ]
1552
+ }
1553
+ ),
1554
+ /* @__PURE__ */ jsx7(
1555
+ SelectionActions,
1556
+ {
1557
+ actions,
1558
+ onAction: runAction
1559
+ }
1560
+ )
1561
+ ]
1562
+ }
1563
+ )
1564
+ }
1565
+ )
1566
+ ]
1567
+ }
1568
+ );
1569
+ };
1570
+ export {
1571
+ Combobox,
1572
+ MultiSelect,
1573
+ Select
1574
+ };
1575
+ //# sourceMappingURL=index.js.map