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