@mirohq/design-system-combobox 0.1.0-combobox.8 → 0.1.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/main.js +287 -160
- package/dist/main.js.map +1 -1
- package/dist/module.js +289 -162
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +83 -5
- package/package.json +11 -10
package/dist/main.js
CHANGED
|
@@ -6,8 +6,8 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
6
6
|
var React = require('react');
|
|
7
7
|
var react = require('@ariakit/react');
|
|
8
8
|
var designSystemBaseForm = require('@mirohq/design-system-base-form');
|
|
9
|
-
var RadixPopover = require('@radix-ui/react-popover');
|
|
10
9
|
var designSystemUtils = require('@mirohq/design-system-utils');
|
|
10
|
+
var RadixPopover = require('@radix-ui/react-popover');
|
|
11
11
|
var designSystemStitches = require('@mirohq/design-system-stitches');
|
|
12
12
|
var designSystemInput = require('@mirohq/design-system-input');
|
|
13
13
|
var reactUseControllableState = require('@radix-ui/react-use-controllable-state');
|
|
@@ -16,7 +16,9 @@ var designSystemScrollArea = require('@mirohq/design-system-scroll-area');
|
|
|
16
16
|
var designSystemPrimitive = require('@mirohq/design-system-primitive');
|
|
17
17
|
var utils = require('@react-aria/utils');
|
|
18
18
|
var designSystemUseAriaDisabled = require('@mirohq/design-system-use-aria-disabled');
|
|
19
|
+
var designSystemUseLayoutEffect = require('@mirohq/design-system-use-layout-effect');
|
|
19
20
|
var designSystemStyles = require('@mirohq/design-system-styles');
|
|
21
|
+
var reactDom = require('react-dom');
|
|
20
22
|
var designSystemBaseButton = require('@mirohq/design-system-base-button');
|
|
21
23
|
|
|
22
24
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -42,14 +44,10 @@ function _interopNamespace(e) {
|
|
|
42
44
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
43
45
|
var RadixPopover__namespace = /*#__PURE__*/_interopNamespace(RadixPopover);
|
|
44
46
|
|
|
45
|
-
const StyledAnchor = designSystemStitches.styled(RadixPopover.Anchor, {
|
|
46
|
-
position: "relative",
|
|
47
|
-
width: "100%"
|
|
48
|
-
});
|
|
49
47
|
const StyledInput = designSystemStitches.styled(designSystemInput.Input, {
|
|
50
48
|
flexWrap: "wrap",
|
|
51
49
|
flexGrow: 1,
|
|
52
|
-
gap: "
|
|
50
|
+
gap: "$50",
|
|
53
51
|
overflowY: "scroll",
|
|
54
52
|
"&[data-valid], &[data-invalid]": {
|
|
55
53
|
// we don't need a bigger padding here as Input component will render its own icon
|
|
@@ -118,6 +116,9 @@ const ComboboxProvider = ({
|
|
|
118
116
|
});
|
|
119
117
|
const [filteredItems, setFilteredItems] = React.useState(/* @__PURE__ */ new Set());
|
|
120
118
|
const [searchValue, setSearchValue] = React.useState("");
|
|
119
|
+
const [size, setSize] = React.useState();
|
|
120
|
+
const [placeholder, setPlaceholder] = React.useState();
|
|
121
|
+
const [itemValueTextMap, setItemValueTextMap] = React.useState(/* @__PURE__ */ new Map());
|
|
121
122
|
const { valid: formFieldValid } = designSystemBaseForm.useFormFieldContext();
|
|
122
123
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
123
124
|
ComboboxContext.Provider,
|
|
@@ -139,7 +140,13 @@ const ComboboxProvider = ({
|
|
|
139
140
|
searchValue,
|
|
140
141
|
setSearchValue,
|
|
141
142
|
filteredItems,
|
|
142
|
-
setFilteredItems
|
|
143
|
+
setFilteredItems,
|
|
144
|
+
itemValueTextMap,
|
|
145
|
+
setItemValueTextMap,
|
|
146
|
+
placeholder,
|
|
147
|
+
setPlaceholder,
|
|
148
|
+
size,
|
|
149
|
+
setSize
|
|
143
150
|
},
|
|
144
151
|
children
|
|
145
152
|
}
|
|
@@ -223,7 +230,6 @@ const Trigger = React__default["default"].forwardRef(
|
|
|
223
230
|
closeActionLabel,
|
|
224
231
|
clearActionLabel,
|
|
225
232
|
onChange,
|
|
226
|
-
css,
|
|
227
233
|
...restProps
|
|
228
234
|
}, forwardRef) => {
|
|
229
235
|
const {
|
|
@@ -237,16 +243,21 @@ const Trigger = React__default["default"].forwardRef(
|
|
|
237
243
|
onSearchValueChange,
|
|
238
244
|
searchValue,
|
|
239
245
|
setSearchValue,
|
|
240
|
-
setOpenState
|
|
246
|
+
setOpenState,
|
|
247
|
+
setSize,
|
|
248
|
+
setPlaceholder
|
|
241
249
|
} = useComboboxContext();
|
|
242
250
|
const {
|
|
243
251
|
formElementId,
|
|
244
252
|
ariaInvalid: formFieldAriaInvalid,
|
|
245
|
-
valid: formFieldValid
|
|
246
|
-
label,
|
|
247
|
-
isFloatingLabel,
|
|
248
|
-
focused
|
|
253
|
+
valid: formFieldValid
|
|
249
254
|
} = designSystemBaseForm.useFormFieldContext();
|
|
255
|
+
React.useEffect(() => {
|
|
256
|
+
setSize(size);
|
|
257
|
+
}, [size, setSize]);
|
|
258
|
+
React.useEffect(() => {
|
|
259
|
+
setPlaceholder(placeholder);
|
|
260
|
+
}, [setPlaceholder, placeholder]);
|
|
250
261
|
const valid = formFieldValid != null ? formFieldValid : comboboxValid;
|
|
251
262
|
const inputProps = {
|
|
252
263
|
...restProps,
|
|
@@ -261,8 +272,6 @@ const Trigger = React__default["default"].forwardRef(
|
|
|
261
272
|
id: id != null ? id : formElementId,
|
|
262
273
|
placeholder: value.length === 0 ? placeholder : void 0
|
|
263
274
|
};
|
|
264
|
-
const shouldUseFloatingLabel = label !== null && isFloatingLabel;
|
|
265
|
-
const isFloating = placeholder !== void 0 || value.length !== 0 || focused || searchValue !== "";
|
|
266
275
|
const scrollIntoView = (event) => {
|
|
267
276
|
var _a;
|
|
268
277
|
const trigger = triggerRef == null ? void 0 : triggerRef.current;
|
|
@@ -282,47 +291,43 @@ const Trigger = React__default["default"].forwardRef(
|
|
|
282
291
|
onSearchValueChange == null ? void 0 : onSearchValueChange(e.target.value);
|
|
283
292
|
onChange == null ? void 0 : onChange(e);
|
|
284
293
|
};
|
|
285
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
286
|
-
|
|
294
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
295
|
+
RadixPopover.Anchor,
|
|
287
296
|
{
|
|
288
297
|
ref: designSystemUtils.mergeRefs([triggerRef, forwardRef]),
|
|
289
|
-
css,
|
|
290
298
|
onClick: () => {
|
|
291
299
|
if (!designSystemUtils.booleanify(disabled) && !designSystemUtils.booleanify(ariaDisabled) && !designSystemUtils.booleanify(readOnly)) {
|
|
292
300
|
setOpenState(true);
|
|
293
301
|
}
|
|
294
302
|
},
|
|
295
|
-
children:
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
}
|
|
324
|
-
)
|
|
325
|
-
]
|
|
303
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
304
|
+
react.Combobox,
|
|
305
|
+
{
|
|
306
|
+
render: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
307
|
+
StyledInput,
|
|
308
|
+
{
|
|
309
|
+
...inputProps,
|
|
310
|
+
value: searchValue,
|
|
311
|
+
size,
|
|
312
|
+
ref: inputRef,
|
|
313
|
+
onChange: onInputChange,
|
|
314
|
+
onFocus: scrollIntoView,
|
|
315
|
+
children: [
|
|
316
|
+
children,
|
|
317
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
318
|
+
TriggerActionButton,
|
|
319
|
+
{
|
|
320
|
+
openActionLabel,
|
|
321
|
+
closeActionLabel,
|
|
322
|
+
clearActionLabel,
|
|
323
|
+
size
|
|
324
|
+
}
|
|
325
|
+
)
|
|
326
|
+
]
|
|
327
|
+
}
|
|
328
|
+
)
|
|
329
|
+
}
|
|
330
|
+
)
|
|
326
331
|
}
|
|
327
332
|
);
|
|
328
333
|
}
|
|
@@ -388,7 +393,24 @@ const StyledItem = designSystemStitches.styled(react.ComboboxItem, {
|
|
|
388
393
|
const Item = React__default["default"].forwardRef(
|
|
389
394
|
({ disabled = false, value, textValue, children, ...restProps }, forwardRef) => {
|
|
390
395
|
const { "aria-disabled": ariaDisabled, ...restAriaDisabledProps } = designSystemUseAriaDisabled.useAriaDisabled(restProps, { allowArrows: true });
|
|
391
|
-
const {
|
|
396
|
+
const {
|
|
397
|
+
autoFilter,
|
|
398
|
+
filteredItems,
|
|
399
|
+
setItemValueTextMap,
|
|
400
|
+
triggerRef,
|
|
401
|
+
inputRef,
|
|
402
|
+
value: comboboxValue = []
|
|
403
|
+
} = useComboboxContext();
|
|
404
|
+
designSystemUseLayoutEffect.useLayoutEffect(() => {
|
|
405
|
+
const textToSet = textValue !== void 0 ? textValue : typeof children === "string" ? children : "";
|
|
406
|
+
setItemValueTextMap((prevState) => new Map(prevState.set(value, textToSet)));
|
|
407
|
+
return () => {
|
|
408
|
+
setItemValueTextMap((prevState) => {
|
|
409
|
+
prevState.delete(value);
|
|
410
|
+
return new Map(prevState);
|
|
411
|
+
});
|
|
412
|
+
};
|
|
413
|
+
}, [setItemValueTextMap, value, textValue, children]);
|
|
392
414
|
if (autoFilter !== false && !filteredItems.has(value)) {
|
|
393
415
|
return null;
|
|
394
416
|
}
|
|
@@ -403,6 +425,7 @@ const Item = React__default["default"].forwardRef(
|
|
|
403
425
|
restProps.onClick(event);
|
|
404
426
|
}
|
|
405
427
|
};
|
|
428
|
+
const isSelected = comboboxValue.includes(value);
|
|
406
429
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
407
430
|
StyledItem,
|
|
408
431
|
{
|
|
@@ -414,10 +437,12 @@ const Item = React__default["default"].forwardRef(
|
|
|
414
437
|
ref: forwardRef,
|
|
415
438
|
value,
|
|
416
439
|
onClick: scrollIntoView,
|
|
440
|
+
"aria-selected": isSelected,
|
|
417
441
|
children: [
|
|
418
442
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
419
443
|
react.ComboboxItemCheck,
|
|
420
444
|
{
|
|
445
|
+
checked: isSelected,
|
|
421
446
|
render: ({ style, ...props }) => (
|
|
422
447
|
// AriakitComboboxItemCheck adds its owm inline styles which we want to omit here
|
|
423
448
|
/* @__PURE__ */ jsxRuntime.jsx(StyledItemCheck, { ...props })
|
|
@@ -460,6 +485,22 @@ const getChildrenItemValues = (componentChildren) => {
|
|
|
460
485
|
return values;
|
|
461
486
|
};
|
|
462
487
|
|
|
488
|
+
const useDocumentFragment = () => {
|
|
489
|
+
const [fragment, setFragment] = React__default["default"].useState();
|
|
490
|
+
designSystemUseLayoutEffect.useLayoutEffect(() => {
|
|
491
|
+
setFragment(new DocumentFragment());
|
|
492
|
+
}, []);
|
|
493
|
+
return fragment;
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
const useInvisibleContent = () => {
|
|
497
|
+
const fragment = useDocumentFragment();
|
|
498
|
+
return React.useCallback(
|
|
499
|
+
(children) => fragment !== void 0 ? reactDom.createPortal(/* @__PURE__ */ jsxRuntime.jsx("div", { children }), fragment) : null,
|
|
500
|
+
[fragment]
|
|
501
|
+
);
|
|
502
|
+
};
|
|
503
|
+
|
|
463
504
|
const CONTENT_OFFSET = parseInt(designSystemStitches.theme.space[50]);
|
|
464
505
|
const isInsideRef = (element, ref) => {
|
|
465
506
|
var _a, _b;
|
|
@@ -467,9 +508,16 @@ const isInsideRef = (element, ref) => {
|
|
|
467
508
|
};
|
|
468
509
|
const Content = React__default["default"].forwardRef(
|
|
469
510
|
({
|
|
511
|
+
side = "bottom",
|
|
470
512
|
sideOffset = CONTENT_OFFSET,
|
|
513
|
+
align = "center",
|
|
514
|
+
alignOffset = 0,
|
|
515
|
+
collisionPadding = 0,
|
|
516
|
+
avoidCollisions = true,
|
|
517
|
+
sticky = "partial",
|
|
518
|
+
hideWhenDetached = true,
|
|
519
|
+
overflow = "visible",
|
|
471
520
|
maxHeight,
|
|
472
|
-
overflow,
|
|
473
521
|
children,
|
|
474
522
|
...restProps
|
|
475
523
|
}, forwardRef) => {
|
|
@@ -481,7 +529,8 @@ const Content = React__default["default"].forwardRef(
|
|
|
481
529
|
setFilteredItems,
|
|
482
530
|
searchValue,
|
|
483
531
|
noResultsText,
|
|
484
|
-
direction
|
|
532
|
+
direction,
|
|
533
|
+
openState
|
|
485
534
|
} = useComboboxContext();
|
|
486
535
|
React.useEffect(() => {
|
|
487
536
|
const childrenItemValues = getChildrenItemValues(children);
|
|
@@ -493,14 +542,28 @@ const Content = React__default["default"].forwardRef(
|
|
|
493
542
|
)
|
|
494
543
|
);
|
|
495
544
|
}, [children, autoFilter, setFilteredItems, searchValue]);
|
|
496
|
-
const
|
|
545
|
+
const getInvisibleContent = useInvisibleContent();
|
|
546
|
+
if (!openState) {
|
|
547
|
+
return getInvisibleContent(children);
|
|
548
|
+
}
|
|
549
|
+
const content = filteredItems.size === 0 ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
550
|
+
/* @__PURE__ */ jsxRuntime.jsx(NoResultPlaceholder, { children: noResultsText }),
|
|
551
|
+
getInvisibleContent(children)
|
|
552
|
+
] }) : children;
|
|
497
553
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
498
554
|
StyledContent,
|
|
499
555
|
{
|
|
500
556
|
asChild: true,
|
|
501
557
|
...restProps,
|
|
502
558
|
dir: direction,
|
|
559
|
+
side,
|
|
503
560
|
sideOffset,
|
|
561
|
+
align,
|
|
562
|
+
alignOffset,
|
|
563
|
+
avoidCollisions,
|
|
564
|
+
collisionPadding,
|
|
565
|
+
sticky,
|
|
566
|
+
hideWhenDetached,
|
|
504
567
|
ref: designSystemUtils.mergeRefs([forwardRef, contentRef]),
|
|
505
568
|
onOpenAutoFocus: (event) => event.preventDefault(),
|
|
506
569
|
onInteractOutside: (event) => {
|
|
@@ -546,8 +609,9 @@ const Group = React__default["default"].forwardRef(({ children, ...rest }, forwa
|
|
|
546
609
|
),
|
|
547
610
|
[childValues, filteredItems, autoFilter]
|
|
548
611
|
);
|
|
612
|
+
const getInvisibleContent = useInvisibleContent();
|
|
549
613
|
if (!hasVisibleChildren) {
|
|
550
|
-
return
|
|
614
|
+
return getInvisibleContent(children);
|
|
551
615
|
}
|
|
552
616
|
return /* @__PURE__ */ jsxRuntime.jsx(StyledGroup, { ...rest, ref: forwardRef, children });
|
|
553
617
|
});
|
|
@@ -599,35 +663,45 @@ const Chip = React__default["default"].forwardRef(
|
|
|
599
663
|
);
|
|
600
664
|
Chip.LeftSlot = LeftSlot;
|
|
601
665
|
|
|
602
|
-
const StyledValue = designSystemStitches.styled(Chip, {
|
|
603
|
-
marginTop: "$50"
|
|
604
|
-
});
|
|
605
|
-
|
|
606
666
|
const Value = ({ unselectAriaLabel }) => {
|
|
607
667
|
const {
|
|
608
668
|
value = [],
|
|
609
669
|
setValue,
|
|
610
670
|
disabled,
|
|
611
|
-
"aria-disabled": ariaDisabled
|
|
671
|
+
"aria-disabled": ariaDisabled,
|
|
672
|
+
itemValueTextMap
|
|
612
673
|
} = useComboboxContext();
|
|
613
674
|
const isDisabled = ariaDisabled === true || disabled;
|
|
614
|
-
const onItemRemove = (
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
if (value.length === 0) {
|
|
618
|
-
return null;
|
|
619
|
-
}
|
|
620
|
-
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: value.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
621
|
-
StyledValue,
|
|
622
|
-
{
|
|
623
|
-
onRemove: () => onItemRemove(item),
|
|
624
|
-
disabled: isDisabled,
|
|
625
|
-
removeAriaLabel: "".concat(unselectAriaLabel, " ").concat(item),
|
|
626
|
-
"data-testid": process.env.NODE_ENV === "test" ? "combobox-value-".concat(item) : void 0,
|
|
627
|
-
children: item
|
|
675
|
+
const onItemRemove = React.useCallback(
|
|
676
|
+
(item) => {
|
|
677
|
+
setValue((prevValue) => prevValue == null ? void 0 : prevValue.filter((value2) => value2 !== item));
|
|
628
678
|
},
|
|
629
|
-
|
|
630
|
-
)
|
|
679
|
+
[setValue]
|
|
680
|
+
);
|
|
681
|
+
const getItemText = React.useCallback(
|
|
682
|
+
(itemValue) => {
|
|
683
|
+
const textValue = itemValueTextMap.get(itemValue);
|
|
684
|
+
if (textValue === void 0 || textValue === "") {
|
|
685
|
+
return null;
|
|
686
|
+
}
|
|
687
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
688
|
+
Chip,
|
|
689
|
+
{
|
|
690
|
+
onRemove: (e) => {
|
|
691
|
+
onItemRemove(itemValue);
|
|
692
|
+
e.stopPropagation();
|
|
693
|
+
},
|
|
694
|
+
disabled: isDisabled,
|
|
695
|
+
removeAriaLabel: "".concat(unselectAriaLabel, " ").concat(textValue),
|
|
696
|
+
"data-testid": process.env.NODE_ENV === "test" ? "combobox-value-".concat(itemValue) : void 0,
|
|
697
|
+
children: textValue
|
|
698
|
+
},
|
|
699
|
+
itemValue
|
|
700
|
+
);
|
|
701
|
+
},
|
|
702
|
+
[isDisabled, itemValueTextMap, onItemRemove, unselectAriaLabel]
|
|
703
|
+
);
|
|
704
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: value.map(getItemText) });
|
|
631
705
|
};
|
|
632
706
|
|
|
633
707
|
const StyledSeparator = designSystemStitches.styled(designSystemPrimitive.Primitive.div, {
|
|
@@ -645,53 +719,71 @@ const Separator = React__default["default"].forwardRef((props, forwardRef) => {
|
|
|
645
719
|
return /* @__PURE__ */ jsxRuntime.jsx(StyledSeparator, { ...props, ref: forwardRef, "aria-hidden": true });
|
|
646
720
|
});
|
|
647
721
|
|
|
648
|
-
const
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
722
|
+
const StyledNativeSelect = designSystemStitches.styled(designSystemPrimitive.Primitive.select, {
|
|
723
|
+
// if we support autoComplete, we would have to use visually-hidden styles here
|
|
724
|
+
display: "none"
|
|
725
|
+
});
|
|
726
|
+
const StyledComboboxContent = designSystemStitches.styled(designSystemPrimitive.Primitive.div, {
|
|
727
|
+
position: "relative",
|
|
728
|
+
width: "100%"
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
const Root = React__default["default"].forwardRef(
|
|
732
|
+
({ value: valueProp, onValueChange, name, children, ...restProps }, forwardRef) => {
|
|
733
|
+
var _a;
|
|
734
|
+
const {
|
|
735
|
+
openState,
|
|
736
|
+
setOpenState,
|
|
737
|
+
defaultValue,
|
|
738
|
+
value = [],
|
|
739
|
+
setValue,
|
|
740
|
+
required,
|
|
741
|
+
readOnly,
|
|
742
|
+
"aria-disabled": ariaDisabled,
|
|
743
|
+
disabled,
|
|
744
|
+
direction,
|
|
745
|
+
size,
|
|
746
|
+
placeholder,
|
|
747
|
+
triggerRef
|
|
748
|
+
} = useComboboxContext();
|
|
749
|
+
const {
|
|
750
|
+
setRequired,
|
|
751
|
+
setDisabled,
|
|
752
|
+
setAriaDisabled,
|
|
753
|
+
setReadOnly,
|
|
754
|
+
label,
|
|
755
|
+
isFloatingLabel,
|
|
756
|
+
focused,
|
|
757
|
+
formElementRef
|
|
758
|
+
} = designSystemBaseForm.useFormFieldContext();
|
|
759
|
+
React.useEffect(() => {
|
|
760
|
+
setRequired == null ? void 0 : setRequired(required);
|
|
761
|
+
setDisabled == null ? void 0 : setDisabled(disabled);
|
|
762
|
+
setAriaDisabled == null ? void 0 : setAriaDisabled(ariaDisabled);
|
|
763
|
+
setReadOnly == null ? void 0 : setReadOnly(readOnly);
|
|
764
|
+
}, [
|
|
765
|
+
readOnly,
|
|
766
|
+
disabled,
|
|
767
|
+
ariaDisabled,
|
|
768
|
+
required,
|
|
769
|
+
setRequired,
|
|
770
|
+
setDisabled,
|
|
771
|
+
setAriaDisabled,
|
|
772
|
+
setReadOnly
|
|
773
|
+
]);
|
|
774
|
+
const shouldUseFloatingLabel = label !== null && isFloatingLabel;
|
|
775
|
+
const isFloating = placeholder !== void 0 || value.length !== 0 || focused;
|
|
776
|
+
const onSetSelectedValue = (newValue) => {
|
|
777
|
+
setValue(typeof newValue === "string" ? [newValue] : newValue);
|
|
778
|
+
};
|
|
779
|
+
const onOpenChange = (value2) => {
|
|
780
|
+
if (!designSystemUtils.booleanify(readOnly)) {
|
|
781
|
+
setOpenState(value2);
|
|
782
|
+
}
|
|
783
|
+
};
|
|
784
|
+
const isFormControl = Boolean((_a = triggerRef.current) == null ? void 0 : _a.closest("form"));
|
|
785
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RadixPopover__namespace.Root, { open: openState, onOpenChange, children: [
|
|
786
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
695
787
|
react.ComboboxProvider,
|
|
696
788
|
{
|
|
697
789
|
open: openState,
|
|
@@ -699,51 +791,86 @@ const Root = ({
|
|
|
699
791
|
defaultSelectedValue: defaultValue,
|
|
700
792
|
selectedValue: value,
|
|
701
793
|
setSelectedValue: onSetSelectedValue,
|
|
702
|
-
children
|
|
794
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
795
|
+
StyledComboboxContent,
|
|
796
|
+
{
|
|
797
|
+
ref: forwardRef,
|
|
798
|
+
...restProps,
|
|
799
|
+
dir: direction,
|
|
800
|
+
"data-form-element": "select",
|
|
801
|
+
children: [
|
|
802
|
+
shouldUseFloatingLabel && /* @__PURE__ */ jsxRuntime.jsx(designSystemBaseForm.FloatingLabel, { floating: isFloating, size, children: label }),
|
|
803
|
+
children
|
|
804
|
+
]
|
|
805
|
+
}
|
|
806
|
+
)
|
|
807
|
+
}
|
|
808
|
+
),
|
|
809
|
+
isFormControl && /* @__PURE__ */ jsxRuntime.jsx(
|
|
810
|
+
StyledNativeSelect,
|
|
811
|
+
{
|
|
812
|
+
multiple: true,
|
|
813
|
+
autoComplete: "off",
|
|
814
|
+
name,
|
|
815
|
+
tabIndex: -1,
|
|
816
|
+
"aria-hidden": "true",
|
|
817
|
+
ref: formElementRef,
|
|
818
|
+
required,
|
|
819
|
+
disabled,
|
|
820
|
+
"aria-disabled": ariaDisabled,
|
|
821
|
+
value,
|
|
822
|
+
onChange: () => {
|
|
823
|
+
},
|
|
824
|
+
children: value.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("option", { value: "" }) : (
|
|
825
|
+
// since we don't support autoComplete we can render here only selected values
|
|
826
|
+
value.map((itemValue) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: itemValue, children: itemValue }, itemValue))
|
|
827
|
+
)
|
|
703
828
|
}
|
|
704
829
|
)
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
const Combobox = (
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
valid,
|
|
713
|
-
disabled,
|
|
714
|
-
readOnly,
|
|
715
|
-
required,
|
|
716
|
-
value,
|
|
717
|
-
defaultValue,
|
|
718
|
-
onOpen,
|
|
719
|
-
onClose,
|
|
720
|
-
onSearchValueChange,
|
|
721
|
-
onValueChange,
|
|
722
|
-
direction = "ltr",
|
|
723
|
-
autoFilter = true,
|
|
724
|
-
noResultsText,
|
|
725
|
-
...restProps
|
|
726
|
-
}) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
727
|
-
ComboboxProvider,
|
|
728
|
-
{
|
|
729
|
-
defaultValue,
|
|
730
|
-
value,
|
|
731
|
-
onValueChange,
|
|
732
|
-
onSearchValueChange,
|
|
733
|
-
defaultOpen,
|
|
830
|
+
] });
|
|
831
|
+
}
|
|
832
|
+
);
|
|
833
|
+
const Combobox = React__default["default"].forwardRef(
|
|
834
|
+
({
|
|
835
|
+
"aria-disabled": ariaDisabled,
|
|
836
|
+
defaultOpen = false,
|
|
734
837
|
open,
|
|
735
|
-
onOpen,
|
|
736
|
-
onClose,
|
|
737
838
|
valid,
|
|
738
|
-
required,
|
|
739
839
|
disabled,
|
|
740
840
|
readOnly,
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
841
|
+
required,
|
|
842
|
+
value,
|
|
843
|
+
defaultValue,
|
|
844
|
+
onOpen,
|
|
845
|
+
onClose,
|
|
846
|
+
onSearchValueChange,
|
|
847
|
+
onValueChange,
|
|
848
|
+
direction = "ltr",
|
|
849
|
+
autoFilter = true,
|
|
744
850
|
noResultsText,
|
|
745
|
-
|
|
746
|
-
}
|
|
851
|
+
...restProps
|
|
852
|
+
}, forwardRef) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
853
|
+
ComboboxProvider,
|
|
854
|
+
{
|
|
855
|
+
defaultValue,
|
|
856
|
+
value,
|
|
857
|
+
onValueChange,
|
|
858
|
+
onSearchValueChange,
|
|
859
|
+
defaultOpen,
|
|
860
|
+
open,
|
|
861
|
+
onOpen,
|
|
862
|
+
onClose,
|
|
863
|
+
valid,
|
|
864
|
+
required,
|
|
865
|
+
disabled,
|
|
866
|
+
readOnly,
|
|
867
|
+
"aria-disabled": ariaDisabled,
|
|
868
|
+
direction,
|
|
869
|
+
autoFilter,
|
|
870
|
+
noResultsText,
|
|
871
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(Root, { ...restProps, value, ref: forwardRef })
|
|
872
|
+
}
|
|
873
|
+
)
|
|
747
874
|
);
|
|
748
875
|
Combobox.Portal = Portal;
|
|
749
876
|
Combobox.Trigger = Trigger;
|