@economic/taco 2.44.1 → 2.44.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -14391,7 +14391,6 @@ const Root = /*#__PURE__*/React__default.forwardRef(function CollectionRoot(prop
14391
14391
  } = props;
14392
14392
  const internalRef = useMergedRef(ref);
14393
14393
  const [activeIndex, setActiveIndex] = React__default.useState();
14394
- const lastLengthRef = React__default.useRef(0);
14395
14394
  const setActiveOption = (index, collection, option) => {
14396
14395
  var _collection$querySele;
14397
14396
  (_collection$querySele = collection.querySelector(`[aria-current]`)) === null || _collection$querySele === void 0 ? void 0 : _collection$querySele.removeAttribute('aria-current');
@@ -14414,13 +14413,13 @@ const Root = /*#__PURE__*/React__default.forwardRef(function CollectionRoot(prop
14414
14413
  }, [internalRef.current, querySelector]);
14415
14414
  React__default.useEffect(() => {
14416
14415
  if (internalRef.current) {
14417
- internalRef.current.setActiveIndex = setActiveIndexByElement;
14416
+ internalRef.current.setActiveIndexByElement = setActiveIndexByElement;
14418
14417
  }
14419
14418
  }, [internalRef.current]);
14420
14419
  React__default.useEffect(() => {
14421
14420
  if (internalRef.current) {
14422
14421
  const options = getOptionsFromCollection(internalRef.current, querySelector);
14423
- if (options.length && options.length !== lastLengthRef.current) {
14422
+ if (options.length) {
14424
14423
  let selected = internalRef.current.querySelectorAll(`[aria-current="true"]`);
14425
14424
  if (selected.length === 0) {
14426
14425
  selected = internalRef.current.querySelectorAll(`[aria-selected]`);
@@ -14438,7 +14437,6 @@ const Root = /*#__PURE__*/React__default.forwardRef(function CollectionRoot(prop
14438
14437
  setActiveOption(0, internalRef.current, options.item(0));
14439
14438
  }
14440
14439
  }
14441
- lastLengthRef.current = options.length;
14442
14440
  }
14443
14441
  }, [props.children]);
14444
14442
  const handleClick = event => {
@@ -14643,6 +14641,7 @@ const Option = /*#__PURE__*/React__default.forwardRef(function Listbox2Option(pr
14643
14641
  return /*#__PURE__*/React__default.createElement("div", Object.assign({}, otherProps, {
14644
14642
  "aria-disabled": listboxDisabled || disabled ? 'true' : undefined,
14645
14643
  "aria-selected": selected ? 'true' : undefined,
14644
+ key: `${value}_${String(selected)}`,
14646
14645
  id: id,
14647
14646
  onClick: handleClick,
14648
14647
  onKeyDown: handleKeyDown,
@@ -14736,6 +14735,16 @@ const getFontSize = fontSize => {
14736
14735
  return 'text-sm';
14737
14736
  }
14738
14737
  };
14738
+ const filterOption = (child, searchQuery) => {
14739
+ var _child$props$textValu, _child$props$descript;
14740
+ if ((_child$props$textValu = child.props.textValue) !== null && _child$props$textValu !== void 0 && _child$props$textValu.toLowerCase().includes(searchQuery.toLowerCase())) {
14741
+ return true;
14742
+ }
14743
+ if ((_child$props$descript = child.props.description) !== null && _child$props$descript !== void 0 && _child$props$descript.toLowerCase().includes(searchQuery.toLowerCase())) {
14744
+ return true;
14745
+ }
14746
+ return String(child.props.children).toLowerCase().includes(searchQuery.toLowerCase());
14747
+ };
14739
14748
 
14740
14749
  const Select2Context = /*#__PURE__*/React__default.createContext({});
14741
14750
  const useSelect2Context = () => React__default.useContext(Select2Context);
@@ -15008,7 +15017,7 @@ const Option$1 = /*#__PURE__*/React__default.forwardRef(function Select2Option(p
15008
15017
  onClick: event => {
15009
15018
  var _listboxRef$current;
15010
15019
  event.stopPropagation();
15011
- listboxRef === null || listboxRef === void 0 ? void 0 : (_listboxRef$current = listboxRef.current) === null || _listboxRef$current === void 0 ? void 0 : _listboxRef$current.setActiveIndex(event.currentTarget.parentElement);
15020
+ listboxRef === null || listboxRef === void 0 ? void 0 : (_listboxRef$current = listboxRef.current) === null || _listboxRef$current === void 0 ? void 0 : _listboxRef$current.setActiveIndexByElement(event.currentTarget.parentElement);
15012
15021
  },
15013
15022
  popover: popover,
15014
15023
  tabIndex: -1
@@ -15423,7 +15432,7 @@ const Search$2 = /*#__PURE__*/React__default.forwardRef(function ListboxSearch(p
15423
15432
  }
15424
15433
  };
15425
15434
  return /*#__PURE__*/React__default.createElement(Field, {
15426
- className: cn('mx-1.5 mb-1.5 !min-h-fit ', {
15435
+ className: cn('mx-1.5 mb-1.5 !min-h-fit', {
15427
15436
  '!pb-0': !validationError
15428
15437
  }),
15429
15438
  invalid: !!validationError,
@@ -15489,16 +15498,6 @@ const useChildren = ({
15489
15498
  setSearchQuery
15490
15499
  };
15491
15500
  };
15492
- const filterOption = (child, searchQuery) => {
15493
- var _child$props$textValu, _child$props$descript;
15494
- if ((_child$props$textValu = child.props.textValue) !== null && _child$props$textValu !== void 0 && _child$props$textValu.toLowerCase().includes(searchQuery.toLowerCase())) {
15495
- return true;
15496
- }
15497
- if ((_child$props$descript = child.props.description) !== null && _child$props$descript !== void 0 && _child$props$descript.toLowerCase().includes(searchQuery.toLowerCase())) {
15498
- return true;
15499
- }
15500
- return String(child.props.children).toLowerCase().includes(searchQuery.toLowerCase());
15501
- };
15502
15501
 
15503
15502
  const getNextColor = options => {
15504
15503
  let occurrences = {};
@@ -15714,6 +15713,26 @@ const Select2 = /*#__PURE__*/React__default.forwardRef(function Select2(props, r
15714
15713
  createDialog,
15715
15714
  createTriggerText
15716
15715
  };
15716
+ const hasInlineCreation = onCreate && !createDialog;
15717
+ const hasSearch = flattenedChildren.length > 5 || hasInlineCreation;
15718
+ const visibleChildren = searchQuery === '' ? initialChildren : filteredChildren;
15719
+ const selectOptions = searchQuery === '' ? flattenedChildren.map(child => child.props.value) : filteredChildren.map(child => isGroup(child) ? Array.isArray(child.props.children) && child.props.children.map(subChild => subChild.props.value) : child.props.value).flatMap(c => c) || [];
15720
+ // support typeahead functionality when search isn't available
15721
+ const queryTimeoutRef = React__default.useRef('');
15722
+ const typeahead = debounce(function () {
15723
+ if (!queryTimeoutRef.current) {
15724
+ return;
15725
+ }
15726
+ const matchedValueIndex = visibleChildren.findIndex(child => filterOption(child, queryTimeoutRef.current));
15727
+ if (matchedValueIndex > -1) {
15728
+ setValue(selectOptions[matchedValueIndex]);
15729
+ }
15730
+ queryTimeoutRef.current = '';
15731
+ }, 200);
15732
+ const setValueIfMatched = query => {
15733
+ queryTimeoutRef.current = queryTimeoutRef.current + query;
15734
+ typeahead();
15735
+ };
15717
15736
  const handleKeyDown = event => {
15718
15737
  var _listboxRef$current;
15719
15738
  if (open) {
@@ -15722,6 +15741,9 @@ const Select2 = /*#__PURE__*/React__default.forwardRef(function Select2(props, r
15722
15741
  return;
15723
15742
  } else if (!event.ctrlKey && !event.metaKey && (event.key === 'ArrowDown' || /^[a-z0-9]$/i.test(event.key))) {
15724
15743
  setOpen(true);
15744
+ if (!hasSearch) {
15745
+ setValueIfMatched(event.key);
15746
+ }
15725
15747
  }
15726
15748
  // the focus should always remain on the input, so we forward events on to the listbox
15727
15749
  (_listboxRef$current = listboxRef.current) === null || _listboxRef$current === void 0 ? void 0 : _listboxRef$current.dispatchEvent(createCustomKeyboardEvent(event));
@@ -15748,6 +15770,9 @@ const Select2 = /*#__PURE__*/React__default.forwardRef(function Select2(props, r
15748
15770
  if (isAriaDirectionKey(event)) {
15749
15771
  setShouldPauseHoverState(true);
15750
15772
  }
15773
+ if (!hasSearch && /^[a-z0-9]$/i.test(event.key)) {
15774
+ setValueIfMatched(event.key);
15775
+ }
15751
15776
  };
15752
15777
  const handleCloseAutoFocus = event => {
15753
15778
  event.preventDefault();
@@ -15765,7 +15790,6 @@ const Select2 = /*#__PURE__*/React__default.forwardRef(function Select2(props, r
15765
15790
  (_internalRef$current = internalRef.current) === null || _internalRef$current === void 0 ? void 0 : _internalRef$current.focus();
15766
15791
  }
15767
15792
  };
15768
- const selectOptions = searchQuery === '' ? flattenedChildren.map(child => child.props.value) : filteredChildren.map(child => isGroup(child) ? Array.isArray(child.props.children) && child.props.children.map(subChild => subChild.props.value) : child.props.value).flatMap(c => c) || [];
15769
15793
  const areAllSelected = Array.isArray(value) && selectOptions.every(option => value.includes(option));
15770
15794
  const selectAllText = React__default.useMemo(() => {
15771
15795
  if (searchQuery === '') {
@@ -15797,8 +15821,6 @@ const Select2 = /*#__PURE__*/React__default.forwardRef(function Select2(props, r
15797
15821
  setValue(nextValue);
15798
15822
  }
15799
15823
  };
15800
- const hasInlineCreation = onCreate && !createDialog;
15801
- const hasSearch = flattenedChildren.length > 5 || hasInlineCreation;
15802
15824
  const className = cn('border-grey-300 rounded border bg-white py-1.5 shadow-md ', {
15803
15825
  'focus-within:yt-focus': !hasSearch,
15804
15826
  'outline-none': hasSearch
@@ -15865,7 +15887,7 @@ const Select2 = /*#__PURE__*/React__default.forwardRef(function Select2(props, r
15865
15887
  ref: listboxRef,
15866
15888
  setValue: setValue,
15867
15889
  value: value
15868
- }, searchQuery === '' ? (/*#__PURE__*/React__default.createElement(Collection$1, null, initialChildren)) : (/*#__PURE__*/React__default.createElement(Collection$1, null, filteredChildren)), onCreate ? /*#__PURE__*/React__default.createElement(Create, {
15890
+ }, /*#__PURE__*/React__default.createElement(Collection$1, null, visibleChildren), onCreate ? /*#__PURE__*/React__default.createElement(Create, {
15869
15891
  onCreate: onCreate,
15870
15892
  options: flattenedChildren
15871
15893
  }) : null))))), /*#__PURE__*/React__default.createElement(ControlledHiddenField, {