@ssa-ui-kit/core 2.15.0-canary-3fd3271-20250501 → 2.15.0-canary-912002a-20250506

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
@@ -11543,10 +11543,8 @@ const TriggerInput = ({
11543
11543
  setLastFocusedElement,
11544
11544
  onBlur: handleBlur
11545
11545
  } = useDateRangePickerContext();
11546
- const formContext = (0,external_react_hook_form_namespaceObject.useFormContext)(); // Using FormProvider from react-hook-form
11547
- const useFormResult = (0,external_react_hook_form_namespaceObject.useForm)();
11548
11546
  const currentName = datepickerType === 'from' ? nameFrom : nameTo;
11549
- const hookFormResult = formContext ?? useFormResult;
11547
+ const hookFormResult = (0,external_react_hook_form_namespaceObject.useFormContext)() ?? (0,external_react_hook_form_namespaceObject.useForm)();
11550
11548
  const {
11551
11549
  register,
11552
11550
  formState: {
@@ -11611,10 +11609,14 @@ function Trigger_EMOTION_STRINGIFIED_CSS_ERROR_() { return "You have tried to st
11611
11609
 
11612
11610
 
11613
11611
  var Trigger_ref = true ? {
11612
+ name: "5bhc30",
11613
+ styles: "margin-bottom:8px"
11614
+ } : 0;
11615
+ var Trigger_ref2 = true ? {
11614
11616
  name: "jpxugn",
11615
11617
  styles: "margin:0 14px"
11616
11618
  } : 0;
11617
- var Trigger_ref2 = true ? {
11619
+ var Trigger_ref3 = true ? {
11618
11620
  name: "ud49p1",
11619
11621
  styles: "color:inherit;&::first-letter{text-transform:uppercase;}"
11620
11622
  } : 0;
@@ -11635,7 +11637,7 @@ const Trigger = () => {
11635
11637
  handleToggleOpen
11636
11638
  } = useDateRangePickerContext();
11637
11639
  const theme = (0,react_namespaceObject.useTheme)();
11638
- const formContext = (0,external_react_hook_form_namespaceObject.useFormContext)();
11640
+ const hookFormResult = (0,external_react_hook_form_namespaceObject.useFormContext)() || (0,external_react_hook_form_namespaceObject.useForm)();
11639
11641
  const wrapperRef = (0,external_react_namespaceObject.useRef)(null);
11640
11642
  (0,hooks_namespaceObject.useClickOutside)(wrapperRef, event => {
11641
11643
  const {
@@ -11646,16 +11648,17 @@ const Trigger = () => {
11646
11648
  setIsOpen(false);
11647
11649
  }
11648
11650
  });
11649
- const errorsFrom = formContext.formState.errors[nameFrom]?.message;
11650
- const errorsTo = formContext.formState.errors[nameTo]?.message;
11651
+ const errorsFrom = hookFormResult.formState.errors[nameFrom]?.message;
11652
+ const errorsTo = hookFormResult.formState.errors[nameTo]?.message;
11651
11653
  const errorMessage = [errorsFrom, errorsTo].filter(Boolean);
11652
11654
  return (0,jsx_runtime_namespaceObject.jsxs)(FieldRoot, {
11653
11655
  status: status,
11654
11656
  disabled: disabled,
11655
11657
  "data-testid": "daterangepicker",
11656
11658
  className: triggerClassname,
11657
- children: [(0,jsx_runtime_namespaceObject.jsx)(FieldLabel, {
11659
+ children: [label && (0,jsx_runtime_namespaceObject.jsx)(FieldLabel, {
11658
11660
  htmlFor: lastFocusedElement === 'from' ? nameFrom : nameTo,
11661
+ css: Trigger_ref,
11659
11662
  children: label
11660
11663
  }), (0,jsx_runtime_namespaceObject.jsx)(FieldControl, {
11661
11664
  children: (0,jsx_runtime_namespaceObject.jsxs)(Wrapper_Wrapper, {
@@ -11672,7 +11675,7 @@ const Trigger = () => {
11672
11675
  name: "carrot-right",
11673
11676
  size: 18,
11674
11677
  color: theme.colors.greyDarker80,
11675
- css: Trigger_ref
11678
+ css: Trigger_ref2
11676
11679
  }), (0,jsx_runtime_namespaceObject.jsx)(TriggerInput, {
11677
11680
  datepickerType: "to",
11678
11681
  onClick: () => {
@@ -11705,7 +11708,7 @@ const Trigger = () => {
11705
11708
  children: helperText
11706
11709
  }), (0,jsx_runtime_namespaceObject.jsx)(FieldError, {
11707
11710
  children: errorMessage ? errorMessage.map((error, index) => (0,jsx_runtime_namespaceObject.jsx)("span", {
11708
- css: Trigger_ref2,
11711
+ css: Trigger_ref3,
11709
11712
  children: error
11710
11713
  }, `error-${index}`)) : helperText
11711
11714
  }), (0,jsx_runtime_namespaceObject.jsx)(FieldSuccess, {
@@ -11806,13 +11809,14 @@ const useDateRangePicker = ({
11806
11809
  const handleSetIsOpen = open => {
11807
11810
  setIsOpen(open);
11808
11811
  };
11812
+ const hookFormResult = (0,external_react_hook_form_namespaceObject.useFormContext)() ?? (0,external_react_hook_form_namespaceObject.useForm)();
11809
11813
  const {
11810
11814
  clearErrors,
11811
11815
  setError,
11812
11816
  setValue,
11813
11817
  resetField,
11814
11818
  setFocus
11815
- } = (0,external_react_hook_form_namespaceObject.useFormContext)();
11819
+ } = hookFormResult;
11816
11820
  const nameFrom = `${_name}From`;
11817
11821
  const nameTo = `${_name}To`;
11818
11822
  const inputValueFrom = (0,external_react_hook_form_namespaceObject.useWatch)({
@@ -17514,7 +17518,6 @@ const TypeaheadContext = /*#__PURE__*/external_react_namespaceObject.createConte
17514
17518
  options: [],
17515
17519
  placeholder: '',
17516
17520
  useFormResult: {},
17517
- error: undefined,
17518
17521
  setValue: () => {
17519
17522
  /* no-op */
17520
17523
  },
@@ -17522,7 +17525,7 @@ const TypeaheadContext = /*#__PURE__*/external_react_namespaceObject.createConte
17522
17525
  /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
17523
17526
  return {};
17524
17527
  },
17525
- onChange: () => {
17528
+ handleChange: () => {
17526
17529
  /* no-op */
17527
17530
  },
17528
17531
  handleClearAll: () => {
@@ -17542,6 +17545,9 @@ const TypeaheadContext = /*#__PURE__*/external_react_namespaceObject.createConte
17542
17545
  },
17543
17546
  handleRemoveSelectedClick: () => () => {
17544
17547
  /* no-op */
17548
+ },
17549
+ handleSelectedClick: () => {
17550
+ /* no-op */
17545
17551
  }
17546
17552
  });
17547
17553
  const useTypeaheadContext = () => external_react_namespaceObject.useContext(TypeaheadContext);
@@ -17549,18 +17555,10 @@ const useTypeaheadContext = () => external_react_namespaceObject.useContext(Type
17549
17555
 
17550
17556
 
17551
17557
 
17552
- const findExactMatch = (input, options) => {
17553
- const normalizedInput = input.toLowerCase();
17554
- return Object.values(options).find(opt => {
17555
- const labelText = (opt.label ?? opt.value).toString().toLowerCase();
17556
- return labelText === normalizedInput;
17557
- });
17558
- };
17559
17558
  const useTypeahead = ({
17560
17559
  name = 'typeahead-input',
17561
17560
  isOpen: isInitOpen,
17562
17561
  selectedItems,
17563
- defaultSelectedItems,
17564
17562
  isDisabled,
17565
17563
  isMultiple,
17566
17564
  children,
@@ -17573,8 +17571,8 @@ const useTypeahead = ({
17573
17571
  error,
17574
17572
  success,
17575
17573
  placeholder,
17576
- filterOptions = true,
17577
- autoSelect = true,
17574
+ register,
17575
+ setValue,
17578
17576
  onChange,
17579
17577
  onClearAll,
17580
17578
  onRemoveSelectedClick,
@@ -17582,240 +17580,266 @@ const useTypeahead = ({
17582
17580
  renderOption
17583
17581
  }) => {
17584
17582
  const inputName = `${name}-text`;
17585
- const [isOpen, _setIsOpen] = (0,hooks_namespaceObject.useUncontrolled)({
17586
- defaultValue: isInitOpen,
17587
- finalValue: false
17588
- });
17589
- const [selected, setSelected] = (0,hooks_namespaceObject.useUncontrolled)({
17590
- value: selectedItems,
17591
- defaultValue: defaultSelectedItems,
17592
- finalValue: []
17593
- });
17594
- const [rawInput, setRawInput] = (0,external_react_namespaceObject.useState)(null);
17595
- const {
17596
- ref: inputRef
17597
- } = (0,hooks_namespaceObject.useElementSize)();
17583
+ const [isOpen, setIsOpen] = (0,external_react_namespaceObject.useState)(isInitOpen || false);
17584
+ const [selected, setSelected] = (0,external_react_namespaceObject.useState)(selectedItems || []);
17585
+ const [optionsWithKey, setOptionsWithKey] = (0,external_react_namespaceObject.useState)({});
17586
+ const [isEmpty, setIsEmpty] = (0,external_react_namespaceObject.useState)(true);
17587
+ const [isFirstRender, setFirstRender] = (0,external_react_namespaceObject.useState)(true);
17588
+ const [items, setItems] = (0,external_react_namespaceObject.useState)();
17589
+ const [inputValue, setInputValue] = (0,external_react_namespaceObject.useState)('');
17590
+ const [status, setStatus] = (0,external_react_namespaceObject.useState)('basic');
17591
+ const [firstSuggestion, setFirstSuggestion] = (0,external_react_namespaceObject.useState)('');
17592
+ const inputRef = (0,external_react_namespaceObject.useRef)(null);
17593
+ const typeaheadId = (0,external_react_namespaceObject.useId)();
17598
17594
  const triggerRef = (0,external_react_namespaceObject.useRef)(null);
17599
- const defaultForm = (0,external_react_hook_form_namespaceObject.useForm)();
17600
- const form = (0,external_react_hook_form_namespaceObject.useFormContext)() ?? defaultForm;
17601
- const {
17602
- register,
17603
- setValue
17604
- } = form;
17595
+ const useFormResult = (0,external_react_hook_form_namespaceObject.useForm)();
17605
17596
  (0,external_react_namespaceObject.useEffect)(() => {
17606
- if (!selected.length) {
17607
- return;
17597
+ if (!register) {
17598
+ console.warn('Typeahead component must be used within a Form component');
17608
17599
  }
17600
+ }, []);
17601
+ (0,external_react_namespaceObject.useEffect)(() => {
17609
17602
  if (isMultiple) {
17610
17603
  setValue?.(name, selected, {
17611
- shouldDirty: false
17604
+ shouldDirty: !isFirstRender
17612
17605
  });
17606
+ setInputValue('');
17607
+ setFirstSuggestion('');
17613
17608
  } else {
17614
- setValue?.(name, selected[0], {
17615
- shouldDirty: false
17609
+ setValue?.(name, selected.length ? selected[0] : [], {
17610
+ shouldDirty: !isFirstRender
17616
17611
  });
17617
17612
  }
17618
- }, []);
17619
- const typeaheadId = (0,external_react_namespaceObject.useId)();
17620
- const optionsWithKey = (0,external_react_namespaceObject.useMemo)(() => {
17621
- const opts = {};
17622
- external_react_default().Children.forEach(children, child => {
17623
- if (/*#__PURE__*/external_react_default().isValidElement(child)) {
17624
- opts[child.props.value] = child.props;
17625
- }
17613
+ handleOnEmptyChange(!selected.length);
17614
+ }, [selected]);
17615
+ (0,external_react_namespaceObject.useEffect)(() => {
17616
+ if (isDisabled && isOpen) {
17617
+ setIsOpen(false);
17618
+ }
17619
+ }, [isDisabled]);
17620
+ (0,external_react_namespaceObject.useEffect)(() => {
17621
+ const status = success ? 'success' : useFormResult.formState.errors[name] ? 'error' : 'basic';
17622
+ setStatus(status);
17623
+ }, [useFormResult.formState.errors[name], success]);
17624
+ (0,external_react_namespaceObject.useEffect)(() => {
17625
+ if (error) {
17626
+ useFormResult.setError(name, error);
17627
+ } else {
17628
+ setStatus('basic');
17629
+ useFormResult.resetField(name);
17630
+ }
17631
+ }, [error]);
17632
+ (0,external_react_namespaceObject.useEffect)(() => {
17633
+ processChildren({
17634
+ selectedLocal: selected
17626
17635
  });
17627
- return opts;
17628
17636
  }, [children]);
17629
- const inputValue = (0,external_react_namespaceObject.useMemo)(() => {
17630
- if (isMultiple) return rawInput ?? '';
17631
- if (rawInput != null) return rawInput;
17632
- return selected.length === 1 ? optionsWithKey[selected[0]]?.label?.toString() || '' : '';
17633
- }, [isMultiple, rawInput, selected, optionsWithKey]);
17634
- const filteredChildren = (0,external_react_namespaceObject.useMemo)(() => {
17635
- // if filtering is disabled, or there's no input, show all
17636
- if (!filterOptions || !inputValue) return external_react_default().Children.toArray(children);
17637
- const needle = inputValue.toLowerCase();
17638
- return external_react_default().Children.toArray(children).filter(child => {
17639
- if (! /*#__PURE__*/external_react_default().isValidElement(child)) return false;
17640
- const {
17641
- label,
17642
- value
17643
- } = child.props;
17644
- const text = (label ?? value)?.toString().toLowerCase() || '';
17645
- return text.includes(needle);
17637
+ (0,external_react_namespaceObject.useEffect)(() => {
17638
+ setSelected(selectedItems || []);
17639
+ if (selectedItems?.length) {
17640
+ if (!isMultiple) {
17641
+ const currentOption = optionsWithKey[selectedItems[0]];
17642
+ const optionText = currentOption && (currentOption.children || currentOption.label || currentOption.value);
17643
+ setInputValue(`${optionText}`);
17644
+ }
17645
+ } else {
17646
+ setInputValue('');
17647
+ setFirstSuggestion('');
17648
+ }
17649
+ processChildren({
17650
+ selectedLocal: selectedItems || []
17646
17651
  });
17647
- }, [children, inputValue]);
17648
- const items = (0,external_react_namespaceObject.useMemo)(() => {
17649
- return filteredChildren.map((child, index) => {
17650
- if (! /*#__PURE__*/external_react_default().isValidElement(child)) return null;
17651
- const isActive = selected.includes(child.props.value);
17652
+ }, [selectedItems]);
17653
+ (0,external_react_namespaceObject.useEffect)(() => {
17654
+ const childrenArray = external_react_default().Children.toArray(children).filter(Boolean);
17655
+ const filteredOptions = [...childrenArray];
17656
+ const childItems = filteredOptions.map((child, index) => {
17652
17657
  const {
17658
+ id,
17653
17659
  value,
17654
17660
  label,
17655
- id,
17656
17661
  isDisabled
17657
17662
  } = child.props;
17663
+ const isActive = selected.includes(child.props.value);
17658
17664
  return /*#__PURE__*/external_react_default().cloneElement(child, {
17659
- ...child.props,
17660
17665
  index,
17666
+ ...child.props,
17661
17667
  isActive,
17662
17668
  isDisabled,
17663
- role: 'option',
17669
+ id,
17664
17670
  'aria-selected': isActive,
17665
17671
  'aria-labelledby': `typeahead-label-${name}`,
17666
- onClick: e => {
17667
- e.preventDefault();
17672
+ role: 'option',
17673
+ onClick: event => {
17674
+ event.preventDefault();
17668
17675
  if (!isDisabled) {
17669
- const shouldClose = !isMultiple;
17670
- handleChange({
17671
- value,
17672
- shouldClose
17673
- });
17676
+ handleChange(child.props.value);
17674
17677
  }
17675
17678
  },
17676
- children: renderOption?.({
17679
+ children: renderOption ? renderOption({
17677
17680
  value: id || value,
17678
- input: inputValue,
17681
+ input: inputValue || '',
17679
17682
  label
17680
- }) ?? child.props.children ?? label ?? value
17683
+ }) : child.props.children || child.props.label || child.props.value
17681
17684
  });
17682
17685
  });
17683
- }, [children, selected, inputValue]);
17684
- const firstSuggestion = (0,external_react_namespaceObject.useMemo)(() => {
17685
- if (!inputValue) return '';
17686
- const needle = inputValue.toLowerCase();
17687
- for (const child of filteredChildren) {
17688
- if (! /*#__PURE__*/external_react_default().isValidElement(child)) continue;
17689
- const labelText = (child.props.label ?? child.props.value).toString();
17690
- if (labelText.toLowerCase().startsWith(needle)) {
17691
- return inputValue + labelText.slice(inputValue.length);
17686
+ setItems(childItems);
17687
+ }, [inputValue, optionsWithKey, selected]);
17688
+ (0,external_react_namespaceObject.useEffect)(() => {
17689
+ if (!isMultiple && Object.keys(optionsWithKey).length) {
17690
+ const foundItem = Object.values(optionsWithKey).find(item => item.label === inputValue);
17691
+ if (!foundItem && selected.length) {
17692
+ setSelected([]);
17693
+ }
17694
+ if (foundItem && !selected.includes(foundItem?.value)) {
17695
+ setSelected([foundItem.value]);
17692
17696
  }
17693
17697
  }
17694
- return '';
17695
- }, [inputValue, filteredChildren]);
17696
- const setIsOpen = open => {
17697
- if (!open) {
17698
- form.trigger();
17698
+ }, [optionsWithKey, inputValue]);
17699
+ (0,external_react_namespaceObject.useEffect)(() => {
17700
+ processSingleSelected({
17701
+ optionsWithKeyLocal: optionsWithKey,
17702
+ selectedLocal: selected
17703
+ });
17704
+ }, [selected]);
17705
+ (0,external_react_namespaceObject.useEffect)(() => {
17706
+ if (inputValue) {
17707
+ const newFirstSuggestion = Object.values(optionsWithKey)?.find(item => {
17708
+ const label = (0,utils_namespaceObject.propOr)('', 'label')(item);
17709
+ return label.toLowerCase().startsWith(inputValue.toLowerCase());
17710
+ });
17711
+ const firstSuggestionLabel = (0,utils_namespaceObject.propOr)('', 'label')(newFirstSuggestion);
17712
+ const humanSuggestionLabel = inputValue.concat(firstSuggestionLabel.slice(inputValue.length));
17713
+ setFirstSuggestion(humanSuggestionLabel);
17714
+ } else {
17715
+ setFirstSuggestion('');
17716
+ if (isMultiple) {
17717
+ setInputValue('');
17718
+ }
17719
+ }
17720
+ }, [inputValue, items, selected]);
17721
+ const processSingleSelected = ({
17722
+ optionsWithKeyLocal = {},
17723
+ selectedLocal = []
17724
+ }) => {
17725
+ if (!isMultiple && selectedLocal.length && Object.keys(optionsWithKeyLocal).length) {
17726
+ const currentOption = optionsWithKeyLocal[selectedLocal[0]];
17727
+ const optionText = currentOption && (currentOption.children || currentOption.label || currentOption.value);
17728
+ setInputValue(`${optionText}`);
17699
17729
  }
17700
- _setIsOpen(open);
17701
17730
  };
17702
- const handleChange = ({
17703
- value,
17704
- shouldClose = true,
17705
- resetInput = true
17731
+ const processChildren = ({
17732
+ selectedLocal
17706
17733
  }) => {
17707
- if (isDisabled || value == null) return;
17708
- const alreadySelected = selected.includes(value);
17709
- const updatedSelected = isMultiple ? alreadySelected ? selected.filter(item => item !== value) : [...selected, value] : alreadySelected ? [] : [value];
17710
- const fieldValue = isMultiple ? updatedSelected : updatedSelected[0];
17711
- setSelected(updatedSelected);
17712
- setValue?.(name, fieldValue);
17713
- form.clearErrors(name);
17714
- if (resetInput) {
17715
- const rawInputValue = isMultiple ? null : updatedSelected.length ? String(optionsWithKey[value]?.label) : null;
17716
- setRawInput(rawInputValue);
17734
+ const keyedOptions = {};
17735
+ const childItems = external_react_default().Children.toArray(children).filter(Boolean).map((child, index) => {
17736
+ keyedOptions[child.props.value] = {
17737
+ ...child.props
17738
+ };
17739
+ return /*#__PURE__*/external_react_default().cloneElement(child, {
17740
+ index,
17741
+ ...child.props
17742
+ });
17743
+ });
17744
+ setOptionsWithKey(keyedOptions);
17745
+ setItems(childItems);
17746
+ processSingleSelected({
17747
+ optionsWithKeyLocal: keyedOptions,
17748
+ selectedLocal
17749
+ });
17750
+ setFirstRender(false);
17751
+ };
17752
+ const handleOnEmptyChange = newIsEmptyValue => {
17753
+ if (newIsEmptyValue !== isEmpty) {
17754
+ setIsEmpty(newIsEmptyValue);
17755
+ onEmptyChange?.(newIsEmptyValue);
17717
17756
  }
17718
- if (shouldClose) {
17719
- setIsOpen(false);
17757
+ };
17758
+ const handleOpenChange = open => {
17759
+ if (!isDisabled) {
17760
+ setIsOpen(open);
17720
17761
  }
17721
- onChange?.(value, !alreadySelected);
17722
- onEmptyChange?.(updatedSelected.length === 0);
17723
17762
  };
17724
- const handleClearAll = e => {
17725
- if (isDisabled) return;
17726
- e.preventDefault();
17727
- e.stopPropagation();
17728
- setSelected([]);
17729
- setRawInput(null);
17763
+ const handleChange = changingValue => {
17764
+ if (isDisabled || changingValue === undefined) {
17765
+ return;
17766
+ }
17767
+ const isNewSelected = true;
17768
+ const isChangingItemSelected = selected.includes(changingValue);
17769
+ if (isMultiple) {
17770
+ setSelected(currentSelected => isChangingItemSelected ? currentSelected.filter(current => current !== changingValue) : [...currentSelected, changingValue]);
17771
+ setInputValue('');
17772
+ } else {
17773
+ if (selected[0] === changingValue) {
17774
+ setSelected([]);
17775
+ setInputValue('');
17776
+ } else {
17777
+ setSelected([changingValue]);
17778
+ }
17779
+ }
17730
17780
  setIsOpen(false);
17731
- setValue?.(name, undefined);
17732
- form.trigger(name);
17781
+ setFirstSuggestion('');
17733
17782
  inputRef.current?.focus();
17734
- onClearAll?.();
17735
- onEmptyChange?.(true);
17783
+ setStatus('basic');
17784
+ useFormResult.clearErrors(name);
17785
+ useFormResult.trigger(name);
17786
+ onChange?.(changingValue, isNewSelected);
17736
17787
  };
17737
- const handleInputChange = e => {
17738
- const input = e.target.value;
17739
- setRawInput(input);
17740
- if (!autoSelect || !filterOptions) return;
17741
- const match = findExactMatch(input, optionsWithKey);
17742
- if (match) {
17743
- handleChange({
17744
- value: match.value,
17745
- shouldClose: false
17746
- });
17788
+ const handleClearAll = event => {
17789
+ if (isDisabled) {
17747
17790
  return;
17748
17791
  }
17749
- // unset selected value if not fully matched
17750
- if (!isMultiple && selected.length > 0) {
17751
- handleChange({
17752
- value: selected[0],
17753
- shouldClose: false,
17754
- resetInput: false
17755
- });
17756
- }
17792
+ event.stopPropagation();
17793
+ event.preventDefault();
17794
+ setSelected([]);
17795
+ setInputValue('');
17796
+ setIsOpen(false);
17797
+ setFirstSuggestion('');
17798
+ useFormResult.trigger(name);
17799
+ inputRef.current?.focus();
17800
+ onClearAll?.();
17757
17801
  };
17758
- const handleInputClick = e => {
17759
- e.stopPropagation();
17760
- e.preventDefault();
17802
+ const handleInputClick = event => {
17761
17803
  if (!isDisabled) {
17762
17804
  inputRef.current?.focus();
17763
17805
  setIsOpen(true);
17764
17806
  }
17807
+ event.stopPropagation();
17808
+ event.preventDefault();
17765
17809
  };
17766
- const handleInputKeyDown = e => {
17767
- const isEnterOrTab = ['Enter', 'Tab'].includes(e.code);
17768
- if (isEnterOrTab && firstSuggestion && firstSuggestion !== inputValue) {
17769
- const match = findExactMatch(firstSuggestion, optionsWithKey);
17770
- if (match) {
17771
- handleChange({
17772
- value: match.value,
17773
- shouldClose: false
17774
- });
17810
+ const handleInputKeyDown = event => {
17811
+ if (['Space'].includes(event.code) && !firstSuggestion) {
17812
+ setIsOpen(true);
17813
+ inputRef.current?.focus();
17814
+ event.stopPropagation();
17815
+ event.preventDefault();
17816
+ } else if (['Tab', 'Enter'].includes(event.code) && firstSuggestion && firstSuggestion !== inputValue) {
17817
+ const foundItem = Object.values(optionsWithKey).find(item => `${item.label}`.toLowerCase() === firstSuggestion.toLowerCase());
17818
+ handleChange(foundItem?.value);
17819
+ if (foundItem) {
17820
+ setInputValue(`${foundItem?.label}`);
17775
17821
  }
17776
- e.preventDefault();
17777
- return;
17778
- }
17779
- if (isMultiple && e.code === 'Backspace' && selected.length && !inputValue) {
17780
- const lastSelected = selected[selected.length - 1];
17781
- handleChange({
17782
- value: lastSelected,
17783
- shouldClose: false
17784
- });
17785
- e.preventDefault();
17786
- return;
17787
- }
17788
- if (!isOpen && firstSuggestion !== inputValue) {
17822
+ event.preventDefault();
17823
+ return false;
17824
+ } else if (isMultiple && event.code === 'Backspace' && selected.length > 0 && !firstSuggestion) {
17825
+ handleChange(selected[selected.length - 1]);
17826
+ event.preventDefault();
17827
+ return false;
17828
+ } else if (!isOpen && firstSuggestion !== inputValue) {
17789
17829
  setIsOpen(true);
17790
17830
  }
17791
17831
  };
17792
- const handleRemoveSelectedClick = value => e => {
17793
- e.stopPropagation();
17794
- handleChange({
17795
- value
17796
- });
17797
- onRemoveSelectedClick?.(value);
17798
- form.trigger(name);
17832
+ const handleInputChange = event => {
17833
+ setInputValue(event.target.value);
17799
17834
  };
17800
- const handleOpenChange = (open, event, reason) => {
17801
- if (isDisabled || reason === 'reference-press') {
17802
- return;
17803
- }
17804
- setIsOpen(open);
17805
- if (!isMultiple && selected.length > 0) {
17806
- const selectedValue = selected[0];
17807
- const label = optionsWithKey[selectedValue]?.label;
17808
- setRawInput(label ? String(label) : null);
17809
- return;
17810
- }
17811
- setRawInput(null);
17835
+ const handleSelectedClick = event => {
17836
+ event.stopPropagation();
17837
+ };
17838
+ const handleRemoveSelectedClick = selectedItem => event => {
17839
+ event.stopPropagation();
17840
+ handleChange(selectedItem);
17841
+ onRemoveSelectedClick?.(selectedItem);
17812
17842
  };
17813
- const status = (() => {
17814
- if (form.formState.errors[name]) return 'error';
17815
- if (error) return 'error';
17816
- if (success) return 'success';
17817
- return 'basic';
17818
- })();
17819
17843
  return {
17820
17844
  isOpen,
17821
17845
  isDisabled,
@@ -17836,18 +17860,18 @@ const useTypeahead = ({
17836
17860
  inputValue,
17837
17861
  validationSchema,
17838
17862
  status,
17839
- error: error ?? form.formState.errors[name],
17840
17863
  placeholder,
17841
17864
  options: items,
17842
- useFormResult: form,
17865
+ useFormResult,
17843
17866
  register,
17844
17867
  setValue,
17845
- onChange,
17868
+ handleChange,
17846
17869
  handleClearAll,
17847
17870
  handleOpenChange,
17848
17871
  handleInputChange,
17849
17872
  handleInputClick,
17850
17873
  handleInputKeyDown,
17874
+ handleSelectedClick,
17851
17875
  handleRemoveSelectedClick
17852
17876
  };
17853
17877
  };
@@ -17961,7 +17985,7 @@ const MultipleTrigger = () => {
17961
17985
  const theme = (0,react_namespaceObject.useTheme)();
17962
17986
  const context = useTypeaheadContext();
17963
17987
  const typeaheadInputAdditionalProps = {};
17964
- if (!context.selectedItems.length && !context.inputValue && !!context.placeholder) {
17988
+ if (!context.selectedItems.length && !!context.placeholder) {
17965
17989
  typeaheadInputAdditionalProps.placeholder = context.placeholder;
17966
17990
  }
17967
17991
  return (0,jsx_runtime_namespaceObject.jsxs)((external_react_default()).Fragment, {
@@ -17969,7 +17993,7 @@ const MultipleTrigger = () => {
17969
17993
  const currentOption = context.optionsWithKey[selectedItem];
17970
17994
  const optionText = currentOption ? currentOption.children || currentOption.label || currentOption.value : '';
17971
17995
  return (0,jsx_runtime_namespaceObject.jsxs)(TypeaheadItem, {
17972
- onClick: e => e.stopPropagation(),
17996
+ onClick: context.handleSelectedClick,
17973
17997
  isDisabled: context.isDisabled,
17974
17998
  children: [(0,jsx_runtime_namespaceObject.jsx)(TypeaheadItemLabel, {
17975
17999
  isDisabled: context.isDisabled,
@@ -18044,7 +18068,7 @@ const SingleTrigger = () => {
18044
18068
  const context = useTypeaheadContext();
18045
18069
  const theme = (0,react_namespaceObject.useTheme)();
18046
18070
  const typeaheadInputAdditionalProps = {};
18047
- if (!context.selectedItems.length && !context.inputValue && !!context.placeholder) {
18071
+ if (!context.selectedItems.length && !!context.placeholder) {
18048
18072
  typeaheadInputAdditionalProps.placeholder = context.placeholder;
18049
18073
  }
18050
18074
  return (0,jsx_runtime_namespaceObject.jsxs)(TypeaheadInputsGroupWrapper, {
@@ -18184,7 +18208,6 @@ const Typeahead = ({
18184
18208
  name = 'typeahead-search',
18185
18209
  label,
18186
18210
  selectedItems,
18187
- defaultSelectedItems,
18188
18211
  isOpen,
18189
18212
  isDisabled,
18190
18213
  isMultiple,
@@ -18202,6 +18225,8 @@ const Typeahead = ({
18202
18225
  optionsClassName,
18203
18226
  wrapperClassName,
18204
18227
  width = 300,
18228
+ setValue,
18229
+ register,
18205
18230
  onChange,
18206
18231
  onEmptyChange,
18207
18232
  onClearAll,
@@ -18212,7 +18237,6 @@ const Typeahead = ({
18212
18237
  const hookResult = useTypeahead({
18213
18238
  name,
18214
18239
  selectedItems,
18215
- defaultSelectedItems,
18216
18240
  isOpen,
18217
18241
  isDisabled,
18218
18242
  isMultiple,
@@ -18226,6 +18250,8 @@ const Typeahead = ({
18226
18250
  success,
18227
18251
  validationSchema,
18228
18252
  placeholder,
18253
+ setValue,
18254
+ register,
18229
18255
  onChange,
18230
18256
  onEmptyChange,
18231
18257
  renderOption,
@@ -18273,7 +18299,7 @@ const Typeahead = ({
18273
18299
  status: hookResult.status,
18274
18300
  disabled: isDisabled,
18275
18301
  "data-testid": "helper-text",
18276
- children: hookResult.error ? hookResult.error?.message?.toString() : helperText
18302
+ children: error ? error?.message : helperText
18277
18303
  })]
18278
18304
  })
18279
18305
  });
@@ -19151,7 +19177,6 @@ const SelectWidget = props => {
19151
19177
  placeholder,
19152
19178
  onChange,
19153
19179
  onBlur,
19154
- onFocus,
19155
19180
  onChangeOverride,
19156
19181
  value
19157
19182
  } = props;
@@ -19166,44 +19191,43 @@ const SelectWidget = props => {
19166
19191
  const handleBlur = ({
19167
19192
  target
19168
19193
  }) => onBlur(id, target && target.value);
19169
- const handleFocus = ({
19170
- target
19171
- }) => onFocus(id, target && target.value);
19172
19194
  const onEmptyChange = isEmpty => {
19173
19195
  if (isEmpty) {
19174
19196
  handleChange();
19175
19197
  }
19176
19198
  };
19199
+ const register = fieldName => ({
19200
+ onBlur: handleBlur,
19201
+ onChange: handleChange,
19202
+ name: fieldName,
19203
+ ref: () => {}
19204
+ });
19177
19205
  const items = Array.isArray(enumOptions) ? enumOptions : [];
19178
19206
  const selectedItems = selectedIndex ? [items[Number(selectedIndex)].value] : [];
19179
- return (0,jsx_runtime_namespaceObject.jsx)("div", {
19180
- id: id,
19181
- onBlur: handleBlur,
19182
- onFocus: handleFocus,
19183
- children: (0,jsx_runtime_namespaceObject.jsx)(Typeahead, {
19184
- width: "100%",
19185
- selectedItems: selectedItems,
19186
- isDisabled: disabled,
19187
- name: name
19188
- // RJSF provides placeholder as empty string
19189
- ,
19190
- placeholder: placeholder || undefined,
19191
- onChange: handleChange,
19192
- onEmptyChange: onEmptyChange,
19193
- renderOption: ({
19194
- label,
19195
- input
19196
- }) => highlightInputMatch(label, input),
19197
- children: items.map(({
19198
- label,
19199
- value
19200
- }) => (0,jsx_runtime_namespaceObject.jsx)(TypeaheadOption_TypeaheadOption, {
19201
- value: value,
19202
- label: label || value,
19203
- isDisabled: disabled || Array.isArray(enumDisabled) && enumDisabled.includes(value),
19204
- children: label || value
19205
- }, value))
19206
- })
19207
+ return (0,jsx_runtime_namespaceObject.jsx)(Typeahead, {
19208
+ width: "100%",
19209
+ selectedItems: selectedItems,
19210
+ isDisabled: disabled,
19211
+ name: name
19212
+ // RJSF provides placeholder as empty string
19213
+ ,
19214
+ placeholder: placeholder || undefined,
19215
+ onChange: handleChange,
19216
+ register: register,
19217
+ onEmptyChange: onEmptyChange,
19218
+ renderOption: ({
19219
+ label,
19220
+ input
19221
+ }) => highlightInputMatch(label, input),
19222
+ children: items.map(({
19223
+ label,
19224
+ value
19225
+ }) => (0,jsx_runtime_namespaceObject.jsx)(TypeaheadOption_TypeaheadOption, {
19226
+ value: value,
19227
+ label: label || value,
19228
+ isDisabled: disabled || Array.isArray(enumDisabled) && enumDisabled.includes(value),
19229
+ children: label || value
19230
+ }, value))
19207
19231
  });
19208
19232
  };
19209
19233
  ;// ./src/components/JsonSchemaForm/widgets/PasswordWidget.tsx