@ssa-ui-kit/core 2.16.2 → 2.16.3-canary-be61b75-20250507

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
@@ -10551,9 +10551,10 @@ const DatesListWrapper = /*#__PURE__*/base_default()(Wrapper_Wrapper, true ? {
10551
10551
  }) => theme.colors.greyLighter, ";}" + ( true ? "" : 0));
10552
10552
  ;// ./src/components/DateRangePicker/styles.ts
10553
10553
 
10554
+ function DateRangePicker_styles_EMOTION_STRINGIFIED_CSS_ERROR_() { return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."; }
10554
10555
 
10555
10556
  const styles_DaysViewCell = /*#__PURE__*/base_default()(Wrapper_Wrapper, true ? {
10556
- target: "e19l41fq2"
10557
+ target: "e19l41fq3"
10557
10558
  } : 0)("position:relative;width:40px;height:40px;justify-content:center;font-size:14px;font-weight:500;border-radius:", ({
10558
10559
  isHighlighted
10559
10560
  }) => isHighlighted ? 0 : '6px', ";border:", ({
@@ -10589,7 +10590,7 @@ const styles_DaysViewCell = /*#__PURE__*/base_default()(Wrapper_Wrapper, true ?
10589
10590
  isCalendarDateNow
10590
10591
  }) => isCalendarDateNow && `1px solid ${theme.colors.greyFocused}`, ";}" + ( true ? "" : 0));
10591
10592
  const styles_YearsViewCell = /*#__PURE__*/base_default()("div", true ? {
10592
- target: "e19l41fq1"
10593
+ target: "e19l41fq2"
10593
10594
  } : 0)("display:flex;justify-content:center;position:relative;align-items:center;width:70px;height:40px;border-radius:", ({
10594
10595
  isCalendarFirstDateSelected,
10595
10596
  isCalendarSecondDateSelected
@@ -10622,7 +10623,7 @@ const styles_YearsViewCell = /*#__PURE__*/base_default()("div", true ? {
10622
10623
  theme
10623
10624
  }) => theme.colors.blueRoyal16, ";}" + ( true ? "" : 0));
10624
10625
  const styles_MonthsViewCell = /*#__PURE__*/base_default()("div", true ? {
10625
- target: "e19l41fq0"
10626
+ target: "e19l41fq1"
10626
10627
  } : 0)("display:flex;justify-content:center;position:relative;align-items:center;width:99px;height:40px;border-radius:", ({
10627
10628
  isCalendarFirstDateSelected,
10628
10629
  isCalendarSecondDateSelected
@@ -10659,6 +10660,12 @@ const styles_MonthsViewCell = /*#__PURE__*/base_default()("div", true ? {
10659
10660
  }) => isCalendarFirstDateSelected ? '0' : 'auto', ";z-index:-1;background:", ({
10660
10661
  theme
10661
10662
  }) => theme.colors.blueRoyal16, ";}}" + ( true ? "" : 0));
10663
+ const TriggerWrapper = /*#__PURE__*/base_default()(Wrapper_Wrapper, true ? {
10664
+ target: "e19l41fq0"
10665
+ } : 0)( true ? {
10666
+ name: "1utaypi",
10667
+ styles: "padding:14px"
10668
+ } : 0);
10662
10669
  ;// ./src/components/DateRangePicker/utils/dates.ts
10663
10670
 
10664
10671
  const dates_getDaysForCalendarMonth = date => {
@@ -11384,7 +11391,7 @@ const FieldLabel = ({
11384
11391
 
11385
11392
  const FieldControlBase = /*#__PURE__*/base_default()("div", true ? {
11386
11393
  target: "e1lr2tz0"
11387
- } : 0)("display:flex;align-items:center;min-height:44px;height:auto;border-radius:8px;overflow:hidden;border:1px solid ", ({
11394
+ } : 0)("display:flex;align-items:center;min-height:44px;height:auto;border-radius:16px;overflow:hidden;border:1px solid ", ({
11388
11395
  status,
11389
11396
  theme
11390
11397
  }) => {
@@ -11577,6 +11584,7 @@ const TriggerInput = ({
11577
11584
  disabled: disabled,
11578
11585
  register: register,
11579
11586
  className: className,
11587
+ wrapperClassName: /*#__PURE__*/(0,css_namespaceObject.css)("display:flex;padding-left:", datepickerType === 'from' ? 0 : 14, "px;" + ( true ? "" : 0), true ? "" : 0),
11580
11588
  inputProps: {
11581
11589
  onBlur: handleBlur,
11582
11590
  onClick: handleOpen,
@@ -11585,8 +11593,8 @@ const TriggerInput = ({
11585
11593
  'data-testid': `daterangepicker-input-${datepickerType}`,
11586
11594
  autoComplete: 'off',
11587
11595
  className: [/*#__PURE__*/(0,css_namespaceObject.css)( true ? {
11588
- name: "150iz59",
11589
- styles: "border:none!important"
11596
+ name: "15obm9d",
11597
+ styles: "border:none!important;height:auto!important;padding:0!important;min-width:75px;line-height:16px;max-height:16px;letter-spacing:0.8px;border-radius:0!important;&::placeholder{letter-spacing:normal;}"
11590
11598
  } : 0), datepickerType === 'from' ? classNames?.trigger?.inputFrom : classNames?.trigger?.inputTo].filter(Boolean).join(' '),
11591
11599
  ...inputElementProps
11592
11600
  },
@@ -11613,9 +11621,10 @@ function Trigger_EMOTION_STRINGIFIED_CSS_ERROR_() { return "You have tried to st
11613
11621
 
11614
11622
 
11615
11623
 
11624
+
11616
11625
  var Trigger_ref = true ? {
11617
- name: "jpxugn",
11618
- styles: "margin:0 14px"
11626
+ name: "1ldd2k6",
11627
+ styles: "margin:0 3px"
11619
11628
  } : 0;
11620
11629
  var Trigger_ref2 = true ? {
11621
11630
  name: "ud49p1",
@@ -11662,7 +11671,7 @@ const Trigger = () => {
11662
11671
  className: classNames?.label,
11663
11672
  children: label
11664
11673
  }), (0,jsx_runtime_namespaceObject.jsx)(FieldControl, {
11665
- children: (0,jsx_runtime_namespaceObject.jsxs)(Wrapper_Wrapper, {
11674
+ children: (0,jsx_runtime_namespaceObject.jsxs)(TriggerWrapper, {
11666
11675
  ref: wrapperRef,
11667
11676
  className: classNames?.trigger?.controlsWrapper,
11668
11677
  children: [(0,jsx_runtime_namespaceObject.jsx)(TriggerInput, {
@@ -11676,8 +11685,8 @@ const Trigger = () => {
11676
11685
  }
11677
11686
  }), (0,jsx_runtime_namespaceObject.jsx)(Icon_Icon, {
11678
11687
  name: "carrot-right",
11679
- size: 18,
11680
- color: theme.colors.greyDarker80,
11688
+ size: 16,
11689
+ color: disabled ? theme.colors.grey : theme.colors.greyDarker,
11681
11690
  className: classNames?.trigger?.arrowIcon,
11682
11691
  css: Trigger_ref
11683
11692
  }), (0,jsx_runtime_namespaceObject.jsx)(TriggerInput, {
@@ -11702,7 +11711,8 @@ const Trigger = () => {
11702
11711
  className: classNames?.trigger?.calendarIcon,
11703
11712
  css: /*#__PURE__*/(0,react_namespaceObject.css)({
11704
11713
  padding: 0,
11705
- margin: '0 8px 0 14px',
11714
+ margin: '0 0 0 10px',
11715
+ height: 'auto',
11706
11716
  cursor: openCalendarMode === 'input' || disabled ? 'default' : 'pointer',
11707
11717
  '&:focus::before': {
11708
11718
  display: 'none'
@@ -17209,7 +17219,7 @@ const SearchBoxWrapper = /*#__PURE__*/base_default()("div", true ? {
17209
17219
 
17210
17220
  const SearchBoxInput = /*#__PURE__*/base_default()(Input_Input, true ? {
17211
17221
  target: "e1kaxfzq0"
17212
- } : 0)("height:30px;font-size:12px;border-radius:5px;background-color:", ({
17222
+ } : 0)("height:30px;font-size:12px;border-radius:12px;background-color:", ({
17213
17223
  theme
17214
17224
  }) => theme.colors.greyLighter, ";border:1px solid #dee0e8;color:", ({
17215
17225
  theme
@@ -17523,6 +17533,7 @@ const TypeaheadContext = /*#__PURE__*/external_react_namespaceObject.createConte
17523
17533
  options: [],
17524
17534
  placeholder: '',
17525
17535
  useFormResult: {},
17536
+ error: undefined,
17526
17537
  setValue: () => {
17527
17538
  /* no-op */
17528
17539
  },
@@ -17530,7 +17541,7 @@ const TypeaheadContext = /*#__PURE__*/external_react_namespaceObject.createConte
17530
17541
  /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
17531
17542
  return {};
17532
17543
  },
17533
- handleChange: () => {
17544
+ onChange: () => {
17534
17545
  /* no-op */
17535
17546
  },
17536
17547
  handleClearAll: () => {
@@ -17550,9 +17561,6 @@ const TypeaheadContext = /*#__PURE__*/external_react_namespaceObject.createConte
17550
17561
  },
17551
17562
  handleRemoveSelectedClick: () => () => {
17552
17563
  /* no-op */
17553
- },
17554
- handleSelectedClick: () => {
17555
- /* no-op */
17556
17564
  }
17557
17565
  });
17558
17566
  const useTypeaheadContext = () => external_react_namespaceObject.useContext(TypeaheadContext);
@@ -17560,10 +17568,18 @@ const useTypeaheadContext = () => external_react_namespaceObject.useContext(Type
17560
17568
 
17561
17569
 
17562
17570
 
17571
+ const findExactMatch = (input, options) => {
17572
+ const normalizedInput = input.toLowerCase();
17573
+ return Object.values(options).find(opt => {
17574
+ const labelText = (opt.label ?? opt.value).toString().toLowerCase();
17575
+ return labelText === normalizedInput;
17576
+ });
17577
+ };
17563
17578
  const useTypeahead = ({
17564
17579
  name = 'typeahead-input',
17565
17580
  isOpen: isInitOpen,
17566
- selectedItems,
17581
+ selectedItems: providedSelectedItems,
17582
+ defaultSelectedItems,
17567
17583
  isDisabled,
17568
17584
  isMultiple,
17569
17585
  children,
@@ -17576,8 +17592,8 @@ const useTypeahead = ({
17576
17592
  error,
17577
17593
  success,
17578
17594
  placeholder,
17579
- register,
17580
- setValue,
17595
+ filterOptions = true,
17596
+ autoSelect = true,
17581
17597
  onChange,
17582
17598
  onClearAll,
17583
17599
  onRemoveSelectedClick,
@@ -17585,271 +17601,263 @@ const useTypeahead = ({
17585
17601
  renderOption
17586
17602
  }) => {
17587
17603
  const inputName = `${name}-text`;
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');
17604
- }
17605
- }, []);
17606
- (0,external_react_namespaceObject.useEffect)(() => {
17607
- if (isMultiple) {
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
- });
17604
+ const defaultForm = (0,external_react_hook_form_namespaceObject.useForm)();
17605
+ const form = (0,external_react_hook_form_namespaceObject.useFormContext)() ?? defaultForm;
17606
+ const {
17607
+ register,
17608
+ setValue,
17609
+ watch
17610
+ } = form;
17611
+ const formFieldValue = watch(name);
17612
+ const controlledValue = (() => {
17613
+ if (providedSelectedItems) {
17614
+ return providedSelectedItems;
17617
17615
  }
17618
- handleOnEmptyChange(!selected.length);
17619
- }, [selected]);
17620
- (0,external_react_namespaceObject.useEffect)(() => {
17621
- if (isDisabled && isOpen) {
17622
- setIsOpen(false);
17616
+ // controlledValue should be undefined if defaultSelectedItems is provided
17617
+ if (defaultSelectedItems) {
17618
+ return;
17623
17619
  }
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);
17620
+ if (isMultiple) {
17621
+ return Array.isArray(formFieldValue) ? formFieldValue : [];
17635
17622
  }
17636
- }, [error]);
17637
- (0,external_react_namespaceObject.useEffect)(() => {
17638
- processChildren({
17639
- selectedLocal: selected
17623
+ return ['number', 'string'].includes(typeof formFieldValue) ? [formFieldValue] : [];
17624
+ })();
17625
+ const [isOpen, _setIsOpen] = (0,hooks_namespaceObject.useUncontrolled)({
17626
+ defaultValue: isInitOpen,
17627
+ finalValue: false
17628
+ });
17629
+ const [selectedItems, setSelected] = (0,hooks_namespaceObject.useUncontrolled)({
17630
+ value: controlledValue,
17631
+ defaultValue: defaultSelectedItems,
17632
+ finalValue: []
17633
+ });
17634
+ const [rawInput, setRawInput] = (0,external_react_namespaceObject.useState)(null);
17635
+ const {
17636
+ ref: inputRef
17637
+ } = (0,hooks_namespaceObject.useElementSize)();
17638
+ const triggerRef = (0,external_react_namespaceObject.useRef)(null);
17639
+ (0,external_react_hook_form_namespaceObject.useController)({
17640
+ control: form.control,
17641
+ name,
17642
+ rules: validationSchema,
17643
+ defaultValue: isMultiple ? selectedItems : selectedItems[0]
17644
+ });
17645
+ const typeaheadId = (0,external_react_namespaceObject.useId)();
17646
+ const optionsWithKey = (0,external_react_namespaceObject.useMemo)(() => {
17647
+ const opts = {};
17648
+ external_react_default().Children.forEach(children, child => {
17649
+ if (/*#__PURE__*/external_react_default().isValidElement(child)) {
17650
+ opts[child.props.value] = child.props;
17651
+ }
17640
17652
  });
17653
+ return opts;
17641
17654
  }, [children]);
17642
17655
  (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('');
17656
+ const validSelected = selectedItems.filter(item => optionsWithKey[item]);
17657
+ if (validSelected.length !== selectedItems.length) {
17658
+ setSelected(validSelected);
17659
+ const fieldValue = isMultiple ? validSelected : undefined;
17660
+ setValue?.(name, fieldValue);
17661
+ setRawInput(null);
17662
+ form.clearErrors(name);
17663
+ form.trigger(name);
17664
+ onEmptyChange?.(validSelected.length === 0);
17653
17665
  }
17654
- processChildren({
17655
- selectedLocal: selectedItems || []
17666
+ }, [optionsWithKey, selectedItems]);
17667
+ const inputValue = (0,external_react_namespaceObject.useMemo)(() => {
17668
+ if (isMultiple) return rawInput ?? '';
17669
+ if (rawInput != null) return rawInput;
17670
+ return selectedItems.length === 1 ? optionsWithKey[selectedItems[0]]?.label?.toString() || '' : '';
17671
+ }, [isMultiple, rawInput, selectedItems, optionsWithKey]);
17672
+ const filteredChildren = (0,external_react_namespaceObject.useMemo)(() => {
17673
+ // if filtering is disabled, or there's no input, show all
17674
+ if (!filterOptions || !inputValue) return external_react_default().Children.toArray(children);
17675
+ const needle = inputValue.toLowerCase();
17676
+ return external_react_default().Children.toArray(children).filter(child => {
17677
+ if (! /*#__PURE__*/external_react_default().isValidElement(child)) return false;
17678
+ const {
17679
+ label,
17680
+ value
17681
+ } = child.props;
17682
+ const text = (label ?? value)?.toString().toLowerCase() || '';
17683
+ return text.includes(needle);
17656
17684
  });
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) => {
17685
+ }, [children, inputValue]);
17686
+ const items = (0,external_react_namespaceObject.useMemo)(() => {
17687
+ return filteredChildren.map((child, index) => {
17688
+ if (! /*#__PURE__*/external_react_default().isValidElement(child)) return null;
17689
+ const isActive = selectedItems.includes(child.props.value);
17662
17690
  const {
17663
- id,
17664
17691
  value,
17665
17692
  label,
17693
+ id,
17666
17694
  isDisabled
17667
17695
  } = child.props;
17668
- const isActive = selected.includes(child.props.value);
17669
17696
  return /*#__PURE__*/external_react_default().cloneElement(child, {
17670
- index,
17671
17697
  ...child.props,
17698
+ index,
17672
17699
  isActive,
17673
17700
  isDisabled,
17674
- id,
17701
+ role: 'option',
17675
17702
  'aria-selected': isActive,
17676
17703
  'aria-labelledby': `typeahead-label-${name}`,
17677
- role: 'option',
17678
- onClick: event => {
17679
- event.preventDefault();
17704
+ onClick: e => {
17705
+ e.preventDefault();
17680
17706
  if (!isDisabled) {
17681
- handleChange(child.props.value);
17707
+ const shouldClose = !isMultiple;
17708
+ handleChange({
17709
+ value,
17710
+ shouldClose
17711
+ });
17682
17712
  }
17683
17713
  },
17684
- children: renderOption ? renderOption({
17714
+ children: renderOption?.({
17685
17715
  value: id || value,
17686
- input: inputValue || '',
17716
+ input: inputValue,
17687
17717
  label
17688
- }) : child.props.children || child.props.label || child.props.value
17718
+ }) ?? child.props.children ?? label ?? value
17689
17719
  });
17690
17720
  });
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]);
17701
- }
17702
- }
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('');
17721
+ }, [children, selectedItems, inputValue]);
17722
+ const firstSuggestion = (0,external_react_namespaceObject.useMemo)(() => {
17723
+ if (!inputValue) return '';
17724
+ const needle = inputValue.toLowerCase();
17725
+ for (const child of filteredChildren) {
17726
+ if (! /*#__PURE__*/external_react_default().isValidElement(child)) continue;
17727
+ const labelText = (child.props.label ?? child.props.value).toString();
17728
+ if (labelText.toLowerCase().startsWith(needle)) {
17729
+ return inputValue + labelText.slice(inputValue.length);
17723
17730
  }
17724
17731
  }
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}`);
17732
+ return '';
17733
+ }, [inputValue, filteredChildren]);
17734
+ const setIsOpen = open => {
17735
+ if (!open) {
17736
+ form.trigger(name);
17734
17737
  }
17738
+ _setIsOpen(open);
17735
17739
  };
17736
- const processChildren = ({
17737
- selectedLocal
17740
+ const handleChange = ({
17741
+ value,
17742
+ shouldClose = true,
17743
+ resetInput = true
17738
17744
  }) => {
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);
17745
+ if (isDisabled || value == null) return;
17746
+ const alreadySelected = selectedItems.includes(value);
17747
+ const updatedSelected = isMultiple ? alreadySelected ? selectedItems.filter(item => item !== value) : [...selectedItems, value] : alreadySelected ? [] : [value];
17748
+ const fieldValue = isMultiple ? updatedSelected : updatedSelected[0];
17749
+ setSelected(updatedSelected);
17750
+ setValue?.(name, fieldValue);
17751
+ form.clearErrors(name);
17752
+ if (resetInput) {
17753
+ const rawInputValue = isMultiple ? null : updatedSelected.length ? String(optionsWithKey[value]?.label) : null;
17754
+ setRawInput(rawInputValue);
17761
17755
  }
17762
- };
17763
- const handleOpenChange = open => {
17764
- if (!isDisabled) {
17765
- setIsOpen(open);
17756
+ if (shouldClose) {
17757
+ setIsOpen(false);
17766
17758
  }
17759
+ onChange?.(value, !alreadySelected);
17760
+ onEmptyChange?.(updatedSelected.length === 0);
17767
17761
  };
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
- }
17762
+ const handleClearAll = e => {
17763
+ if (isDisabled) return;
17764
+ e.preventDefault();
17765
+ e.stopPropagation();
17766
+ setSelected([]);
17767
+ setRawInput(null);
17785
17768
  setIsOpen(false);
17786
- setFirstSuggestion('');
17769
+ setValue?.(name, undefined);
17770
+ form.trigger(name);
17787
17771
  inputRef.current?.focus();
17788
- setStatus('basic');
17789
- useFormResult.clearErrors(name);
17790
- useFormResult.trigger(name);
17791
- onChange?.(changingValue, isNewSelected);
17772
+ onClearAll?.();
17773
+ onEmptyChange?.(true);
17792
17774
  };
17793
- const handleClearAll = event => {
17794
- if (isDisabled) {
17775
+ const handleInputChange = e => {
17776
+ const input = e.target.value;
17777
+ setRawInput(input);
17778
+ if (!autoSelect || !filterOptions) return;
17779
+ const match = findExactMatch(input, optionsWithKey);
17780
+ if (match) {
17781
+ handleChange({
17782
+ value: match.value,
17783
+ shouldClose: false
17784
+ });
17795
17785
  return;
17796
17786
  }
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?.();
17787
+ // unset selected value if not fully matched
17788
+ if (!isMultiple && selectedItems.length > 0) {
17789
+ handleChange({
17790
+ value: selectedItems[0],
17791
+ shouldClose: false,
17792
+ resetInput: false
17793
+ });
17794
+ }
17806
17795
  };
17807
- const handleInputClick = event => {
17796
+ const handleInputClick = e => {
17797
+ e.stopPropagation();
17798
+ e.preventDefault();
17808
17799
  if (!isDisabled) {
17809
17800
  inputRef.current?.focus();
17810
17801
  setIsOpen(true);
17811
17802
  }
17812
- event.stopPropagation();
17813
- event.preventDefault();
17814
17803
  };
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}`);
17804
+ const handleInputKeyDown = e => {
17805
+ const isEnterOrTab = ['Enter', 'Tab'].includes(e.code);
17806
+ if (isEnterOrTab && firstSuggestion && firstSuggestion !== inputValue) {
17807
+ const match = findExactMatch(firstSuggestion, optionsWithKey);
17808
+ if (match) {
17809
+ handleChange({
17810
+ value: match.value
17811
+ });
17826
17812
  }
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) {
17813
+ e.preventDefault();
17814
+ return;
17815
+ }
17816
+ if (isMultiple && e.code === 'Backspace' && selectedItems.length && !inputValue) {
17817
+ const lastSelected = selectedItems[selectedItems.length - 1];
17818
+ handleChange({
17819
+ value: lastSelected,
17820
+ shouldClose: false
17821
+ });
17822
+ e.preventDefault();
17823
+ return;
17824
+ }
17825
+ if (!isOpen && firstSuggestion !== inputValue) {
17834
17826
  setIsOpen(true);
17835
17827
  }
17836
17828
  };
17837
- const handleInputChange = event => {
17838
- setInputValue(event.target.value);
17839
- };
17840
- const handleSelectedClick = event => {
17841
- event.stopPropagation();
17829
+ const handleRemoveSelectedClick = value => e => {
17830
+ e.stopPropagation();
17831
+ handleChange({
17832
+ value
17833
+ });
17834
+ onRemoveSelectedClick?.(value);
17835
+ form.trigger(name);
17842
17836
  };
17843
- const handleRemoveSelectedClick = selectedItem => event => {
17844
- event.stopPropagation();
17845
- handleChange(selectedItem);
17846
- onRemoveSelectedClick?.(selectedItem);
17837
+ const handleOpenChange = (open, event, reason) => {
17838
+ if (isDisabled || reason === 'reference-press') {
17839
+ return;
17840
+ }
17841
+ setIsOpen(open);
17842
+ if (!isMultiple && selectedItems.length > 0) {
17843
+ const selectedValue = selectedItems[0];
17844
+ const label = optionsWithKey[selectedValue]?.label;
17845
+ setRawInput(label ? String(label) : null);
17846
+ return;
17847
+ }
17848
+ setRawInput(null);
17847
17849
  };
17850
+ const status = (() => {
17851
+ if (form.formState.errors[name]) return 'error';
17852
+ if (error) return 'error';
17853
+ if (success) return 'success';
17854
+ return 'basic';
17855
+ })();
17848
17856
  return {
17849
17857
  isOpen,
17850
17858
  isDisabled,
17851
17859
  optionsWithKey,
17852
- selectedItems: selected,
17860
+ selectedItems,
17853
17861
  inputRef,
17854
17862
  firstSuggestion,
17855
17863
  isMultiple,
@@ -17865,18 +17873,18 @@ const useTypeahead = ({
17865
17873
  inputValue,
17866
17874
  validationSchema,
17867
17875
  status,
17876
+ error: error ?? form.formState.errors[name],
17868
17877
  placeholder,
17869
17878
  options: items,
17870
- useFormResult,
17879
+ useFormResult: form,
17871
17880
  register,
17872
17881
  setValue,
17873
- handleChange,
17882
+ onChange,
17874
17883
  handleClearAll,
17875
17884
  handleOpenChange,
17876
17885
  handleInputChange,
17877
17886
  handleInputClick,
17878
17887
  handleInputKeyDown,
17879
- handleSelectedClick,
17880
17888
  handleRemoveSelectedClick
17881
17889
  };
17882
17890
  };
@@ -17940,7 +17948,7 @@ const TypeaheadInputsGroupWrapper = /*#__PURE__*/base_default()(Wrapper_Wrapper,
17940
17948
  }) => isOpen ? '50px' : 'auto', ";flex-direction:column!important;" + ( true ? "" : 0));
17941
17949
  const TypeaheadTrigger = /*#__PURE__*/base_default()(PopoverTrigger, true ? {
17942
17950
  target: "e1vig1dw0"
17943
- } : 0)("position:relative;border-radius:8px;border:1px solid ", ({
17951
+ } : 0)("position:relative;border-radius:12px;border:1px solid ", ({
17944
17952
  status,
17945
17953
  theme
17946
17954
  }) => status === 'basic' ? theme.colors.grey : status === 'error' ? theme.colors.red : theme.colors.greenLighter, ";min-height:44px;height:auto;background:#fff;gap:8px;padding:5px 28px 5px 8px;width:100%;flex-wrap:wrap;border-color:", ({
@@ -17990,7 +17998,7 @@ const MultipleTrigger = () => {
17990
17998
  const theme = (0,react_namespaceObject.useTheme)();
17991
17999
  const context = useTypeaheadContext();
17992
18000
  const typeaheadInputAdditionalProps = {};
17993
- if (!context.selectedItems.length && !!context.placeholder) {
18001
+ if (!context.selectedItems.length && !context.inputValue && !!context.placeholder) {
17994
18002
  typeaheadInputAdditionalProps.placeholder = context.placeholder;
17995
18003
  }
17996
18004
  return (0,jsx_runtime_namespaceObject.jsxs)((external_react_default()).Fragment, {
@@ -17998,7 +18006,7 @@ const MultipleTrigger = () => {
17998
18006
  const currentOption = context.optionsWithKey[selectedItem];
17999
18007
  const optionText = currentOption ? currentOption.children || currentOption.label || currentOption.value : '';
18000
18008
  return (0,jsx_runtime_namespaceObject.jsxs)(TypeaheadItem, {
18001
- onClick: context.handleSelectedClick,
18009
+ onClick: e => e.stopPropagation(),
18002
18010
  isDisabled: context.isDisabled,
18003
18011
  children: [(0,jsx_runtime_namespaceObject.jsx)(TypeaheadItemLabel, {
18004
18012
  isDisabled: context.isDisabled,
@@ -18042,11 +18050,6 @@ const MultipleTrigger = () => {
18042
18050
  disabled: context.isDisabled,
18043
18051
  className: ['typeahead-input', TypeaheadInput(theme), TypeaheadInputPlaceholder].join(' '),
18044
18052
  ...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)
18050
18053
  })]
18051
18054
  }), !context.isDisabled && context.selectedItems.length ? (0,jsx_runtime_namespaceObject.jsx)(Button_Button, {
18052
18055
  variant: "tertiary",
@@ -18073,7 +18076,7 @@ const SingleTrigger = () => {
18073
18076
  const context = useTypeaheadContext();
18074
18077
  const theme = (0,react_namespaceObject.useTheme)();
18075
18078
  const typeaheadInputAdditionalProps = {};
18076
- if (!context.selectedItems.length && !!context.placeholder) {
18079
+ if (!context.selectedItems.length && !context.inputValue && !!context.placeholder) {
18077
18080
  typeaheadInputAdditionalProps.placeholder = context.placeholder;
18078
18081
  }
18079
18082
  return (0,jsx_runtime_namespaceObject.jsxs)(TypeaheadInputsGroupWrapper, {
@@ -18102,11 +18105,6 @@ const SingleTrigger = () => {
18102
18105
  tabIndex: -1,
18103
18106
  className: ['typeahead-input', TypeaheadInput(theme), TypeaheadInputPlaceholder].join(' '),
18104
18107
  ...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)
18110
18108
  }), !context.isDisabled && context.selectedItems.length ? (0,jsx_runtime_namespaceObject.jsx)(Button_Button, {
18111
18109
  variant: "tertiary",
18112
18110
  "data-testid": "remove-all-button",
@@ -18213,6 +18211,7 @@ const Typeahead = ({
18213
18211
  name = 'typeahead-search',
18214
18212
  label,
18215
18213
  selectedItems,
18214
+ defaultSelectedItems,
18216
18215
  isOpen,
18217
18216
  isDisabled,
18218
18217
  isMultiple,
@@ -18230,8 +18229,6 @@ const Typeahead = ({
18230
18229
  optionsClassName,
18231
18230
  wrapperClassName,
18232
18231
  width = 300,
18233
- setValue,
18234
- register,
18235
18232
  onChange,
18236
18233
  onEmptyChange,
18237
18234
  onClearAll,
@@ -18242,6 +18239,7 @@ const Typeahead = ({
18242
18239
  const hookResult = useTypeahead({
18243
18240
  name,
18244
18241
  selectedItems,
18242
+ defaultSelectedItems,
18245
18243
  isOpen,
18246
18244
  isDisabled,
18247
18245
  isMultiple,
@@ -18255,8 +18253,6 @@ const Typeahead = ({
18255
18253
  success,
18256
18254
  validationSchema,
18257
18255
  placeholder,
18258
- setValue,
18259
- register,
18260
18256
  onChange,
18261
18257
  onEmptyChange,
18262
18258
  renderOption,
@@ -18304,7 +18300,7 @@ const Typeahead = ({
18304
18300
  status: hookResult.status,
18305
18301
  disabled: isDisabled,
18306
18302
  "data-testid": "helper-text",
18307
- children: error ? error?.message : helperText
18303
+ children: hookResult.error ? hookResult.error?.message?.toString() : helperText
18308
18304
  })]
18309
18305
  })
18310
18306
  });
@@ -19182,6 +19178,7 @@ const SelectWidget = props => {
19182
19178
  placeholder,
19183
19179
  onChange,
19184
19180
  onBlur,
19181
+ onFocus,
19185
19182
  onChangeOverride,
19186
19183
  value
19187
19184
  } = props;
@@ -19196,43 +19193,44 @@ const SelectWidget = props => {
19196
19193
  const handleBlur = ({
19197
19194
  target
19198
19195
  }) => onBlur(id, target && target.value);
19196
+ const handleFocus = ({
19197
+ target
19198
+ }) => onFocus(id, target && target.value);
19199
19199
  const onEmptyChange = isEmpty => {
19200
19200
  if (isEmpty) {
19201
19201
  handleChange();
19202
19202
  }
19203
19203
  };
19204
- const register = fieldName => ({
19205
- onBlur: handleBlur,
19206
- onChange: handleChange,
19207
- name: fieldName,
19208
- ref: () => {}
19209
- });
19210
19204
  const items = Array.isArray(enumOptions) ? enumOptions : [];
19211
19205
  const selectedItems = selectedIndex ? [items[Number(selectedIndex)].value] : [];
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))
19206
+ return (0,jsx_runtime_namespaceObject.jsx)("div", {
19207
+ id: id,
19208
+ onBlur: handleBlur,
19209
+ onFocus: handleFocus,
19210
+ children: (0,jsx_runtime_namespaceObject.jsx)(Typeahead, {
19211
+ width: "100%",
19212
+ selectedItems: selectedItems,
19213
+ isDisabled: disabled,
19214
+ name: name
19215
+ // RJSF provides placeholder as empty string
19216
+ ,
19217
+ placeholder: placeholder || undefined,
19218
+ onChange: handleChange,
19219
+ onEmptyChange: onEmptyChange,
19220
+ renderOption: ({
19221
+ label,
19222
+ input
19223
+ }) => highlightInputMatch(label, input),
19224
+ children: items.map(({
19225
+ label,
19226
+ value
19227
+ }) => (0,jsx_runtime_namespaceObject.jsx)(TypeaheadOption_TypeaheadOption, {
19228
+ value: value,
19229
+ label: label || value,
19230
+ isDisabled: disabled || Array.isArray(enumDisabled) && enumDisabled.includes(value),
19231
+ children: label || value
19232
+ }, value))
19233
+ })
19236
19234
  });
19237
19235
  };
19238
19236
  ;// ./src/components/JsonSchemaForm/widgets/PasswordWidget.tsx