@ssa-ui-kit/core 2.16.2-canary-1c17e94-20250507 → 2.16.2

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 CHANGED
@@ -17523,7 +17523,6 @@ const TypeaheadContext = /*#__PURE__*/external_react_namespaceObject.createConte
17523
17523
  options: [],
17524
17524
  placeholder: '',
17525
17525
  useFormResult: {},
17526
- error: undefined,
17527
17526
  setValue: () => {
17528
17527
  /* no-op */
17529
17528
  },
@@ -17531,7 +17530,7 @@ const TypeaheadContext = /*#__PURE__*/external_react_namespaceObject.createConte
17531
17530
  /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
17532
17531
  return {};
17533
17532
  },
17534
- onChange: () => {
17533
+ handleChange: () => {
17535
17534
  /* no-op */
17536
17535
  },
17537
17536
  handleClearAll: () => {
@@ -17551,6 +17550,9 @@ const TypeaheadContext = /*#__PURE__*/external_react_namespaceObject.createConte
17551
17550
  },
17552
17551
  handleRemoveSelectedClick: () => () => {
17553
17552
  /* no-op */
17553
+ },
17554
+ handleSelectedClick: () => {
17555
+ /* no-op */
17554
17556
  }
17555
17557
  });
17556
17558
  const useTypeaheadContext = () => external_react_namespaceObject.useContext(TypeaheadContext);
