@bolttech/molecules-dropdown 0.22.1 → 0.23.0

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/README.md CHANGED
@@ -67,6 +67,7 @@ The **Dropdown** component accepts the following props:
67
67
  | `onFocus` | `function` | Callback function triggered when the dropdown is focused. |
68
68
  | `placeholder` | `string` | Placeholder text for the input. |
69
69
  | `disableSearch` | `boolean` | Boolean that represent if we should disable user searching on the dropdown. Defaults to false |
70
+ | `selectMaxHeight` | `string` | An optional string to indicate the select height |
70
71
 
71
72
  ## Functionality
72
73
 
package/index.cjs CHANGED
@@ -2475,11 +2475,17 @@ const ReusableDropdownComponent = _a => {
2475
2475
  "$hasError": hasError,
2476
2476
  disabled: disabled,
2477
2477
  "data-testid": `${dataTestId}-dropdown-container`,
2478
+ onMouseDown: e => {
2479
+ var _a, _b;
2480
+ e.preventDefault();
2481
+ if (showSelectComponent === false) {
2482
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
2483
+ } else {
2484
+ (_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.blur();
2485
+ }
2486
+ },
2478
2487
  children: [jsxRuntime.jsxs(ContentDropdown, {
2479
2488
  children: [label && jsxRuntime.jsxs(FieldLabelAndRequiredLabelDropdown, {
2480
- onClick: () => {
2481
- setShowSelectComponent(disabled ? false : !showSelectComponent);
2482
- },
2483
2489
  children: [jsxRuntime.jsx("label", {
2484
2490
  htmlFor: `${id}-input`,
2485
2491
  className: "fieldLabel",
@@ -2524,15 +2530,10 @@ const ReusableDropdownComponent = _a => {
2524
2530
  }, uiUtils.applyDataAttributes(props, 'input')))
2525
2531
  })]
2526
2532
  }), jsxRuntime.jsx(ClickableElement, {
2527
- onClick: () => {
2528
- if (!disabled) {
2529
- setShowSelectComponent(!showSelectComponent);
2530
- }
2531
- },
2532
2533
  children: jsxRuntime.jsx(atomsIcon.Icon, {
2533
2534
  dataTestId: `${dataTestId}-icon`,
2534
2535
  size: sizeIcon,
2535
- icon: !showSelectComponent ? 'keyboard_arrow_down' : 'keyboard_arrow_up'
2536
+ icon: showSelectComponent ? 'keyboard_arrow_up' : 'keyboard_arrow_down'
2536
2537
  })
2537
2538
  })]
2538
2539
  }), !showSelectComponent && hasError && errorMessage && jsxRuntime.jsx("div", {
@@ -2688,9 +2689,11 @@ const Dropdown = /*#__PURE__*/react.forwardRef((_a, ref) => {
2688
2689
  onFocus,
2689
2690
  placeholder,
2690
2691
  onKeyUp,
2691
- onKeyDown
2692
+ onKeyDown,
2693
+ selectMaxHeight,
2694
+ disableSearch
2692
2695
  } = _a,
2693
- props = __rest(_a, ["label", "variant", "required", "optionList", "disabled", "errorMessage", "urlFilterOptions", "id", "dataTestId", "filterOptionsParam", "value", "onChange", "onBlur", "onFocus", "placeholder", "onKeyUp", "onKeyDown"]);
2696
+ props = __rest(_a, ["label", "variant", "required", "optionList", "disabled", "errorMessage", "urlFilterOptions", "id", "dataTestId", "filterOptionsParam", "value", "onChange", "onBlur", "onFocus", "placeholder", "onKeyUp", "onKeyDown", "selectMaxHeight", "disableSearch"]);
2694
2697
  const [isFirstRender, setIsFirstRender] = react.useState(true);
2695
2698
  const [showSelectComponent, setShowSelectComponent] = react.useState(false);
2696
2699
  const [currentOptionList, setCurrentOptionList] = react.useState([]);
@@ -2733,12 +2736,14 @@ const Dropdown = /*#__PURE__*/react.forwardRef((_a, ref) => {
2733
2736
  const foundOption = optionList === null || optionList === void 0 ? void 0 : optionList.find(option => option.id === value);
2734
2737
  setInternalSelectedOption(foundOption);
2735
2738
  setInputValue((foundOption === null || foundOption === void 0 ? void 0 : foundOption.value) || '');
2736
- setInputLabel((foundOption === null || foundOption === void 0 ? void 0 : foundOption.label) || '');
2739
+ if (!onKeyUp && !onKeyDown) {
2740
+ setInputLabel((foundOption === null || foundOption === void 0 ? void 0 : foundOption.label) || '');
2741
+ }
2737
2742
  }
2738
2743
  if (!isFirstRender || currentOptionList.length === 0) return;
2739
2744
  setInternalSelectedOption(currentOptionList.find(option => option.id === value));
2740
2745
  setIsFirstRender(false);
2741
- }, [currentOptionList, setSelectedOptionOnInputValue, value, internalSelectedOption, optionList, isFirstRender]);
2746
+ }, [currentOptionList, setSelectedOptionOnInputValue, value, internalSelectedOption, optionList, isFirstRender, onKeyUp, onKeyDown]);
2742
2747
  return jsxRuntime.jsxs(SectionContainer, Object.assign({
2743
2748
  "$variant": variant,
2744
2749
  id: `${id}-container`,
@@ -2746,11 +2751,7 @@ const Dropdown = /*#__PURE__*/react.forwardRef((_a, ref) => {
2746
2751
  style: {
2747
2752
  maxWidth: (_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.style.width
2748
2753
  },
2749
- ref: ref,
2750
- onClick: () => {
2751
- var _a;
2752
- return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
2753
- }
2754
+ ref: ref
2754
2755
  }, uiUtils.applyDataAttributes(props), {
2755
2756
  children: [jsxRuntime.jsx(ReusableDropdownComponent, Object.assign({
2756
2757
  id: id,
@@ -2772,23 +2773,27 @@ const Dropdown = /*#__PURE__*/react.forwardRef((_a, ref) => {
2772
2773
  onBlur: onBlur,
2773
2774
  onFocus: onFocus,
2774
2775
  onKeyUp: onKeyUp,
2775
- onKeyDown: onKeyDown
2776
+ onKeyDown: onKeyDown,
2777
+ disableSearch: disableSearch
2776
2778
  }, props)), showSelectComponent && !disabled && jsxRuntime.jsx(DropdownOptionsContainer, {
2777
2779
  children: jsxRuntime.jsx(atomsSelect.Select, Object.assign({
2778
2780
  id: `${id}-select`,
2779
2781
  dataTestId: `${dataTestId}-select`,
2780
2782
  onChange: selectedValue => {
2781
2783
  var _a;
2782
- setInputValue(selectedValue.value);
2783
- setInputLabel(selectedValue.label);
2784
- setInternalSelectedOption(Object.assign({}, selectedValue));
2785
- reactDom.flushSync(() => {
2786
- onChange(selectedValue);
2787
- });
2788
- (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur();
2784
+ if (!selectedValue.disabled) {
2785
+ setInputValue(selectedValue.value);
2786
+ setInputLabel(selectedValue.label);
2787
+ setInternalSelectedOption(Object.assign({}, selectedValue));
2788
+ reactDom.flushSync(() => {
2789
+ onChange(selectedValue);
2790
+ });
2791
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur();
2792
+ }
2789
2793
  },
2790
2794
  active: internalSelectedOption,
2791
- options: currentOptionList
2795
+ options: currentOptionList,
2796
+ maxHeight: selectMaxHeight
2792
2797
  }, uiUtils.applyDataAttributes(props, 'select')))
2793
2798
  })]
2794
2799
  }));
@@ -2811,9 +2816,11 @@ const DropdownWithHeaders = /*#__PURE__*/react.forwardRef((_a, ref) => {
2811
2816
  onFocus,
2812
2817
  placeholder,
2813
2818
  onKeyUp,
2814
- onKeyDown
2819
+ onKeyDown,
2820
+ selectMaxHeight,
2821
+ disableSearch
2815
2822
  } = _a,
2816
- props = __rest(_a, ["label", "variant", "required", "optionList", "disabled", "errorMessage", "urlFilterOptions", "dataTestId", "filterOptionsParam", "value", "onChange", "onBlur", "onFocus", "placeholder", "onKeyUp", "onKeyDown"]);
2823
+ props = __rest(_a, ["label", "variant", "required", "optionList", "disabled", "errorMessage", "urlFilterOptions", "dataTestId", "filterOptionsParam", "value", "onChange", "onBlur", "onFocus", "placeholder", "onKeyUp", "onKeyDown", "selectMaxHeight", "disableSearch"]);
2817
2824
  const [isFirstRender, setIsFirstRender] = react.useState(true);
2818
2825
  const [showSelectComponent, setShowSelectComponent] = react.useState(false);
2819
2826
  const [currentOptionList, setCurrentOptionList] = react.useState([]);
@@ -2860,7 +2867,9 @@ const DropdownWithHeaders = /*#__PURE__*/react.forwardRef((_a, ref) => {
2860
2867
  })[0]) || undefined;
2861
2868
  setInternalSelectedOption(option);
2862
2869
  setInputValue((option === null || option === void 0 ? void 0 : option.value) || '');
2863
- setInputLabel((option === null || option === void 0 ? void 0 : option.label) || '');
2870
+ if (!onKeyUp && !onKeyDown) {
2871
+ setInputLabel((option === null || option === void 0 ? void 0 : option.label) || '');
2872
+ }
2864
2873
  return;
2865
2874
  }
2866
2875
  if (!isFirstRender || currentOptionList.length === 0) return;
@@ -2868,12 +2877,8 @@ const DropdownWithHeaders = /*#__PURE__*/react.forwardRef((_a, ref) => {
2868
2877
  return optionsList.options.find(option => option.id === value);
2869
2878
  })[0] || undefined);
2870
2879
  setIsFirstRender(false);
2871
- }, [currentOptionList, value, optionList, internalSelectedOption === null || internalSelectedOption === void 0 ? void 0 : internalSelectedOption.id, isFirstRender]);
2880
+ }, [currentOptionList, value, optionList, internalSelectedOption === null || internalSelectedOption === void 0 ? void 0 : internalSelectedOption.id, isFirstRender, onKeyUp, onKeyDown]);
2872
2881
  return jsxRuntime.jsxs(SectionContainer, Object.assign({
2873
- onClick: () => {
2874
- var _a;
2875
- return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
2876
- },
2877
2882
  "$variant": variant,
2878
2883
  "data-testid": `${dataTestId}-container`,
2879
2884
  ref: ref
@@ -2897,7 +2902,8 @@ const DropdownWithHeaders = /*#__PURE__*/react.forwardRef((_a, ref) => {
2897
2902
  onBlur: onBlur,
2898
2903
  onFocus: onFocus,
2899
2904
  onKeyUp: onKeyUp,
2900
- onKeyDown: onKeyDown
2905
+ onKeyDown: onKeyDown,
2906
+ disableSearch: disableSearch
2901
2907
  }, props)), showSelectComponent && !disabled && jsxRuntime.jsx(DropdownOptionsContainer, {
2902
2908
  children: jsxRuntime.jsx(atomsSelect.SelectWithHeaders, Object.assign({
2903
2909
  dataTestId: `${dataTestId}-select`,
@@ -2912,7 +2918,8 @@ const DropdownWithHeaders = /*#__PURE__*/react.forwardRef((_a, ref) => {
2912
2918
  (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur();
2913
2919
  },
2914
2920
  active: internalSelectedOption,
2915
- options: currentOptionList
2921
+ options: currentOptionList,
2922
+ maxHeight: selectMaxHeight
2916
2923
  }, uiUtils.applyDataAttributes(props, 'select')))
2917
2924
  })]
2918
2925
  }));
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@bolttech/molecules-dropdown",
3
- "version": "0.22.1",
3
+ "version": "0.23.0",
4
4
  "main": "./index.cjs",
5
5
  "type": "commonjs",
6
6
  "types": "./src/index.d.ts",
7
7
  "dependencies": {
8
8
  "@bolttech/atoms-icon": "0.22.1",
9
9
  "@bolttech/atoms-input": "0.21.1",
10
- "@bolttech/atoms-select": "0.19.3",
11
- "@bolttech/default-theme": "0.1.1",
10
+ "@bolttech/atoms-select": "0.1.0",
11
+ "@bolttech/default-theme": "0.3.0",
12
12
  "@bolttech/form-engine": "0.5.0",
13
13
  "@bolttech/frontend-foundations": "0.3.1",
14
- "@bolttech/ui-utils": "0.2.2",
14
+ "@bolttech/ui-utils": "0.2.3",
15
15
  "react": "18.2.0",
16
16
  "react-dom": "18.2.0",
17
17
  "styled-components": "6.1.1"
@@ -10,6 +10,7 @@ export declare const DropdownWithHeaders: import("react").ForwardRefExoticCompon
10
10
  required?: boolean | undefined;
11
11
  variant?: import("./molecules-dropdown.type").StyleVariants | undefined;
12
12
  disableSearch?: boolean | undefined;
13
+ selectMaxHeight?: string | undefined;
13
14
  onBlur?: ((value?: unknown) => void) | ((evt: import("react").FocusEvent<HTMLElement, Element>) => void) | undefined;
14
15
  onFocus?: ((value?: unknown) => void) | ((evt: import("react").FocusEvent<HTMLElement, Element>) => void) | undefined;
15
16
  } & {
@@ -10,6 +10,7 @@ export declare const Dropdown: import("react").ForwardRefExoticComponent<Pick<im
10
10
  required?: boolean | undefined;
11
11
  variant?: import("./molecules-dropdown.type").StyleVariants | undefined;
12
12
  disableSearch?: boolean | undefined;
13
+ selectMaxHeight?: string | undefined;
13
14
  onBlur?: ((value?: unknown) => void) | ((evt: import("react").FocusEvent<HTMLElement, Element>) => void) | undefined;
14
15
  onFocus?: ((value?: unknown) => void) | ((evt: import("react").FocusEvent<HTMLElement, Element>) => void) | undefined;
15
16
  } & {
@@ -17,6 +17,7 @@ Default props for Dropdown component
17
17
  @property required - An optional boolean to indicate if the dropdown is required
18
18
  @property variant - An optional string to set the variant of the dropdown
19
19
  @property disableSearch - An optional boolean representing if the user can type and mobile phones should show the keyboard
20
+ @property selectMaxHeight - An optional string to indicate the select height
20
21
  */
21
22
  type DefaultDropdownProps = {
22
23
  label: string;
@@ -28,6 +29,7 @@ type DefaultDropdownProps = {
28
29
  required?: boolean;
29
30
  variant?: StyleVariants;
30
31
  disableSearch?: boolean;
32
+ selectMaxHeight?: string;
31
33
  onBlur?: ((value?: unknown) => void) | ((evt: React.FocusEvent<HTMLElement, Element>) => void);
32
34
  onFocus?: ((value?: unknown) => void) | ((evt: React.FocusEvent<HTMLElement, Element>) => void);
33
35
  };
@@ -170,7 +172,7 @@ export type DropdownWithHeadersProps = Pick<DOMAttributes<HTMLInputElement>, 'on
170
172
  @property setSelectedOptionOnInputValue - A function to set the selected option based on the input value
171
173
  @property inputRef - A ref to the input element of the dropdown
172
174
  */
173
- export type ReusableDropdownComponentProps = DefaultProps & Pick<DOMAttributes<HTMLInputElement>, 'onKeyUp' | 'onKeyDown'> & DefaultDropdownProps & {
175
+ export type ReusableDropdownComponentProps = DefaultProps & Pick<DOMAttributes<HTMLInputElement>, 'onKeyUp' | 'onKeyDown'> & Omit<DefaultDropdownProps, 'selectMaxHeight'> & {
174
176
  setShowSelectComponent: React.Dispatch<React.SetStateAction<boolean>>;
175
177
  showSelectComponent: boolean;
176
178
  onChangeInputValue: React.Dispatch<React.SetStateAction<string>>;