@bolttech/molecules-dropdown 0.22.2 → 0.24.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:
|
|
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([]);
|
|
@@ -2748,11 +2751,7 @@ const Dropdown = /*#__PURE__*/react.forwardRef((_a, ref) => {
|
|
|
2748
2751
|
style: {
|
|
2749
2752
|
maxWidth: (_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.style.width
|
|
2750
2753
|
},
|
|
2751
|
-
ref: ref
|
|
2752
|
-
onClick: () => {
|
|
2753
|
-
var _a;
|
|
2754
|
-
return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
2755
|
-
}
|
|
2754
|
+
ref: ref
|
|
2756
2755
|
}, uiUtils.applyDataAttributes(props), {
|
|
2757
2756
|
children: [jsxRuntime.jsx(ReusableDropdownComponent, Object.assign({
|
|
2758
2757
|
id: id,
|
|
@@ -2774,23 +2773,27 @@ const Dropdown = /*#__PURE__*/react.forwardRef((_a, ref) => {
|
|
|
2774
2773
|
onBlur: onBlur,
|
|
2775
2774
|
onFocus: onFocus,
|
|
2776
2775
|
onKeyUp: onKeyUp,
|
|
2777
|
-
onKeyDown: onKeyDown
|
|
2776
|
+
onKeyDown: onKeyDown,
|
|
2777
|
+
disableSearch: disableSearch
|
|
2778
2778
|
}, props)), showSelectComponent && !disabled && jsxRuntime.jsx(DropdownOptionsContainer, {
|
|
2779
2779
|
children: jsxRuntime.jsx(atomsSelect.Select, Object.assign({
|
|
2780
2780
|
id: `${id}-select`,
|
|
2781
2781
|
dataTestId: `${dataTestId}-select`,
|
|
2782
2782
|
onChange: selectedValue => {
|
|
2783
2783
|
var _a;
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
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
|
+
}
|
|
2791
2793
|
},
|
|
2792
2794
|
active: internalSelectedOption,
|
|
2793
|
-
options: currentOptionList
|
|
2795
|
+
options: currentOptionList,
|
|
2796
|
+
maxHeight: selectMaxHeight
|
|
2794
2797
|
}, uiUtils.applyDataAttributes(props, 'select')))
|
|
2795
2798
|
})]
|
|
2796
2799
|
}));
|
|
@@ -2813,9 +2816,11 @@ const DropdownWithHeaders = /*#__PURE__*/react.forwardRef((_a, ref) => {
|
|
|
2813
2816
|
onFocus,
|
|
2814
2817
|
placeholder,
|
|
2815
2818
|
onKeyUp,
|
|
2816
|
-
onKeyDown
|
|
2819
|
+
onKeyDown,
|
|
2820
|
+
selectMaxHeight,
|
|
2821
|
+
disableSearch
|
|
2817
2822
|
} = _a,
|
|
2818
|
-
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"]);
|
|
2819
2824
|
const [isFirstRender, setIsFirstRender] = react.useState(true);
|
|
2820
2825
|
const [showSelectComponent, setShowSelectComponent] = react.useState(false);
|
|
2821
2826
|
const [currentOptionList, setCurrentOptionList] = react.useState([]);
|
|
@@ -2872,12 +2877,8 @@ const DropdownWithHeaders = /*#__PURE__*/react.forwardRef((_a, ref) => {
|
|
|
2872
2877
|
return optionsList.options.find(option => option.id === value);
|
|
2873
2878
|
})[0] || undefined);
|
|
2874
2879
|
setIsFirstRender(false);
|
|
2875
|
-
}, [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]);
|
|
2876
2881
|
return jsxRuntime.jsxs(SectionContainer, Object.assign({
|
|
2877
|
-
onClick: () => {
|
|
2878
|
-
var _a;
|
|
2879
|
-
return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
2880
|
-
},
|
|
2881
2882
|
"$variant": variant,
|
|
2882
2883
|
"data-testid": `${dataTestId}-container`,
|
|
2883
2884
|
ref: ref
|
|
@@ -2901,7 +2902,8 @@ const DropdownWithHeaders = /*#__PURE__*/react.forwardRef((_a, ref) => {
|
|
|
2901
2902
|
onBlur: onBlur,
|
|
2902
2903
|
onFocus: onFocus,
|
|
2903
2904
|
onKeyUp: onKeyUp,
|
|
2904
|
-
onKeyDown: onKeyDown
|
|
2905
|
+
onKeyDown: onKeyDown,
|
|
2906
|
+
disableSearch: disableSearch
|
|
2905
2907
|
}, props)), showSelectComponent && !disabled && jsxRuntime.jsx(DropdownOptionsContainer, {
|
|
2906
2908
|
children: jsxRuntime.jsx(atomsSelect.SelectWithHeaders, Object.assign({
|
|
2907
2909
|
dataTestId: `${dataTestId}-select`,
|
|
@@ -2916,7 +2918,8 @@ const DropdownWithHeaders = /*#__PURE__*/react.forwardRef((_a, ref) => {
|
|
|
2916
2918
|
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur();
|
|
2917
2919
|
},
|
|
2918
2920
|
active: internalSelectedOption,
|
|
2919
|
-
options: currentOptionList
|
|
2921
|
+
options: currentOptionList,
|
|
2922
|
+
maxHeight: selectMaxHeight
|
|
2920
2923
|
}, uiUtils.applyDataAttributes(props, 'select')))
|
|
2921
2924
|
})]
|
|
2922
2925
|
}));
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bolttech/molecules-dropdown",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.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.
|
|
11
|
-
"@bolttech/default-theme": "0.
|
|
10
|
+
"@bolttech/atoms-select": "0.20.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.
|
|
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>>;
|