@mirohq/design-system-combobox 1.6.0 → 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
@@ -390,6 +390,12 @@ const StyledContent = designSystemStitches.styled(RadixPopover__namespace.Conten
390
390
  boxSizing: "border-box"
391
391
  });
392
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
+
393
399
  const useDocumentFragment = () => {
394
400
  const [fragment, setFragment] = React.useState();
395
401
  designSystemUseLayoutEffect.useLayoutEffect(() => {
@@ -412,6 +418,11 @@ const isInsideRef = (element, ref) => {
412
418
  var _a, _b;
413
419
  return (_b = element != null && ((_a = ref.current) == null ? void 0 : _a.contains(element))) != null ? _b : false;
414
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);
415
426
  const Content = React.forwardRef(
416
427
  ({
417
428
  side = "bottom",
@@ -434,7 +445,22 @@ const Content = React.forwardRef(
434
445
  if (!openState) {
435
446
  return getInvisibleContent(children);
436
447
  }
437
- 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
+ }
438
464
  return /* @__PURE__ */ jsxRuntime.jsx(
439
465
  StyledContent,
440
466
  {
@@ -449,6 +475,7 @@ const Content = React.forwardRef(
449
475
  sticky,
450
476
  hideWhenDetached,
451
477
  onOpenAutoFocus: (event) => {
478
+ var _a;
452
479
  if (onOpenAutoFocus != null) {
453
480
  onOpenAutoFocus(event);
454
481
  return;
@@ -456,6 +483,13 @@ const Content = React.forwardRef(
456
483
  event == null ? void 0 : event.preventDefault();
457
484
  if (externalOpenedRef.current !== true) return;
458
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
+ }
459
493
  baseElement == null ? void 0 : baseElement.focus();
460
494
  },
461
495
  ref: designSystemUtils.mergeRefs([forwardRef, contentRef]),
@@ -467,18 +501,7 @@ const Content = React.forwardRef(
467
501
  event.preventDefault();
468
502
  }
469
503
  },
470
- children: /* @__PURE__ */ jsxRuntime.jsx(react.ComboboxList, { role: "listbox", children: overflow === "auto" ? /* @__PURE__ */ jsxRuntime.jsxs(designSystemScrollArea.ScrollArea, { type: "always", dir: direction, children: [
471
- /* @__PURE__ */ jsxRuntime.jsx(
472
- designSystemScrollArea.ScrollArea.Viewport,
473
- {
474
- css: {
475
- maxHeight: maxHeight !== void 0 ? "min(".concat(RADIX_CONTENT_AVAILABLE_HEIGHT, ", ").concat(typeof maxHeight === "number" ? "".concat(maxHeight, "px") : maxHeight, ")") : RADIX_CONTENT_AVAILABLE_HEIGHT
476
- },
477
- children: content
478
- }
479
- ),
480
- /* @__PURE__ */ jsxRuntime.jsx(designSystemScrollArea.ScrollArea.Scrollbar, { orientation: "vertical", children: /* @__PURE__ */ jsxRuntime.jsx(designSystemScrollArea.ScrollArea.Thumb, {}) })
481
- ] }) : content })
504
+ children: content
482
505
  }
483
506
  );
484
507
  }
@@ -610,8 +633,7 @@ const GroupLabel = React.forwardRef((props, forwardRef) => /* @__PURE__ */ jsxRu
610
633
 
611
634
  const Value = ({
612
635
  unselectAriaLabel,
613
- multiple = true,
614
- items
636
+ multiple = true
615
637
  }) => {
616
638
  const {
617
639
  value = [],
@@ -637,9 +659,8 @@ const Value = ({
637
659
  );
638
660
  const getItemText = React.useCallback(
639
661
  (itemValue) => {
640
- var _a, _b;
641
- const displayedText = (_b = items == null ? void 0 : items.get(itemValue)) != null ? _b : (_a = itemsMap.get(itemValue)) == null ? void 0 : _a.displayedText;
642
- if (displayedText === void 0 || displayedText === "") {
662
+ const itemData = itemsMap.get(itemValue);
663
+ if (itemData === void 0 || itemData.displayedText === "") {
643
664
  return null;
644
665
  }
645
666
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -651,21 +672,14 @@ const Value = ({
651
672
  e.stopPropagation();
652
673
  },
653
674
  removable: canRemoveItem,
654
- removeAriaLabel: "".concat(unselectAriaLabel, " ").concat(displayedText),
675
+ removeAriaLabel: "".concat(unselectAriaLabel, " ").concat(itemData.displayedText),
655
676
  "data-testid": process.env.NODE_ENV === "test" ? "combobox-value-".concat(itemValue) : void 0,
656
- children: displayedText
677
+ children: itemData.displayedText
657
678
  },
658
679
  itemValue
659
680
  );
660
681
  },
661
- [
662
- canRemoveItem,
663
- isDisabled,
664
- items,
665
- itemsMap,
666
- onItemRemove,
667
- unselectAriaLabel
668
- ]
682
+ [canRemoveItem, isDisabled, itemsMap, onItemRemove, unselectAriaLabel]
669
683
  );
670
684
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: multiple && Array.isArray(value) ? value.map(getItemText) : getItemText(value) });
671
685
  };
@@ -707,39 +721,71 @@ const StyledInputSearch = designSystemStitches.styled(designSystemInput.InputSea
707
721
  "&&": {
708
722
  border: "1px solid $border-neutrals",
709
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
+ }
710
752
  }
711
753
  });
712
- const SearchInput = React.forwardRef((props, ref) => {
713
- const { setSearchValue, contentRef } = useComboboxContext();
714
- const handleSearchChange = React.useCallback(
715
- (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) => {
716
765
  var _a;
717
- setSearchValue(event.target.value);
718
- (_a = props.onChange) == null ? void 0 : _a.call(props, event);
719
- },
720
- [props, setSearchValue]
721
- );
722
- const handleKeyDown = (event) => {
723
- var _a, _b;
724
- if (event.key === "ArrowDown") {
725
- event.preventDefault();
726
- const firstItem = (_a = contentRef.current) == null ? void 0 : _a.querySelector(
727
- '[role="option"]:not([aria-disabled="true"])'
728
- );
729
- firstItem == null ? void 0 : firstItem.focus();
730
- }
731
- (_b = props.onKeyDown) == null ? void 0 : _b.call(props, event);
732
- };
733
- return /* @__PURE__ */ jsxRuntime.jsx(
734
- StyledInputSearch,
735
- {
736
- ...props,
737
- ref,
738
- onKeyDown: handleKeyDown,
739
- onChange: handleSearchChange
740
- }
741
- );
742
- });
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";
743
789
 
744
790
  const StyledCompositeItem = designSystemStitches.styled(react.CompositeItem, {
745
791
  ...designSystemBaseSelect.itemStyles,
@@ -749,7 +795,7 @@ const StyledCompositeItem = designSystemStitches.styled(react.CompositeItem, {
749
795
 
750
796
  const CompositeItem = ({
751
797
  asChild = true,
752
- role = "menuitem",
798
+ role,
753
799
  textValue,
754
800
  disabled = false,
755
801
  tabbable,
@@ -968,6 +1014,7 @@ Combobox.Portal = Portal;
968
1014
  Combobox.Trigger = Trigger;
969
1015
  Combobox.Input = Input;
970
1016
  Combobox.Content = Content;
1017
+ Combobox.List = List;
971
1018
  Combobox.Item = Item;
972
1019
  Combobox.CompositeItem = CompositeItem;
973
1020
  Combobox.Group = Group;