@bolttech/molecules-dropdown 0.31.1 → 0.32.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/index.cjs CHANGED
@@ -135,10 +135,10 @@ var SHARED = '__core-js_shared__';
135
135
  var store$3 = sharedStore.exports = globalThis$e[SHARED] || defineGlobalProperty$2(SHARED, {});
136
136
 
137
137
  (store$3.versions || (store$3.versions = [])).push({
138
- version: '3.38.1',
138
+ version: '3.39.0',
139
139
  mode: 'global',
140
140
  copyright: '© 2014-2024 Denis Pushkarev (zloirock.ru)',
141
- license: 'https://github.com/zloirock/core-js/blob/v3.38.1/LICENSE',
141
+ license: 'https://github.com/zloirock/core-js/blob/v3.39.0/LICENSE',
142
142
  source: 'https://github.com/zloirock/core-js'
143
143
  });
144
144
 
@@ -237,9 +237,9 @@ var symbolConstructorDetection = !!Object.getOwnPropertySymbols && !fails$e(func
237
237
  /* eslint-disable es/no-symbol -- required for testing */
238
238
  var NATIVE_SYMBOL$1 = symbolConstructorDetection;
239
239
 
240
- var useSymbolAsUid = NATIVE_SYMBOL$1
241
- && !Symbol.sham
242
- && typeof Symbol.iterator == 'symbol';
240
+ var useSymbolAsUid = NATIVE_SYMBOL$1 &&
241
+ !Symbol.sham &&
242
+ typeof Symbol.iterator == 'symbol';
243
243
 
244
244
  var globalThis$a = globalThis_1;
245
245
  var shared$3 = shared$4;
@@ -2390,7 +2390,11 @@ const ContainerDropdown = /*#__PURE__*/styled__default["default"].section.withCo
2390
2390
  const SectionContainer = /*#__PURE__*/styled__default["default"].section.withConfig({
2391
2391
  displayName: "molecules-dropdownstyles__SectionContainer",
2392
2392
  componentId: "sc-3wugi4-2"
2393
- })(["position:relative;.errorMessage{padding-right:", ";padding-left:", ";label{color:", ";font-weight:", ";line-height:", ";font-size:", ";letter-spacing:", ";}}.helperMessage{padding-right:", ";padding-left:", ";margin-top:", ";label{color:", ";font-weight:", ";line-height:", ";font-size:", ";letter-spacing:", ";}}"], ({
2393
+ })(["position:relative;.top{top:-", ";transform:translateY(-100%);}.bottom{top:", ";}.errorMessage{padding-right:", ";padding-left:", ";label{color:", ";font-weight:", ";line-height:", ";font-size:", ";letter-spacing:", ";}}.helperMessage{padding-right:", ";padding-left:", ";margin-top:", ";label{color:", ";font-weight:", ";line-height:", ";font-size:", ";letter-spacing:", ";}}"], ({
2394
+ theme
2395
+ }) => theme.components.dropdown.borderWidth.default, ({
2396
+ theme
2397
+ }) => `calc(100% + ${theme.components.dropdown.borderWidth.default})`, ({
2394
2398
  theme
2395
2399
  }) => theme.components.dropdown.paddingHorizontal, ({
2396
2400
  theme
@@ -2440,10 +2444,6 @@ const FieldLabelAndRequiredLabelDropdown = /*#__PURE__*/styled__default["default
2440
2444
  })(["gap:", ";display:flex;"], ({
2441
2445
  theme
2442
2446
  }) => theme.components.dropdown.requiredGap);
2443
- const DropdownOptionsContainer = /*#__PURE__*/styled__default["default"].div.withConfig({
2444
- displayName: "molecules-dropdownstyles__DropdownOptionsContainer",
2445
- componentId: "sc-3wugi4-6"
2446
- })(["position:absolute;inset:0;top:calc(100% + 1px);"]);
2447
2447
 
2448
2448
  const ReusableDropdownComponent = _a => {
2449
2449
  var {
@@ -2519,12 +2519,11 @@ const ReusableDropdownComponent = _a => {
2519
2519
  var _a, _b;
2520
2520
  onChangeInputValue(((_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.value) || '');
2521
2521
  onChangeInputLabel(((_b = e === null || e === void 0 ? void 0 : e.target) === null || _b === void 0 ? void 0 : _b.value) || '');
2522
- setShowSelectComponent(true);
2523
2522
  },
2524
2523
  onFocus: event => {
2524
+ setShowSelectComponent(true);
2525
2525
  onChangeInputValue('');
2526
2526
  onChangeInputLabel('');
2527
- setShowSelectComponent(true);
2528
2527
  onFocus && onFocus(event);
2529
2528
  },
2530
2529
  onBlur: event => {
@@ -2533,8 +2532,8 @@ const ReusableDropdownComponent = _a => {
2533
2532
  (_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus();
2534
2533
  return;
2535
2534
  }
2536
- setSelectedOptionOnInputValue();
2537
2535
  setShowSelectComponent(false);
2536
+ setSelectedOptionOnInputValue();
2538
2537
  onBlur && onBlur(event);
2539
2538
  },
2540
2539
  onKeyUp: onKeyUp,
@@ -2719,7 +2718,17 @@ const Dropdown = /*#__PURE__*/react.forwardRef((_a, ref) => {
2719
2718
  const [inputLabel, setInputLabel] = react.useState('');
2720
2719
  const [internalSelectedOption, setInternalSelectedOption] = react.useState();
2721
2720
  const inputRef = react.useRef(null);
2721
+ const selectRef = react.useRef(null);
2722
+ const containerRef = react.useRef(null);
2723
+ const {
2724
+ addOpenPositionClass,
2725
+ resetPositionClass
2726
+ } = uiUtils.useOpenPosition(selectRef, containerRef, ['top', 'bottom'], 'bottom');
2722
2727
  react.useEffect(() => {
2728
+ if (!showSelectComponent) {
2729
+ setCurrentOptionList(optionList || []);
2730
+ return;
2731
+ }
2723
2732
  if ((internalSelectedOption === null || internalSelectedOption === void 0 ? void 0 : internalSelectedOption.value) === inputValue) {
2724
2733
  setCurrentOptionList([]);
2725
2734
  } else {
@@ -2730,7 +2739,7 @@ const Dropdown = /*#__PURE__*/react.forwardRef((_a, ref) => {
2730
2739
  setCurrentOptionList([...optionsResponse]);
2731
2740
  }).catch(error => console.error('An error happens when trying to normalize options', error));
2732
2741
  }
2733
- }, [filterOptionsParam, optionList, urlFilterOptions, inputValue, internalSelectedOption === null || internalSelectedOption === void 0 ? void 0 : internalSelectedOption.value]);
2742
+ }, [showSelectComponent, filterOptionsParam, optionList, urlFilterOptions, inputValue, internalSelectedOption === null || internalSelectedOption === void 0 ? void 0 : internalSelectedOption.value]);
2734
2743
  const setSelectedOptionOnInputValue = react.useCallback(() => {
2735
2744
  if (!inputValue && internalSelectedOption) {
2736
2745
  setInputValue((internalSelectedOption === null || internalSelectedOption === void 0 ? void 0 : internalSelectedOption.value) || '');
@@ -2769,7 +2778,14 @@ const Dropdown = /*#__PURE__*/react.forwardRef((_a, ref) => {
2769
2778
  style: {
2770
2779
  maxWidth: (_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.style.width
2771
2780
  },
2772
- ref: ref
2781
+ ref: instance => {
2782
+ containerRef.current = instance;
2783
+ if (typeof ref === 'function') {
2784
+ ref(instance);
2785
+ } else if (typeof ref === 'object' && ref) {
2786
+ ref.current = instance;
2787
+ }
2788
+ }
2773
2789
  }, uiUtils.applyDataAttributes(props), {
2774
2790
  children: [jsxRuntime.jsx(ReusableDropdownComponent, Object.assign({
2775
2791
  id: id,
@@ -2784,7 +2800,12 @@ const Dropdown = /*#__PURE__*/react.forwardRef((_a, ref) => {
2784
2800
  showSelectComponent: showSelectComponent,
2785
2801
  inputRef: inputRef,
2786
2802
  placeholder: placeholder,
2787
- setShowSelectComponent: setShowSelectComponent,
2803
+ setShowSelectComponent: show => {
2804
+ reactDom.flushSync(() => {
2805
+ setShowSelectComponent(show);
2806
+ });
2807
+ show ? addOpenPositionClass() : resetPositionClass();
2808
+ },
2788
2809
  onChangeInputValue: setInputValue,
2789
2810
  setSelectedOptionOnInputValue: setSelectedOptionOnInputValue,
2790
2811
  onChangeInputLabel: setInputLabel,
@@ -2793,26 +2814,25 @@ const Dropdown = /*#__PURE__*/react.forwardRef((_a, ref) => {
2793
2814
  onKeyUp: onKeyUp,
2794
2815
  onKeyDown: onKeyDown,
2795
2816
  disableSearch: disableSearch
2796
- }, props)), showSelectComponent && !disabled && jsxRuntime.jsx(DropdownOptionsContainer, {
2797
- children: jsxRuntime.jsx(atomsSelect.Select, Object.assign({
2798
- id: `${id}-select`,
2799
- dataTestId: `${dataTestId}-select`,
2800
- onChange: selectedValue => {
2801
- var _a;
2802
- if (!selectedValue.disabled) {
2803
- setInputValue(selectedValue.value);
2804
- setInputLabel(selectedValue.label);
2805
- setInternalSelectedOption(Object.assign({}, selectedValue));
2806
- reactDom.flushSync(() => {
2807
- onChange(selectedValue);
2808
- });
2809
- (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur();
2810
- }
2811
- },
2812
- active: internalSelectedOption,
2813
- options: currentOptionList
2814
- }, uiUtils.applyDataAttributes(props, 'select')))
2815
- })]
2817
+ }, props)), showSelectComponent && !disabled && jsxRuntime.jsx(atomsSelect.Select, Object.assign({
2818
+ id: `${id}-select`,
2819
+ dataTestId: `${dataTestId}-select`,
2820
+ onChange: selectedValue => {
2821
+ var _a;
2822
+ if (!selectedValue.disabled) {
2823
+ setInputValue(selectedValue.value);
2824
+ setInputLabel(selectedValue.label);
2825
+ setInternalSelectedOption(Object.assign({}, selectedValue));
2826
+ reactDom.flushSync(() => {
2827
+ onChange(selectedValue);
2828
+ });
2829
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur();
2830
+ }
2831
+ },
2832
+ ref: selectRef,
2833
+ active: internalSelectedOption,
2834
+ options: currentOptionList
2835
+ }, uiUtils.applyDataAttributes(props, 'select')))]
2816
2836
  }));
2817
2837
  });
2818
2838
 
@@ -2845,7 +2865,17 @@ const DropdownWithHeaders = /*#__PURE__*/react.forwardRef((_a, ref) => {
2845
2865
  const [inputLabel, setInputLabel] = react.useState('');
2846
2866
  const [internalSelectedOption, setInternalSelectedOption] = react.useState();
2847
2867
  const inputRef = react.useRef(null);
2868
+ const selectRef = react.useRef(null);
2869
+ const containerRef = react.useRef(null);
2870
+ const {
2871
+ addOpenPositionClass,
2872
+ resetPositionClass
2873
+ } = uiUtils.useOpenPosition(selectRef, containerRef, ['top', 'bottom'], 'bottom');
2848
2874
  react.useEffect(() => {
2875
+ if (!showSelectComponent) {
2876
+ setCurrentOptionList(optionList || []);
2877
+ return;
2878
+ }
2849
2879
  if ((internalSelectedOption === null || internalSelectedOption === void 0 ? void 0 : internalSelectedOption.value) === inputValue) {
2850
2880
  setCurrentOptionList([]);
2851
2881
  } else {
@@ -2856,7 +2886,7 @@ const DropdownWithHeaders = /*#__PURE__*/react.forwardRef((_a, ref) => {
2856
2886
  setCurrentOptionList([...optionsResponse]);
2857
2887
  }).catch(error => console.error('An error happens when trying to normalize options', error));
2858
2888
  }
2859
- }, [filterOptionsParam, optionList, urlFilterOptions, inputValue, internalSelectedOption === null || internalSelectedOption === void 0 ? void 0 : internalSelectedOption.value]);
2889
+ }, [showSelectComponent, filterOptionsParam, optionList, urlFilterOptions, inputValue, internalSelectedOption === null || internalSelectedOption === void 0 ? void 0 : internalSelectedOption.value]);
2860
2890
  const setSelectedOptionOnInputValue = react.useCallback(() => {
2861
2891
  if (!inputValue && internalSelectedOption) {
2862
2892
  setInputValue((internalSelectedOption === null || internalSelectedOption === void 0 ? void 0 : internalSelectedOption.value) || '');
@@ -2900,7 +2930,14 @@ const DropdownWithHeaders = /*#__PURE__*/react.forwardRef((_a, ref) => {
2900
2930
  return jsxRuntime.jsxs(SectionContainer, Object.assign({
2901
2931
  "$variant": variant,
2902
2932
  "data-testid": `${dataTestId}-container`,
2903
- ref: ref
2933
+ ref: instance => {
2934
+ containerRef.current = instance;
2935
+ if (typeof ref === 'function') {
2936
+ ref(instance);
2937
+ } else if (typeof ref === 'object' && ref) {
2938
+ ref.current = instance;
2939
+ }
2940
+ }
2904
2941
  }, uiUtils.applyDataAttributes(props), {
2905
2942
  children: [jsxRuntime.jsx(ReusableDropdownComponent, Object.assign({
2906
2943
  label: label,
@@ -2914,7 +2951,12 @@ const DropdownWithHeaders = /*#__PURE__*/react.forwardRef((_a, ref) => {
2914
2951
  showSelectComponent: showSelectComponent,
2915
2952
  inputRef: inputRef,
2916
2953
  placeholder: placeholder,
2917
- setShowSelectComponent: setShowSelectComponent,
2954
+ setShowSelectComponent: show => {
2955
+ reactDom.flushSync(() => {
2956
+ setShowSelectComponent(show);
2957
+ });
2958
+ show ? addOpenPositionClass() : resetPositionClass();
2959
+ },
2918
2960
  onChangeInputValue: setInputValue,
2919
2961
  onChangeInputLabel: setInputLabel,
2920
2962
  setSelectedOptionOnInputValue: setSelectedOptionOnInputValue,
@@ -2923,23 +2965,22 @@ const DropdownWithHeaders = /*#__PURE__*/react.forwardRef((_a, ref) => {
2923
2965
  onKeyUp: onKeyUp,
2924
2966
  onKeyDown: onKeyDown,
2925
2967
  disableSearch: disableSearch
2926
- }, props)), showSelectComponent && !disabled && jsxRuntime.jsx(DropdownOptionsContainer, {
2927
- children: jsxRuntime.jsx(atomsSelect.SelectWithHeaders, Object.assign({
2928
- dataTestId: `${dataTestId}-select`,
2929
- onChange: selectedValue => {
2930
- var _a;
2931
- setInputLabel(selectedValue.label);
2932
- setInputValue(selectedValue.value);
2933
- setInternalSelectedOption(Object.assign({}, selectedValue));
2934
- reactDom.flushSync(() => {
2935
- onChange(selectedValue);
2936
- });
2937
- (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur();
2938
- },
2939
- active: internalSelectedOption,
2940
- options: currentOptionList
2941
- }, uiUtils.applyDataAttributes(props, 'select')))
2942
- })]
2968
+ }, props)), showSelectComponent && !disabled && jsxRuntime.jsx(atomsSelect.SelectWithHeaders, Object.assign({
2969
+ dataTestId: `${dataTestId}-select`,
2970
+ onChange: selectedValue => {
2971
+ var _a;
2972
+ setInputLabel(selectedValue.label);
2973
+ setInputValue(selectedValue.value);
2974
+ setInternalSelectedOption(Object.assign({}, selectedValue));
2975
+ reactDom.flushSync(() => {
2976
+ onChange(selectedValue);
2977
+ });
2978
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur();
2979
+ },
2980
+ active: internalSelectedOption,
2981
+ ref: selectRef,
2982
+ options: currentOptionList
2983
+ }, uiUtils.applyDataAttributes(props, 'select')))]
2943
2984
  }));
2944
2985
  });
2945
2986
 
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@bolttech/molecules-dropdown",
3
- "version": "0.31.1",
3
+ "version": "0.32.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.23.0",
9
- "@bolttech/atoms-input": "0.26.0",
9
+ "@bolttech/atoms-input": "0.26.1",
10
10
  "@bolttech/atoms-select": "0.22.0",
11
- "@bolttech/default-theme": "0.8.0",
12
- "@bolttech/form-engine": "3.0.1-beta.7",
13
- "@bolttech/frontend-foundations": "0.9.3",
14
- "@bolttech/ui-utils": "0.4.0",
11
+ "@bolttech/default-theme": "0.9.0",
12
+ "@bolttech/form-engine": "3.1.0-beta.13",
13
+ "@bolttech/frontend-foundations": "0.10.0",
14
+ "@bolttech/ui-utils": "0.5.0",
15
15
  "react": "18.2.0",
16
16
  "react-dom": "18.2.0",
17
17
  "styled-components": "6.1.1"
@@ -183,7 +183,7 @@ export type DropdownWithHeadersProps = Pick<DOMAttributes<HTMLInputElement>, 'on
183
183
  @property inputRef - A ref to the input element of the dropdown
184
184
  */
185
185
  export type ReusableDropdownComponentProps = DefaultProps & Pick<DOMAttributes<HTMLInputElement>, 'onKeyUp' | 'onKeyDown'> & DefaultDropdownProps & {
186
- setShowSelectComponent: React.Dispatch<React.SetStateAction<boolean>>;
186
+ setShowSelectComponent: (show: boolean) => void;
187
187
  showSelectComponent: boolean;
188
188
  onChangeInputValue: React.Dispatch<React.SetStateAction<string>>;
189
189
  onChangeInputLabel: React.Dispatch<React.SetStateAction<string>>;