@mirohq/design-system-combobox 1.6.1-reactdismissablelayer.1 → 1.7.0-filter-chip.1

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 CHANGED
@@ -70,7 +70,7 @@ const ComboboxProvider = ({
70
70
  prop: openProp,
71
71
  defaultProp: defaultOpen,
72
72
  onChange: (state) => {
73
- if (state === true) {
73
+ if (state) {
74
74
  externalOpenedRef.current = true;
75
75
  onOpen == null ? void 0 : onOpen();
76
76
  } else {
@@ -79,25 +79,15 @@ const ComboboxProvider = ({
79
79
  }
80
80
  }
81
81
  });
82
- const [value, setValue] = reactUseControllableState.useControllableState(
83
- {
84
- prop: valueProp,
85
- defaultProp: defaultValueProp,
86
- // Only the initial state can be undefined — nothing selects "no value" —
87
- // so the public handler never has to widen its parameter.
88
- onChange: (state) => {
89
- if (state !== void 0) {
90
- onValueChange == null ? void 0 : onValueChange(state);
91
- }
92
- }
93
- }
94
- );
82
+ const [value, setValue] = reactUseControllableState.useControllableState({
83
+ prop: valueProp,
84
+ defaultProp: defaultValueProp,
85
+ onChange: onValueChange
86
+ });
95
87
  const [searchValue = "", setSearchValue] = reactUseControllableState.useControllableState({
96
88
  prop: searchValueProp,
97
89
  defaultProp: "",
98
- // Clearing through the setter reads as undefined, which the search is
99
- // free to treat as empty — so the public handler stays on plain strings.
100
- onChange: (state) => onSearchValueChange == null ? void 0 : onSearchValueChange(state != null ? state : "")
90
+ onChange: onSearchValueChange
101
91
  });
102
92
  const [size, setSize] = React.useState();
103
93
  const [placeholder, setPlaceholder] = React.useState();
@@ -400,6 +390,12 @@ const StyledContent = designSystemStitches.styled(RadixPopover__namespace.Conten
400
390
  boxSizing: "border-box"
401
391
  });
402
392
 
393
+ const List = ({ children }) => (
394
+ // Role must be set explicitly; Radix Content can overwrite Ariakit's default.
395
+ /* @__PURE__ */ jsxRuntime.jsx(react.ComboboxList, { role: "listbox", children: /* @__PURE__ */ jsxRuntime.jsx(StyledItemsContainer, { children }) })
396
+ );
397
+ List.displayName = "Combobox.List";
398
+
403
399
  const useDocumentFragment = () => {
404
400
  const [fragment, setFragment] = React.useState();
405
401
  designSystemUseLayoutEffect.useLayoutEffect(() => {
@@ -422,6 +418,11 @@ const isInsideRef = (element, ref) => {
422
418
  var _a, _b;
423
419
  return (_b = element != null && ((_a = ref.current) == null ? void 0 : _a.contains(element))) != null ? _b : false;
424
420
  };
421
+ const isComboboxList = (child) => {
422
+ var _a;
423
+ return React.isValidElement(child) && ((_a = child.type) == null ? void 0 : _a.displayName) === "Combobox.List";
424
+ };
425
+ const hasComboboxList = (children) => React.Children.toArray(children).some(isComboboxList);
425
426
  const Content = React.forwardRef(
426
427
  ({
427
428
  side = "bottom",
@@ -431,7 +432,7 @@ const Content = React.forwardRef(
431
432
  collisionPadding = 0,
432
433
  avoidCollisions = true,
433
434
  sticky = "partial",
434
- hideWhenDetached = process.env.NODE_ENV !== "test",
435
+ hideWhenDetached = true,
435
436
  overflow = "visible",
436
437
  maxHeight,
437
438
  children,
@@ -444,7 +445,22 @@ const Content = React.forwardRef(
444
445
  if (!openState) {
445
446
  return getInvisibleContent(children);
446
447
  }
447
- const content = /* @__PURE__ */ jsxRuntime.jsx(StyledItemsContainer, { children });
448
+ const listContent = hasComboboxList(children) ? children : /* @__PURE__ */ jsxRuntime.jsx(List, { children });
449
+ let content = listContent;
450
+ if (overflow === "auto") {
451
+ content = /* @__PURE__ */ jsxRuntime.jsxs(designSystemScrollArea.ScrollArea, { type: "always", dir: direction, children: [
452
+ /* @__PURE__ */ jsxRuntime.jsx(
453
+ designSystemScrollArea.ScrollArea.Viewport,
454
+ {
455
+ css: {
456
+ maxHeight: maxHeight !== void 0 ? "min(".concat(RADIX_CONTENT_AVAILABLE_HEIGHT, ", ").concat(typeof maxHeight === "number" ? "".concat(maxHeight, "px") : maxHeight, ")") : RADIX_CONTENT_AVAILABLE_HEIGHT
457
+ },
458
+ children: listContent
459
+ }
460
+ ),
461
+ /* @__PURE__ */ jsxRuntime.jsx(designSystemScrollArea.ScrollArea.Scrollbar, { orientation: "vertical", children: /* @__PURE__ */ jsxRuntime.jsx(designSystemScrollArea.ScrollArea.Thumb, {}) })
462
+ ] });
463
+ }
448
464
  return /* @__PURE__ */ jsxRuntime.jsx(
449
465
  StyledContent,
450
466
  {
@@ -459,6 +475,7 @@ const Content = React.forwardRef(
459
475
  sticky,
460
476
  hideWhenDetached,
461
477
  onOpenAutoFocus: (event) => {
478
+ var _a;
462
479
  if (onOpenAutoFocus != null) {
463
480
  onOpenAutoFocus(event);
464
481
  return;
@@ -466,6 +483,13 @@ const Content = React.forwardRef(
466
483
  event == null ? void 0 : event.preventDefault();
467
484
  if (externalOpenedRef.current !== true) return;
468
485
  const baseElement = ariakitStore == null ? void 0 : ariakitStore.getState().baseElement;
486
+ if (!(baseElement instanceof HTMLInputElement)) {
487
+ const searchInput = (_a = contentRef.current) == null ? void 0 : _a.querySelector("input");
488
+ if (searchInput != null) {
489
+ searchInput.focus();
490
+ return;
491
+ }
492
+ }
469
493
  baseElement == null ? void 0 : baseElement.focus();
470
494
  },
471
495
  ref: designSystemUtils.mergeRefs([forwardRef, contentRef]),
@@ -477,18 +501,7 @@ const Content = React.forwardRef(
477
501
  event.preventDefault();
478
502
  }
479
503
  },
480
- children: /* @__PURE__ */ jsxRuntime.jsx(react.ComboboxList, { role: "listbox", children: overflow === "auto" ? /* @__PURE__ */ jsxRuntime.jsxs(designSystemScrollArea.ScrollArea, { type: "always", dir: direction, children: [
481
- /* @__PURE__ */ jsxRuntime.jsx(
482
- designSystemScrollArea.ScrollArea.Viewport,
483
- {
484
- css: {
485
- maxHeight: maxHeight !== void 0 ? "min(".concat(RADIX_CONTENT_AVAILABLE_HEIGHT, ", ").concat(typeof maxHeight === "number" ? "".concat(maxHeight, "px") : maxHeight, ")") : RADIX_CONTENT_AVAILABLE_HEIGHT
486
- },
487
- children: content
488
- }
489
- ),
490
- /* @__PURE__ */ jsxRuntime.jsx(designSystemScrollArea.ScrollArea.Scrollbar, { orientation: "vertical", children: /* @__PURE__ */ jsxRuntime.jsx(designSystemScrollArea.ScrollArea.Thumb, {}) })
491
- ] }) : content })
504
+ children: content
492
505
  }
493
506
  );
494
507
  }
@@ -708,39 +721,71 @@ const StyledInputSearch = designSystemStitches.styled(designSystemInput.InputSea
708
721
  "&&": {
709
722
  border: "1px solid $border-neutrals",
710
723
  backgroundColor: "$background-control"
724
+ },
725
+ variants: {
726
+ // Lay selected chips (passed as children, typically `<Combobox.Value />`)
727
+ // out inside the field alongside the text input, matching the multiselect
728
+ // trigger. The leading magnifier is pulled ahead of the chips so the field
729
+ // still reads as a search.
730
+ inlineChips: {
731
+ true: {
732
+ "&&": {
733
+ flexWrap: "wrap",
734
+ height: "auto",
735
+ minHeight: "$10",
736
+ paddingBlock: "$50",
737
+ gap: "$50"
738
+ },
739
+ // The magnifier icon slot (the only direct child that wraps a bare svg)
740
+ // leads the field, before the chips.
741
+ "& > div:has(> svg)": {
742
+ order: -1
743
+ },
744
+ "& input": {
745
+ width: "auto",
746
+ flexGrow: 1,
747
+ flexBasis: "$8",
748
+ minWidth: "$8"
749
+ }
750
+ }
751
+ }
711
752
  }
712
753
  });
713
- const SearchInput = React.forwardRef((props, ref) => {
714
- const { setSearchValue, contentRef } = useComboboxContext();
715
- const handleSearchChange = React.useCallback(
716
- (event) => {
754
+ const SearchInput = React.forwardRef(
755
+ ({ children, onChange, onKeyDown, inlineChips = false, ...rest }, ref) => {
756
+ const { setSearchValue, contentRef } = useComboboxContext();
757
+ const handleSearchChange = React.useCallback(
758
+ (event) => {
759
+ setSearchValue(event.target.value);
760
+ onChange == null ? void 0 : onChange(event);
761
+ },
762
+ [onChange, setSearchValue]
763
+ );
764
+ const handleKeyDown = (event) => {
717
765
  var _a;
718
- setSearchValue(event.target.value);
719
- (_a = props.onChange) == null ? void 0 : _a.call(props, event);
720
- },
721
- [props, setSearchValue]
722
- );
723
- const handleKeyDown = (event) => {
724
- var _a, _b;
725
- if (event.key === "ArrowDown") {
726
- event.preventDefault();
727
- const firstItem = (_a = contentRef.current) == null ? void 0 : _a.querySelector(
728
- '[role="option"]:not([aria-disabled="true"])'
729
- );
730
- firstItem == null ? void 0 : firstItem.focus();
731
- }
732
- (_b = props.onKeyDown) == null ? void 0 : _b.call(props, event);
733
- };
734
- return /* @__PURE__ */ jsxRuntime.jsx(
735
- StyledInputSearch,
736
- {
737
- ...props,
738
- ref,
739
- onKeyDown: handleKeyDown,
740
- onChange: handleSearchChange
741
- }
742
- );
743
- });
766
+ if (event.key === "ArrowDown") {
767
+ event.preventDefault();
768
+ const firstItem = (_a = contentRef.current) == null ? void 0 : _a.querySelector(
769
+ '[role="option"]:not([aria-disabled="true"])'
770
+ );
771
+ firstItem == null ? void 0 : firstItem.focus();
772
+ }
773
+ onKeyDown == null ? void 0 : onKeyDown(event);
774
+ };
775
+ return /* @__PURE__ */ jsxRuntime.jsx(
776
+ StyledInputSearch,
777
+ {
778
+ ...rest,
779
+ ref,
780
+ inlineChips,
781
+ onKeyDown: handleKeyDown,
782
+ onChange: handleSearchChange,
783
+ children
784
+ }
785
+ );
786
+ }
787
+ );
788
+ SearchInput.displayName = "Combobox.SearchInput";
744
789
 
745
790
  const StyledCompositeItem = designSystemStitches.styled(react.CompositeItem, {
746
791
  ...designSystemBaseSelect.itemStyles,
@@ -750,7 +795,7 @@ const StyledCompositeItem = designSystemStitches.styled(react.CompositeItem, {
750
795
 
751
796
  const CompositeItem = ({
752
797
  asChild = true,
753
- role = "menuitem",
798
+ role,
754
799
  textValue,
755
800
  disabled = false,
756
801
  tabbable,
@@ -969,6 +1014,7 @@ Combobox.Portal = Portal;
969
1014
  Combobox.Trigger = Trigger;
970
1015
  Combobox.Input = Input;
971
1016
  Combobox.Content = Content;
1017
+ Combobox.List = List;
972
1018
  Combobox.Item = Item;
973
1019
  Combobox.CompositeItem = CompositeItem;
974
1020
  Combobox.Group = Group;