hplx-react-elements-dev 1.1.7 → 1.1.8

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/esm/index.js CHANGED
@@ -5625,9 +5625,10 @@ $$5({ target: 'String', proto: true, forced: forcedStringTrimMethod('trim') }, {
5625
5625
  var AddSuggestion = function AddSuggestion(_a) {
5626
5626
  var label = _a.label,
5627
5627
  _b = _a.handleSuggestionValChange,
5628
- handleSuggestionValChange = _b === void 0 ? function (_) {} : _b,
5628
+ handleSuggestionValChange = _b === void 0 ? function (_, _fromEvent) {
5629
+ } : _b,
5629
5630
  _c = _a.onSuggestionClick,
5630
- onSuggestionClick = _c === void 0 ? function (_selectedValue) {} : _c,
5631
+ onSuggestionClick = _c === void 0 ? function (_selectedValue, _index, _searchString) {} : _c,
5631
5632
  className = _a.className,
5632
5633
  _d = _a.rows,
5633
5634
  rows = _d === void 0 ? 2 : _d,
@@ -5650,7 +5651,7 @@ var AddSuggestion = function AddSuggestion(_a) {
5650
5651
 
5651
5652
  var wrapperRef = useRef(null);
5652
5653
 
5653
- var _k = useState(),
5654
+ var _k = useState([]),
5654
5655
  suggestionArr = _k[0],
5655
5656
  setSuggestionArr = _k[1];
5656
5657
 
@@ -5658,6 +5659,10 @@ var AddSuggestion = function AddSuggestion(_a) {
5658
5659
  sugVal = _l[0],
5659
5660
  setSugVal = _l[1];
5660
5661
 
5662
+ var _m = useState(-1),
5663
+ focusIndex = _m[0],
5664
+ setFocusIndex = _m[1];
5665
+
5661
5666
  var suggestionText = function suggestionText(text) {
5662
5667
  // Find the last occurrence of comma, period, or newline
5663
5668
  var lastCommaIndex = text.lastIndexOf(",");
@@ -5705,6 +5710,8 @@ var AddSuggestion = function AddSuggestion(_a) {
5705
5710
  if (wrapperRef.current && !wrapperRef.current.contains(e.target)) {
5706
5711
  setShowDropdown(false);
5707
5712
  }
5713
+
5714
+ setFocusIndex(-1);
5708
5715
  }; // const checkComma = (val: string) => {
5709
5716
  // const lastEle = val.trim().charAt(sugVal.length - 1);
5710
5717
  // if (lastEle === "," || lastEle === "." || lastEle === "\n") {
@@ -5715,7 +5722,7 @@ var AddSuggestion = function AddSuggestion(_a) {
5715
5722
  // };
5716
5723
 
5717
5724
 
5718
- var handleSuggestionClick = function handleSuggestionClick(selectedItem) {
5725
+ var handleSuggestionClick = function handleSuggestionClick(selectedItem, index) {
5719
5726
  var val = selectedItem.value + ", ";
5720
5727
  var result = "";
5721
5728
 
@@ -5732,12 +5739,57 @@ var AddSuggestion = function AddSuggestion(_a) {
5732
5739
  val = result + " " + selectedItem.value + ", ";
5733
5740
  }
5734
5741
 
5735
- handleSuggestionValChange && handleSuggestionValChange(val);
5736
- onSuggestionClick(suggestionValue);
5742
+ handleSuggestionValChange && handleSuggestionValChange(val, "dropdown");
5743
+ onSuggestionClick(suggestionValue, index, suggestionText(suggestionValue)[1].trim());
5737
5744
  setSugVal(val);
5738
5745
  setShowDropdown(false);
5739
5746
  };
5740
5747
 
5748
+ var handleOnKeyDown = function handleOnKeyDown(e) {
5749
+ var ITEM_HEIGHT = 40;
5750
+
5751
+ if (e.code === "Enter" || e.code === "Period" || e.code === "Comma") {
5752
+ setShowDropdown(true);
5753
+ }
5754
+
5755
+ if (e.keyCode === 40) {
5756
+ if (focusIndex < suggestionArr.length - 1) {
5757
+ var focusI = focusIndex + 1;
5758
+
5759
+ if (wrapperRef && wrapperRef.current && focusI > 1) {
5760
+ wrapperRef.current.scrollBy(0, ITEM_HEIGHT);
5761
+ }
5762
+
5763
+ setFocusIndex(focusI);
5764
+ }
5765
+ } // on key up
5766
+
5767
+
5768
+ if (e.keyCode === 38) {
5769
+ if (focusIndex > 0) {
5770
+ var focusI = focusIndex - 1;
5771
+
5772
+ if (wrapperRef && wrapperRef.current && focusI < suggestionArr.length - 2) {
5773
+ wrapperRef.current.scrollBy(0, -ITEM_HEIGHT);
5774
+ }
5775
+
5776
+ setFocusIndex(focusI);
5777
+ }
5778
+ }
5779
+
5780
+ if (e.keyCode === 13 || e.keyCode === 9) {
5781
+ e.preventDefault();
5782
+
5783
+ if (focusIndex >= 0) {
5784
+ // const res = [suggestionArr[focusIndex].value.trim()];
5785
+ // setValue(res.filter(Boolean).join(", "));
5786
+ // setTagInputValue("");
5787
+ setFocusIndex(-1);
5788
+ handleSuggestionClick(suggestionArr[focusIndex], focusIndex);
5789
+ }
5790
+ }
5791
+ };
5792
+
5741
5793
  useEffect(function () {
5742
5794
  setSugVal(suggestionValue);
5743
5795
  }, [suggestionValue]); // Attaching the previous event with UseEffect hook
@@ -5763,12 +5815,12 @@ var AddSuggestion = function AddSuggestion(_a) {
5763
5815
  isDynamicHeight: isDynamicHeight,
5764
5816
  inputProps: __assign(__assign({}, inputProps), {
5765
5817
  onChange: changeHandler,
5766
- value: sugVal.replace(/<br \/>/g, ''),
5818
+ value: sugVal.replace(/<br \/>/g, ""),
5767
5819
  onFocus: function onFocus() {
5768
5820
  return setShowDropdown(true);
5769
5821
  },
5770
5822
  onKeyDown: function onKeyDown(e) {
5771
- if (e.code === "Enter" || e.code === "Period" || e.code === "Comma") setShowDropdown(true);
5823
+ handleOnKeyDown(e);
5772
5824
  }
5773
5825
  })
5774
5826
  }), showDropdown && jsxRuntime.exports.jsx("div", __assign({
@@ -5776,14 +5828,14 @@ var AddSuggestion = function AddSuggestion(_a) {
5776
5828
  className: "hplxt-absolute hplxt-border hplxt-border-Gray-300 hplxt-mt-1 hplxt-min-w-max hplxt-rounded-lg hplxt-bg-Indigo-25 hplxt-overflow-y-auto hplxt-shadow-md hplxt-z-10 hplxt-max-h-80 "
5777
5829
  }, {
5778
5830
  children: suggestionArr && suggestionArr.length > 0 && jsxRuntime.exports.jsx("div", {
5779
- children: (suggestionArr === null || suggestionArr === void 0 ? void 0 : suggestionArr.constructor) === Array && suggestionArr.length ? suggestionArr.map(function (option) {
5831
+ children: (suggestionArr === null || suggestionArr === void 0 ? void 0 : suggestionArr.constructor) === Array && suggestionArr.length ? suggestionArr.map(function (option, index) {
5780
5832
  var restOptions = __rest(option || {}, []);
5781
5833
 
5782
5834
  return jsxRuntime.exports.jsx(DropdownItems, __assign({
5783
- className: "hplxt-text-Primary-700"
5835
+ className: "hplxt-text-Primary-700 ".concat(index === focusIndex ? "hplxt-bg-Blue_gray-100 hplxt-font-inter-1" : "")
5784
5836
  }, restOptions, {
5785
5837
  onSelect: function onSelect() {
5786
- return handleSuggestionClick(restOptions);
5838
+ return handleSuggestionClick(restOptions, index);
5787
5839
  }
5788
5840
  }));
5789
5841
  }) : null
@@ -407,10 +407,10 @@ export interface AddSuggestionProps {
407
407
  inputFieldInputProps?: React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>;
408
408
  suffixInputProps?: React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>;
409
409
  suffixClassName?: string;
410
- onSuggestionClick?: (selectedValue: any) => void;
410
+ onSuggestionClick?: (selectedValue: any, index?: number, _searchString?: string) => void;
411
411
  options?: Array<DropdownItemsProps>;
412
412
  suggestionValue?: string;
413
- handleSuggestionValChange?: (value: any) => void;
413
+ handleSuggestionValChange?: (value: any, fromEvent?: string) => void;
414
414
  handleSuffixValChange?: (value: any) => void;
415
415
  isborderRequired?: boolean;
416
416
  getInputValue?: (value: string) => void;
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "frontend",
10
10
  "healthplix"
11
11
  ],
12
- "version": "1.1.7",
12
+ "version": "1.1.8",
13
13
  "main": "dist/esm/index.js",
14
14
  "module": "dist/esm/index.js",
15
15
  "types": "dist/esm/index.d.ts",