@razorpay/blade 10.13.0 → 10.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5452,6 +5452,7 @@ declare const SelectInput: React__default.ForwardRefExoticComponent<(({
5452
5452
  name?: string | undefined;
5453
5453
  values: string[];
5454
5454
  }) => void) | undefined;
5455
+ syncInputValueWithSelection?: ((value: string) => void) | undefined;
5455
5456
  maxRows?: "multiple" | "single" | "expandable" | undefined;
5456
5457
  labelPosition?: "left" | "top" | "inside-input" | undefined;
5457
5458
  }) & React__default.RefAttributes<BladeElementRef>>;
@@ -5510,6 +5511,7 @@ declare const AutoComplete: React__default.ForwardRefExoticComponent<Pick<BaseIn
5510
5511
  name?: string | undefined;
5511
5512
  values: string[];
5512
5513
  }) => void) | undefined;
5514
+ syncInputValueWithSelection?: ((value: string) => void) | undefined;
5513
5515
  maxRows?: "multiple" | "single" | "expandable" | undefined;
5514
5516
  labelPosition?: "left" | "top" | "inside-input" | undefined;
5515
5517
  } & {
@@ -5534,6 +5536,12 @@ declare type DropdownInputTriggersCommonProps = Pick<BaseInputProps, 'label' | '
5534
5536
  name?: string;
5535
5537
  values: string[];
5536
5538
  }) => void;
5539
+ /**
5540
+ * Syncs the selected value to inputValue in AutoComplete
5541
+ *
5542
+ * Only needed in single select AutoComplete because inputValue is expected to be same as selected value there
5543
+ */
5544
+ syncInputValueWithSelection?: (value: string) => void;
5537
5545
  /**
5538
5546
  * constraints the height of input to given number rows
5539
5547
  *
@@ -13853,7 +13853,8 @@ var makeInputDisplayValue = function makeInputDisplayValue(selectedIndices, opti
13853
13853
 
13854
13854
  // When one item is selected, we display that item's title in input
13855
13855
  if (selectedIndices.length === 1) {
13856
- return options[selectedIndices[0]].title;
13856
+ var _options$selectedIndi;
13857
+ return (_options$selectedIndi = options[selectedIndices[0]]) === null || _options$selectedIndi === void 0 ? void 0 : _options$selectedIndi.title;
13857
13858
  }
13858
13859
 
13859
13860
  // When more than one item is selected, we display the count of items
@@ -23674,6 +23675,12 @@ var useControlledDropdownInput = function useControlledDropdownInput(props) {
23674
23675
  setIsControlled(true);
23675
23676
  }
23676
23677
  selectValues(props.value);
23678
+
23679
+ // in single select AutoComplete, we have to set inputValue of autocomplete according to the new selection.
23680
+ if (selectionType === 'single' && !Array.isArray(props.value) && !props.isSelectInput) {
23681
+ var _props$syncInputValue;
23682
+ (_props$syncInputValue = props.syncInputValueWithSelection) === null || _props$syncInputValue === void 0 ? void 0 : _props$syncInputValue.call(props, props.value);
23683
+ }
23677
23684
  }
23678
23685
  // eslint-disable-next-line react-hooks/exhaustive-deps
23679
23686
  }, [props.value, options]);
@@ -23735,7 +23742,9 @@ var _BaseDropdownInputTrigger = function _BaseDropdownInputTrigger(props, ref) {
23735
23742
  onChange: props.onChange,
23736
23743
  name: props.name,
23737
23744
  value: props.value,
23738
- defaultValue: props.defaultValue
23745
+ defaultValue: props.defaultValue,
23746
+ syncInputValueWithSelection: props.syncInputValueWithSelection,
23747
+ isSelectInput: props.isSelectInput
23739
23748
  });
23740
23749
  var getValue = function getValue() {
23741
23750
  var prefix = '';
@@ -23987,7 +23996,7 @@ var useAutoComplete = function useAutoComplete(_ref) {
23987
23996
  setActiveIndex(firstItemOptionIndex);
23988
23997
  }
23989
23998
  // eslint-disable-next-line react-hooks/exhaustive-deps
23990
- }, [globalFilteredValues.length]);
23999
+ }, [globalFilteredValues.length, options.length]);
23991
24000
 
23992
24001
  // When input is empty or its single select, we want all items to be shown in filter on open of dropdown
23993
24002
  React__default.useEffect(function () {
@@ -24028,7 +24037,7 @@ var useAutoComplete = function useAutoComplete(_ref) {
24028
24037
  // eslint-disable-next-line no-lonely-if
24029
24038
  if (value && options && options.length > 0) {
24030
24039
  var filteredOptions = getOptionValues().filter(function (optionValue) {
24031
- return optionValue.toLowerCase().startsWith(value.toLowerCase());
24040
+ return optionValue.toLowerCase().includes(value.toLowerCase());
24032
24041
  });
24033
24042
  setGlobalFilteredValues(filteredOptions);
24034
24043
  } else {
@@ -24138,6 +24147,17 @@ var _AutoComplete = function _AutoComplete(props, ref) {
24138
24147
  onChange: onSelectionChange,
24139
24148
  isSelectInput: false,
24140
24149
  inputValue: inputValue,
24150
+ syncInputValueWithSelection: function syncInputValueWithSelection(value) {
24151
+ var _selectedOption$title;
24152
+ if (!value) {
24153
+ setInputValue('');
24154
+ return;
24155
+ }
24156
+ var selectedOption = options.find(function (option) {
24157
+ return option.value === value;
24158
+ });
24159
+ setInputValue((_selectedOption$title = selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.title) !== null && _selectedOption$title !== void 0 ? _selectedOption$title : '');
24160
+ },
24141
24161
  onTriggerKeydown: onTriggerKeydown,
24142
24162
  onInputValueChange: onInputValueChange,
24143
24163
  onTriggerClick: function onTriggerClick(triggerEvent) {