@@ -17558,18 +17560,10 @@ const useTypeaheadContext = () => external_react_namespaceObject.useContext(Type
17558
17560
 
17559
17561
 
17560
17562
 
17561
- const findExactMatch = (input, options) => {
17562
- const normalizedInput = input.toLowerCase();
17563
- return Object.values(options).find(opt => {
17564
- const labelText = (opt.label ?? opt.value).toString().toLowerCase();
17565
- return labelText === normalizedInput;
17566
- });
17567
- };
17568
17563
  const useTypeahead = ({
17569
17564
  name = 'typeahead-input',
17570
17565
  isOpen: isInitOpen,
17571
- selectedItems: providedSelectedItems,
17572
- defaultSelectedItems,
17566
+ selectedItems,
17573
17567
  isDisabled,
17574
17568
  isMultiple,
17575
17569
  children,
@@ -17582,8 +17576,8 @@ const useTypeahead = ({
17582
17576
  error,
17583
17577
  success,
17584
17578
  placeholder,
17585
- filterOptions = true,
17586
- autoSelect = true,
17579
+ register,
17580
+ setValue,
17587
17581
  onChange,
17588
17582
  onClearAll,
17589
17583
  onRemoveSelectedClick,
@@ -17591,250 +17585,271 @@ const useTypeahead = ({
17591
17585
  renderOption
17592
17586
  }) => {
17593
17587
  const inputName = `${name}-text`;
17594
- const defaultForm = (0,external_react_hook_form_namespaceObject.useForm)();
17595
- const form = (0,external_react_hook_form_namespaceObject.useFormContext)() ?? defaultForm;
17596
- const {
17597
- register,
17598
- setValue,
17599
- watch
17600
- } = form;
17601
- const formFieldValue = watch(name);
17602
- const controlledValue = (() => {
17603
- if (providedSelectedItems) {
17604
- return providedSelectedItems;
17605
- }
17606
- // controlledValue should be undefined if defaultSelectedItems is provided
17607
- if (defaultSelectedItems) {
17608
- return;
17588
+ const [isOpen, setIsOpen] = (0,external_react_namespaceObject.useState)(isInitOpen || false);
17589
+ const [selected, setSelected] = (0,external_react_namespaceObject.useState)(selectedItems || []);
17590
+ const [optionsWithKey, setOptionsWithKey] = (0,external_react_namespaceObject.useState)({});
17591
+ const [isEmpty, setIsEmpty] = (0,external_react_namespaceObject.useState)(true);
17592
+ const [isFirstRender, setFirstRender] = (0,external_react_namespaceObject.useState)(true);
17593
+ const [items, setItems] = (0,external_react_namespaceObject.useState)();
17594
+ const [inputValue, setInputValue] = (0,external_react_namespaceObject.useState)('');
17595
+ const [status, setStatus] = (0,external_react_namespaceObject.useState)('basic');
17596
+ const [firstSuggestion, setFirstSuggestion] = (0,external_react_namespaceObject.useState)('');
17597
+ const inputRef = (0,external_react_namespaceObject.useRef)(null);
17598
+ const typeaheadId = (0,external_react_namespaceObject.useId)();
17599
+ const triggerRef = (0,external_react_namespaceObject.useRef)(null);
17600
+ const useFormResult = (0,external_react_hook_form_namespaceObject.useForm)();
17601
+ (0,external_react_namespaceObject.useEffect)(() => {
17602
+ if (!register) {
17603
+ console.warn('Typeahead component must be used within a Form component');
17609
17604
  }
17605
+ }, []);
17606
+ (0,external_react_namespaceObject.useEffect)(() => {
17610
17607
  if (isMultiple) {
17611
- return Array.isArray(formFieldValue) ? formFieldValue : [];
17608
+ setValue?.(name, selected, {
17609
+ shouldDirty: !isFirstRender
17610
+ });
17611
+ setInputValue('');
17612
+ setFirstSuggestion('');
17613
+ } else {
17614
+ setValue?.(name, selected.length ? selected[0] : [], {
17615
+ shouldDirty: !isFirstRender
17616
+ });
17612
17617
  }
17613
- return ['number', 'string'].includes(typeof formFieldValue) ? [formFieldValue] : [];
17614
- })();
17615
- const [isOpen, _setIsOpen] = (0,hooks_namespaceObject.useUncontrolled)({
17616
- defaultValue: isInitOpen,
17617
- finalValue: false
17618
- });
17619
- const [selectedItems, setSelected] = (0,hooks_namespaceObject.useUncontrolled)({
17620
- value: controlledValue,
17621
- defaultValue: defaultSelectedItems,
17622
- finalValue: []
17623
- });
17624
- const [rawInput, setRawInput] = (0,external_react_namespaceObject.useState)(null);
17625
- const {
17626
- ref: inputRef
17627
- } = (0,hooks_namespaceObject.useElementSize)();
17628
- const triggerRef = (0,external_react_namespaceObject.useRef)(null);
17629
- (0,external_react_hook_form_namespaceObject.useController)({
17630
- name,
17631
- rules: validationSchema,
17632
- defaultValue: isMultiple ? selectedItems : selectedItems[0]
17633
- });
17634
- const typeaheadId = (0,external_react_namespaceObject.useId)();
17635
- const optionsWithKey = (0,external_react_namespaceObject.useMemo)(() => {
17636
- const opts = {};
17637
- external_react_default().Children.forEach(children, child => {
17638
- if (/*#__PURE__*/external_react_default().isValidElement(child)) {
17639
- opts[child.props.value] = child.props;
17640
- }
17618
+ handleOnEmptyChange(!selected.length);
17619
+ }, [selected]);
17620
+ (0,external_react_namespaceObject.useEffect)(() => {
17621
+ if (isDisabled && isOpen) {
17622
+ setIsOpen(false);
17623
+ }
17624
+ }, [isDisabled]);
17625
+ (0,external_react_namespaceObject.useEffect)(() => {
17626
+ const status = success ? 'success' : useFormResult.formState.errors[name] ? 'error' : 'basic';
17627
+ setStatus(status);
17628
+ }, [useFormResult.formState.errors[name], success]);
17629
+ (0,external_react_namespaceObject.useEffect)(() => {
17630
+ if (error) {
17631
+ useFormResult.setError(name, error);
17632
+ } else {
17633
+ setStatus('basic');
17634
+ useFormResult.resetField(name);
17635
+ }
17636
+ }, [error]);
17637
+ (0,external_react_namespaceObject.useEffect)(() => {
17638
+ processChildren({
17639
+ selectedLocal: selected
17641
17640
  });
17642
- return opts;
17643
17641
  }, [children]);
17644
- const inputValue = (0,external_react_namespaceObject.useMemo)(() => {
17645
- if (isMultiple) return rawInput ?? '';
17646
- if (rawInput != null) return rawInput;
17647
- return selectedItems.length === 1 ? optionsWithKey[selectedItems[0]]?.label?.toString() || '' : '';
17648
- }, [isMultiple, rawInput, selectedItems, optionsWithKey]);
17649
- const filteredChildren = (0,external_react_namespaceObject.useMemo)(() => {
17650
- // if filtering is disabled, or there's no input, show all
17651
- if (!filterOptions || !inputValue) return external_react_default().Children.toArray(children);
17652
- const needle = inputValue.toLowerCase();
17653
- return external_react_default().Children.toArray(children).filter(child => {
17654
- if (! /*#__PURE__*/external_react_default().isValidElement(child)) return false;
17655
- const {
17656
- label,
17657
- value
17658
- } = child.props;
17659
- const text = (label ?? value)?.toString().toLowerCase() || '';
17660
- return text.includes(needle);
17642
+ (0,external_react_namespaceObject.useEffect)(() => {
17643
+ setSelected(selectedItems || []);
17644
+ if (selectedItems?.length) {
17645
+ if (!isMultiple) {
17646
+ const currentOption = optionsWithKey[selectedItems[0]];
17647
+ const optionText = currentOption && (currentOption.children || currentOption.label || currentOption.value);
17648
+ setInputValue(`${optionText}`);
17649
+ }
17650
+ } else {
17651
+ setInputValue('');
17652
+ setFirstSuggestion('');
17653
+ }
17654
+ processChildren({
17655
+ selectedLocal: selectedItems || []
17661
17656
  });
17662
- }, [children, inputValue]);
17663
- const items = (0,external_react_namespaceObject.useMemo)(() => {
17664
- return filteredChildren.map((child, index) => {
17665
- if (! /*#__PURE__*/external_react_default().isValidElement(child)) return null;
17666
- const isActive = selectedItems.includes(child.props.value);
17657
+ }, [selectedItems]);
17658
+ (0,external_react_namespaceObject.useEffect)(() => {
17659
+ const childrenArray = external_react_default().Children.toArray(children).filter(Boolean);
17660
+ const filteredOptions = [...childrenArray];
17661
+ const childItems = filteredOptions.map((child, index) => {
17667
17662
  const {
17663
+ id,
17668
17664
  value,
17669
17665
  label,
17670
- id,
17671
17666
  isDisabled
17672
17667
  } = child.props;
17668
+ const isActive = selected.includes(child.props.value);
17673
17669
  return /*#__PURE__*/external_react_default().cloneElement(child, {
17674
- ...child.props,
17675
17670
  index,
17671
+ ...child.props,
17676
17672
  isActive,
17677
17673
  isDisabled,
17678
- role: 'option',
17674
+ id,
17679
17675
  'aria-selected': isActive,
17680
17676
  'aria-labelledby': `typeahead-label-${name}`,
17681
- onClick: e => {
17682
- e.preventDefault();
17677
+ role: 'option',
17678
+ onClick: event => {
17679
+ event.preventDefault();
17683
17680
  if (!isDisabled) {
17684
- const shouldClose = !isMultiple;
17685
- handleChange({
17686
- value,
17687
- shouldClose
17688
- });
17681
+ handleChange(child.props.value);
17689
17682
  }
17690
17683
  },
17691
- children: renderOption?.({
17684
+ children: renderOption ? renderOption({
17692
17685
  value: id || value,
17693
- input: inputValue,
17686
+ input: inputValue || '',
17694
17687
  label
17695
- }) ?? child.props.children ?? label ?? value
17688
+ }) : child.props.children || child.props.label || child.props.value
17696
17689
  });
17697
17690
  });
17698
- }, [children, selectedItems, inputValue]);
17699
- const firstSuggestion = (0,external_react_namespaceObject.useMemo)(() => {
17700
- if (!inputValue) return '';
17701
- const needle = inputValue.toLowerCase();
17702
- for (const child of filteredChildren) {
17703
- if (! /*#__PURE__*/external_react_default().isValidElement(child)) continue;
17704
- const labelText = (child.props.label ?? child.props.value).toString();
17705
- if (labelText.toLowerCase().startsWith(needle)) {
17706
- return inputValue + labelText.slice(inputValue.length);
17691
+ setItems(childItems);
17692
+ }, [inputValue, optionsWithKey, selected]);
17693
+ (0,external_react_namespaceObject.useEffect)(() => {
17694
+ if (!isMultiple && Object.keys(optionsWithKey).length) {
17695
+ const foundItem = Object.values(optionsWithKey).find(item => item.label === inputValue);
17696
+ if (!foundItem && selected.length) {
17697
+ setSelected([]);
17698
+ }
17699
+ if (foundItem && !selected.includes(foundItem?.value)) {
17700
+ setSelected([foundItem.value]);
17707
17701
  }
17708
17702
  }
17709
- return '';
17710
- }, [inputValue, filteredChildren]);
17711
- const setIsOpen = open => {
17712
- if (!open) {
17713
- form.trigger(name);
17703
+ }, [optionsWithKey, inputValue]);
17704
+ (0,external_react_namespaceObject.useEffect)(() => {
17705
+ processSingleSelected({
17706
+ optionsWithKeyLocal: optionsWithKey,
17707
+ selectedLocal: selected
17708
+ });
17709
+ }, [selected]);
17710
+ (0,external_react_namespaceObject.useEffect)(() => {
17711
+ if (inputValue) {
17712
+ const newFirstSuggestion = Object.values(optionsWithKey)?.find(item => {
17713
+ const label = (0,utils_namespaceObject.propOr)('', 'label')(item);
17714
+ return label.toLowerCase().startsWith(inputValue.toLowerCase());
17715
+ });
17716
+ const firstSuggestionLabel = (0,utils_namespaceObject.propOr)('', 'label')(newFirstSuggestion);
17717
+ const humanSuggestionLabel = inputValue.concat(firstSuggestionLabel.slice(inputValue.length));
17718
+ setFirstSuggestion(humanSuggestionLabel);
17719
+ } else {
17720
+ setFirstSuggestion('');
17721
+ if (isMultiple) {
17722
+ setInputValue('');
17723
+ }
17724
+ }
17725
+ }, [inputValue, items, selected]);
17726
+ const processSingleSelected = ({
17727
+ optionsWithKeyLocal = {},
17728
+ selectedLocal = []
17729
+ }) => {
17730
+ if (!isMultiple && selectedLocal.length && Object.keys(optionsWithKeyLocal).length) {
17731
+ const currentOption = optionsWithKeyLocal[selectedLocal[0]];
17732
+ const optionText = currentOption && (currentOption.children || currentOption.label || currentOption.value);
17733
+ setInputValue(`${optionText}`);
17714
17734
  }
17715
- _setIsOpen(open);
17716
17735
  };
17717
- const handleChange = ({
17718
- value,
17719
- shouldClose = true,
17720
- resetInput = true
17736
+ const processChildren = ({
17737
+ selectedLocal
17721
17738
  }) => {
17722
- if (isDisabled || value == null) return;
17723
- const alreadySelected = selectedItems.includes(value);
17724
- const updatedSelected = isMultiple ? alreadySelected ? selectedItems.filter(item => item !== value) : [...selectedItems, value] : alreadySelected ? [] : [value];
17725
- const fieldValue = isMultiple ? updatedSelected : updatedSelected[0];
17726
- setSelected(updatedSelected);
17727
- setValue?.(name, fieldValue);
17728
- form.clearErrors(name);
17729
- if (resetInput) {
17730
- const rawInputValue = isMultiple ? null : updatedSelected.length ? String(optionsWithKey[value]?.label) : null;
17731
- setRawInput(rawInputValue);
17739
+ const keyedOptions = {};
17740
+ const childItems = external_react_default().Children.toArray(children).filter(Boolean).map((child, index) => {
17741
+ keyedOptions[child.props.value] = {
17742
+ ...child.props
17743
+ };
17744
+ return /*#__PURE__*/external_react_default().cloneElement(child, {
17745
+ index,
17746
+ ...child.props
17747
+ });
17748
+ });
17749
+ setOptionsWithKey(keyedOptions);
17750
+ setItems(childItems);
17751
+ processSingleSelected({
17752
+ optionsWithKeyLocal: keyedOptions,
17753
+ selectedLocal
17754
+ });
17755
+ setFirstRender(false);
17756
+ };
17757
+ const handleOnEmptyChange = newIsEmptyValue => {
17758
+ if (newIsEmptyValue !== isEmpty) {
17759
+ setIsEmpty(newIsEmptyValue);
17760
+ onEmptyChange?.(newIsEmptyValue);
17732
17761
  }
17733
- if (shouldClose) {
17734
- setIsOpen(false);
17762
+ };
17763
+ const handleOpenChange = open => {
17764
+ if (!isDisabled) {
17765
+ setIsOpen(open);
17735
17766
  }
17736
- onChange?.(value, !alreadySelected);
17737
- onEmptyChange?.(updatedSelected.length === 0);
17738
17767
  };
17739
- const handleClearAll = e => {
17740
- if (isDisabled) return;
17741
- e.preventDefault();
17742
- e.stopPropagation();
17743
- setSelected([]);
17744
- setRawInput(null);
17768
+ const handleChange = changingValue => {
17769
+ if (isDisabled || changingValue === undefined) {
17770
+ return;
17771
+ }
17772
+ const isNewSelected = true;
17773
+ const isChangingItemSelected = selected.includes(changingValue);
17774
+ if (isMultiple) {
17775
+ setSelected(currentSelected => isChangingItemSelected ? currentSelected.filter(current => current !== changingValue) : [...currentSelected, changingValue]);
17776
+ setInputValue('');
17777
+ } else {
17778
+ if (selected[0] === changingValue) {
17779
+ setSelected([]);
17780
+ setInputValue('');
17781
+ } else {
17782
+ setSelected([changingValue]);
17783
+ }
17784
+ }
17745
17785
  setIsOpen(false);
17746
- setValue?.(name, undefined);
17747
- form.trigger(name);
17786
+ setFirstSuggestion('');
17748
17787
  inputRef.current?.focus();
17749
- onClearAll?.();
17750
- onEmptyChange?.(true);
17788
+ setStatus('basic');
17789
+ useFormResult.clearErrors(name);
17790
+ useFormResult.trigger(name);
17791
+ onChange?.(changingValue, isNewSelected);
17751
17792
  };
17752
- const handleInputChange = e => {
17753
- const input = e.target.value;
17754
- setRawInput(input);
17755
- if (!autoSelect || !filterOptions) return;
17756
- const match = findExactMatch(input, optionsWithKey);
17757
- if (match) {
17758
- handleChange({
17759
- value: match.value,
17760
- shouldClose: false
17761
- });
17793
+ const handleClearAll = event => {
17794
+ if (isDisabled) {
17762
17795
  return;
17763
17796
  }
17764
- // unset selected value if not fully matched
17765
- if (!isMultiple && selectedItems.length > 0) {
17766
- handleChange({
17767
- value: selectedItems[0],
17768
- shouldClose: false,
17769
- resetInput: false
17770
- });
17771
- }
17797
+ event.stopPropagation();
17798
+ event.preventDefault();
17799
+ setSelected([]);
17800
+ setInputValue('');
17801
+ setIsOpen(false);
17802
+ setFirstSuggestion('');
17803
+ useFormResult.trigger(name);
17804
+ inputRef.current?.focus();
17805
+ onClearAll?.();
17772
17806
  };
17773
- const handleInputClick = e => {
17774
- e.stopPropagation();
17775
- e.preventDefault();
17807
+ const handleInputClick = event => {
17776
17808
  if (!isDisabled) {
17777
17809
  inputRef.current?.focus();
17778
17810
  setIsOpen(true);
17779
17811
  }
17812
+ event.stopPropagation();
17813
+ event.preventDefault();
17780
17814
  };
17781
- const handleInputKeyDown = e => {
17782
- const isEnterOrTab = ['Enter', 'Tab'].includes(e.code);
17783
- if (isEnterOrTab && firstSuggestion && firstSuggestion !== inputValue) {
17784
- const match = findExactMatch(firstSuggestion, optionsWithKey);
17785
- if (match) {
17786
- handleChange({
17787
- value: match.value
17788
- });
17815
+ const handleInputKeyDown = event => {
17816
+ if (['Space'].includes(event.code) && !firstSuggestion) {
17817
+ setIsOpen(true);
17818
+ inputRef.current?.focus();
17819
+ event.stopPropagation();
17820
+ event.preventDefault();
17821
+ } else if (['Tab', 'Enter'].includes(event.code) && firstSuggestion && firstSuggestion !== inputValue) {
17822
+ const foundItem = Object.values(optionsWithKey).find(item => `${item.label}`.toLowerCase() === firstSuggestion.toLowerCase());
17823
+ handleChange(foundItem?.value);
17824
+ if (foundItem) {
17825
+ setInputValue(`${foundItem?.label}`);
17789
17826
  }
17790
- e.preventDefault();
17791
- return;
17792
- }
17793
- if (isMultiple && e.code === 'Backspace' && selectedItems.length && !inputValue) {
17794
- const lastSelected = selectedItems[selectedItems.length - 1];
17795
- handleChange({
17796
- value: lastSelected,
17797
- shouldClose: false
17798
- });
17799
- e.preventDefault();
17800
- return;
17801
- }
17802
- if (!isOpen && firstSuggestion !== inputValue) {
17827
+ event.preventDefault();
17828
+ return false;
17829
+ } else if (isMultiple && event.code === 'Backspace' && selected.length > 0 && !firstSuggestion) {
17830
+ handleChange(selected[selected.length - 1]);
17831
+ event.preventDefault();
17832
+ return false;
17833
+ } else if (!isOpen && firstSuggestion !== inputValue) {
17803
17834
  setIsOpen(true);
17804
17835
  }
17805
17836
  };
17806
- const handleRemoveSelectedClick = value => e => {
17807
- e.stopPropagation();
17808
- handleChange({
17809
- value
17810
- });
17811
- onRemoveSelectedClick?.(value);
17812
- form.trigger(name);
17837
+ const handleInputChange = event => {
17838
+ setInputValue(event.target.value);
17813
17839
  };
17814
- const handleOpenChange = (open, event, reason) => {
17815
- if (isDisabled || reason === 'reference-press') {
17816
- return;
17817
- }
17818
- setIsOpen(open);
17819
- if (!isMultiple && selectedItems.length > 0) {
17820
- const selectedValue = selectedItems[0];
17821
- const label = optionsWithKey[selectedValue]?.label;
17822
- setRawInput(label ? String(label) : null);
17823
- return;
17824
- }
17825
- setRawInput(null);
17840
+ const handleSelectedClick = event => {
17841
+ event.stopPropagation();
17842
+ };
17843
+ const handleRemoveSelectedClick = selectedItem => event => {
17844
+ event.stopPropagation();
17845
+ handleChange(selectedItem);
17846
+ onRemoveSelectedClick?.(selectedItem);
17826
17847
  };
17827
- const status = (() => {
17828
- if (form.formState.errors[name]) return 'error';
17829
- if (error) return 'error';
17830
- if (success) return 'success';
17831
- return 'basic';
17832
- })();
17833
17848
  return {
17834
17849
  isOpen,
17835
17850
  isDisabled,
17836
17851
  optionsWithKey,
17837
- selectedItems,
17852
+ selectedItems: selected,
17838
17853
  inputRef,
17839
17854
  firstSuggestion,
17840
17855
  isMultiple,
@@ -17850,18 +17865,18 @@ const useTypeahead = ({
17850
17865
  inputValue,
17851
17866
  validationSchema,
17852
17867
  status,
17853
- error: error ?? form.formState.errors[name],
17854
17868
  placeholder,
17855
17869
  options: items,
17856
- useFormResult: form,
17870
+ useFormResult,
17857
17871
  register,
17858
17872
  setValue,
17859
- onChange,
17873
+ handleChange,
17860
17874
  handleClearAll,
17861
17875
  handleOpenChange,
17862
17876
  handleInputChange,
17863
17877
  handleInputClick,
17864
17878
  handleInputKeyDown,
17879
+ handleSelectedClick,
17865
17880
  handleRemoveSelectedClick
17866
17881
  };
17867
17882
  };
@@ -17975,7 +17990,7 @@ const MultipleTrigger = () => {
17975
17990
  const theme = (0,react_namespaceObject.useTheme)();
17976
17991
  const context = useTypeaheadContext();
17977
17992
  const typeaheadInputAdditionalProps = {};
17978
- if (!context.selectedItems.length && !context.inputValue && !!context.placeholder) {
17993
+ if (!context.selectedItems.length && !!context.placeholder) {
17979
17994
  typeaheadInputAdditionalProps.placeholder = context.placeholder;
17980
17995
  }
17981
17996
  return (0,jsx_runtime_namespaceObject.jsxs)((external_react_default()).Fragment, {
@@ -17983,7 +17998,7 @@ const MultipleTrigger = () => {
17983
17998
  const currentOption = context.optionsWithKey[selectedItem];
17984
17999
  const optionText = currentOption ? currentOption.children || currentOption.label || currentOption.value : '';
17985
18000
  return (0,jsx_runtime_namespaceObject.jsxs)(TypeaheadItem, {
17986
- onClick: e => e.stopPropagation(),
18001
+ onClick: context.handleSelectedClick,
17987
18002
  isDisabled: context.isDisabled,
17988
18003
  children: [(0,jsx_runtime_namespaceObject.jsx)(TypeaheadItemLabel, {
17989
18004
  isDisabled: context.isDisabled,
@@ -18027,6 +18042,11 @@ const MultipleTrigger = () => {
18027
18042
  disabled: context.isDisabled,
18028
18043
  className: ['typeahead-input', TypeaheadInput(theme), TypeaheadInputPlaceholder].join(' '),
18029
18044
  ...typeaheadInputAdditionalProps
18045
+ }), (0,jsx_runtime_namespaceObject.jsx)("input", {
18046
+ type: "hidden",
18047
+ readOnly: true,
18048
+ value: context.selectedItems,
18049
+ ...context.register?.(context.name, context.validationSchema)
18030
18050
  })]
18031
18051
  }), !context.isDisabled && context.selectedItems.length ? (0,jsx_runtime_namespaceObject.jsx)(Button_Button, {
18032
18052
  variant: "tertiary",
@@ -18053,7 +18073,7 @@ const SingleTrigger = () => {
18053
18073
  const context = useTypeaheadContext();
18054
18074
  const theme = (0,react_namespaceObject.useTheme)();
18055
18075
  const typeaheadInputAdditionalProps = {};
18056
- if (!context.selectedItems.length && !context.inputValue && !!context.placeholder) {
18076
+ if (!context.selectedItems.length && !!context.placeholder) {
18057
18077
  typeaheadInputAdditionalProps.placeholder = context.placeholder;
18058
18078
  }
18059
18079
  return (0,jsx_runtime_namespaceObject.jsxs)(TypeaheadInputsGroupWrapper, {
@@ -18082,6 +18102,11 @@ const SingleTrigger = () => {
18082
18102
  tabIndex: -1,
18083
18103
  className: ['typeahead-input', TypeaheadInput(theme), TypeaheadInputPlaceholder].join(' '),
18084
18104
  ...typeaheadInputAdditionalProps
18105
+ }), (0,jsx_runtime_namespaceObject.jsx)("input", {
18106
+ type: "hidden",
18107
+ readOnly: true,
18108
+ value: context.selectedItems[0] || '',
18109
+ ...context.register?.(context.name, context.validationSchema)
18085
18110
  }), !context.isDisabled && context.selectedItems.length ? (0,jsx_runtime_namespaceObject.jsx)(Button_Button, {
18086
18111
  variant: "tertiary",
18087
18112
  "data-testid": "remove-all-button",
@@ -18188,7 +18213,6 @@ const Typeahead = ({
18188
18213
  name = 'typeahead-search',
18189
18214
  label,
18190
18215
  selectedItems,
18191
- defaultSelectedItems,
18192
18216
  isOpen,
18193
18217
  isDisabled,
18194
18218
  isMultiple,
@@ -18206,6 +18230,8 @@ const Typeahead = ({
18206
18230
  optionsClassName,
18207
18231
  wrapperClassName,
18208
18232
  width = 300,
18233
+ setValue,
18234
+ register,
18209
18235
  onChange,
18210
18236
  onEmptyChange,
18211
18237
  onClearAll,
@@ -18216,7 +18242,6 @@ const Typeahead = ({
18216
18242
  const hookResult = useTypeahead({
18217
18243
  name,
18218
18244
  selectedItems,
18219
- defaultSelectedItems,
18220
18245
  isOpen,
18221
18246
  isDisabled,
18222
18247
  isMultiple,
@@ -18230,6 +18255,8 @@ const Typeahead = ({
18230
18255
  success,
18231
18256
  validationSchema,
18232
18257
  placeholder,
18258
+ setValue,
18259
+ register,
18233
18260
  onChange,
18234
18261
  onEmptyChange,
18235
18262
  renderOption,
@@ -18277,7 +18304,7 @@ const Typeahead = ({
18277
18304
  status: hookResult.status,
18278
18305
  disabled: isDisabled,
18279
18306
  "data-testid": "helper-text",
18280
- children: hookResult.error ? hookResult.error?.message?.toString() : helperText
18307
+ children: error ? error?.message : helperText
18281
18308
  })]
18282
18309
  })
18283
18310
  });
@@ -19155,7 +19182,6 @@ const SelectWidget = props => {
19155
19182
  placeholder,
19156
19183
  onChange,
19157
19184
  onBlur,
19158
- onFocus,
19159
19185
  onChangeOverride,
19160
19186
  value
19161
19187
  } = props;
@@ -19170,44 +19196,43 @@ const SelectWidget = props => {
19170
19196
  const handleBlur = ({
19171
19197
  target
19172
19198
  }) => onBlur(id, target && target.value);
19173
- const handleFocus = ({
19174
- target
19175
- }) => onFocus(id, target && target.value);
19176
19199
  const onEmptyChange = isEmpty => {
19177
19200
  if (isEmpty) {
19178
19201
  handleChange();
19179
19202
  }
19180
19203
  };
19204
+ const register = fieldName => ({
19205
+ onBlur: handleBlur,
19206
+ onChange: handleChange,
19207
+ name: fieldName,
19208
+ ref: () => {}
19209
+ });
19181
19210
  const items = Array.isArray(enumOptions) ? enumOptions : [];
19182
19211
  const selectedItems = selectedIndex ? [items[Number(selectedIndex)].value] : [];
19183
- return (0,jsx_runtime_namespaceObject.jsx)("div", {
19184
- id: id,
19185
- onBlur: handleBlur,
19186
- onFocus: handleFocus,
19187
- children: (0,jsx_runtime_namespaceObject.jsx)(Typeahead, {
19188
- width: "100%",
19189
- selectedItems: selectedItems,
19190
- isDisabled: disabled,
19191
- name: name
19192
- // RJSF provides placeholder as empty string
19193
- ,
19194
- placeholder: placeholder || undefined,
19195
- onChange: handleChange,
19196
- onEmptyChange: onEmptyChange,
19197
- renderOption: ({
19198
- label,
19199
- input
19200
- }) => highlightInputMatch(label, input),
19201
- children: items.map(({
19202
- label,
19203
- value
19204
- }) => (0,jsx_runtime_namespaceObject.jsx)(TypeaheadOption_TypeaheadOption, {
19205
- value: value,
19206
- label: label || value,
19207
- isDisabled: disabled || Array.isArray(enumDisabled) && enumDisabled.includes(value),
19208
- children: label || value
19209
- }, value))
19210
- })
19212
+ return (0,jsx_runtime_namespaceObject.jsx)(Typeahead, {
19213
+ width: "100%",
19214
+ selectedItems: selectedItems,
19215
+ isDisabled: disabled,
19216
+ name: name
19217
+ // RJSF provides placeholder as empty string
19218
+ ,
19219
+ placeholder: placeholder || undefined,
19220
+ onChange: handleChange,
19221
+ register: register,
19222
+ onEmptyChange: onEmptyChange,
19223
+ renderOption: ({
19224
+ label,
19225
+ input
19226
+ }) => highlightInputMatch(label, input),
19227
+ children: items.map(({
19228
+ label,
19229
+ value
19230
+ }) => (0,jsx_runtime_namespaceObject.jsx)(TypeaheadOption_TypeaheadOption, {
19231
+ value: value,
19232
+ label: label || value,
19233
+ isDisabled: disabled || Array.isArray(enumDisabled) && enumDisabled.includes(value),
19234
+ children: label || value
19235
+ }, value))
19211
19236
  });
19212
19237
  };
19213
19238
  ;// ./src/components/JsonSchemaForm/widgets/PasswordWidget.tsx