@bolttech/molecules-dropdown 0.24.0 → 0.25.1
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,7 +67,9 @@ 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
|
-
| `
|
|
70
|
+
| `onKeyUp` | `function` | The onkeyup event occurs when the user releases a key on the keyboard |
|
|
71
|
+
| `onKeyDown` | `boolean` | Onkeydown is an event handler in Javascript that gets called when a key is pressed on the keyboard |
|
|
72
|
+
| `asyncOptionList` | `boolean` | A boolean prop that controls a different behavior when OptionList are set by an API request |
|
|
71
73
|
|
|
72
74
|
## Functionality
|
|
73
75
|
|
package/index.cjs
CHANGED
|
@@ -2690,10 +2690,10 @@ const Dropdown = /*#__PURE__*/react.forwardRef((_a, ref) => {
|
|
|
2690
2690
|
placeholder,
|
|
2691
2691
|
onKeyUp,
|
|
2692
2692
|
onKeyDown,
|
|
2693
|
-
|
|
2694
|
-
|
|
2693
|
+
disableSearch,
|
|
2694
|
+
asyncOptionList = false
|
|
2695
2695
|
} = _a,
|
|
2696
|
-
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", "disableSearch", "asyncOptionList"]);
|
|
2697
2697
|
const [isFirstRender, setIsFirstRender] = react.useState(true);
|
|
2698
2698
|
const [showSelectComponent, setShowSelectComponent] = react.useState(false);
|
|
2699
2699
|
const [currentOptionList, setCurrentOptionList] = react.useState([]);
|
|
@@ -2736,14 +2736,14 @@ const Dropdown = /*#__PURE__*/react.forwardRef((_a, ref) => {
|
|
|
2736
2736
|
const foundOption = optionList === null || optionList === void 0 ? void 0 : optionList.find(option => option.id === value);
|
|
2737
2737
|
setInternalSelectedOption(foundOption);
|
|
2738
2738
|
setInputValue((foundOption === null || foundOption === void 0 ? void 0 : foundOption.value) || '');
|
|
2739
|
-
if (!
|
|
2739
|
+
if (!asyncOptionList) {
|
|
2740
2740
|
setInputLabel((foundOption === null || foundOption === void 0 ? void 0 : foundOption.label) || '');
|
|
2741
2741
|
}
|
|
2742
2742
|
}
|
|
2743
2743
|
if (!isFirstRender || currentOptionList.length === 0) return;
|
|
2744
2744
|
setInternalSelectedOption(currentOptionList.find(option => option.id === value));
|
|
2745
2745
|
setIsFirstRender(false);
|
|
2746
|
-
}, [currentOptionList, setSelectedOptionOnInputValue, value, internalSelectedOption, optionList, isFirstRender, onKeyUp, onKeyDown]);
|
|
2746
|
+
}, [currentOptionList, setSelectedOptionOnInputValue, value, internalSelectedOption, optionList, isFirstRender, onKeyUp, onKeyDown, asyncOptionList]);
|
|
2747
2747
|
return jsxRuntime.jsxs(SectionContainer, Object.assign({
|
|
2748
2748
|
"$variant": variant,
|
|
2749
2749
|
id: `${id}-container`,
|
|
@@ -2792,8 +2792,7 @@ const Dropdown = /*#__PURE__*/react.forwardRef((_a, ref) => {
|
|
|
2792
2792
|
}
|
|
2793
2793
|
},
|
|
2794
2794
|
active: internalSelectedOption,
|
|
2795
|
-
options: currentOptionList
|
|
2796
|
-
maxHeight: selectMaxHeight
|
|
2795
|
+
options: currentOptionList
|
|
2797
2796
|
}, uiUtils.applyDataAttributes(props, 'select')))
|
|
2798
2797
|
})]
|
|
2799
2798
|
}));
|
|
@@ -2817,10 +2816,10 @@ const DropdownWithHeaders = /*#__PURE__*/react.forwardRef((_a, ref) => {
|
|
|
2817
2816
|
placeholder,
|
|
2818
2817
|
onKeyUp,
|
|
2819
2818
|
onKeyDown,
|
|
2820
|
-
|
|
2821
|
-
|
|
2819
|
+
disableSearch,
|
|
2820
|
+
asyncOptionList = false
|
|
2822
2821
|
} = _a,
|
|
2823
|
-
props = __rest(_a, ["label", "variant", "required", "optionList", "disabled", "errorMessage", "urlFilterOptions", "dataTestId", "filterOptionsParam", "value", "onChange", "onBlur", "onFocus", "placeholder", "onKeyUp", "onKeyDown", "
|
|
2822
|
+
props = __rest(_a, ["label", "variant", "required", "optionList", "disabled", "errorMessage", "urlFilterOptions", "dataTestId", "filterOptionsParam", "value", "onChange", "onBlur", "onFocus", "placeholder", "onKeyUp", "onKeyDown", "disableSearch", "asyncOptionList"]);
|
|
2824
2823
|
const [isFirstRender, setIsFirstRender] = react.useState(true);
|
|
2825
2824
|
const [showSelectComponent, setShowSelectComponent] = react.useState(false);
|
|
2826
2825
|
const [currentOptionList, setCurrentOptionList] = react.useState([]);
|
|
@@ -2867,7 +2866,7 @@ const DropdownWithHeaders = /*#__PURE__*/react.forwardRef((_a, ref) => {
|
|
|
2867
2866
|
})[0]) || undefined;
|
|
2868
2867
|
setInternalSelectedOption(option);
|
|
2869
2868
|
setInputValue((option === null || option === void 0 ? void 0 : option.value) || '');
|
|
2870
|
-
if (!
|
|
2869
|
+
if (!asyncOptionList) {
|
|
2871
2870
|
setInputLabel((option === null || option === void 0 ? void 0 : option.label) || '');
|
|
2872
2871
|
}
|
|
2873
2872
|
return;
|
|
@@ -2877,7 +2876,7 @@ const DropdownWithHeaders = /*#__PURE__*/react.forwardRef((_a, ref) => {
|
|
|
2877
2876
|
return optionsList.options.find(option => option.id === value);
|
|
2878
2877
|
})[0] || undefined);
|
|
2879
2878
|
setIsFirstRender(false);
|
|
2880
|
-
}, [currentOptionList, value, optionList, internalSelectedOption === null || internalSelectedOption === void 0 ? void 0 : internalSelectedOption.id, isFirstRender,
|
|
2879
|
+
}, [currentOptionList, value, optionList, internalSelectedOption === null || internalSelectedOption === void 0 ? void 0 : internalSelectedOption.id, isFirstRender, asyncOptionList]);
|
|
2881
2880
|
return jsxRuntime.jsxs(SectionContainer, Object.assign({
|
|
2882
2881
|
"$variant": variant,
|
|
2883
2882
|
"data-testid": `${dataTestId}-container`,
|
|
@@ -2918,8 +2917,7 @@ const DropdownWithHeaders = /*#__PURE__*/react.forwardRef((_a, ref) => {
|
|
|
2918
2917
|
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur();
|
|
2919
2918
|
},
|
|
2920
2919
|
active: internalSelectedOption,
|
|
2921
|
-
options: currentOptionList
|
|
2922
|
-
maxHeight: selectMaxHeight
|
|
2920
|
+
options: currentOptionList
|
|
2923
2921
|
}, uiUtils.applyDataAttributes(props, 'select')))
|
|
2924
2922
|
})]
|
|
2925
2923
|
}));
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bolttech/molecules-dropdown",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.1",
|
|
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
|
-
"@bolttech/atoms-input": "0.
|
|
10
|
-
"@bolttech/atoms-select": "0.
|
|
11
|
-
"@bolttech/default-theme": "0.3.
|
|
12
|
-
"@bolttech/form-engine": "0.
|
|
9
|
+
"@bolttech/atoms-input": "0.0.1",
|
|
10
|
+
"@bolttech/atoms-select": "0.21.0",
|
|
11
|
+
"@bolttech/default-theme": "0.3.1",
|
|
12
|
+
"@bolttech/form-engine": "0.10.3",
|
|
13
13
|
"@bolttech/frontend-foundations": "0.3.1",
|
|
14
|
-
"@bolttech/ui-utils": "0.2.
|
|
14
|
+
"@bolttech/ui-utils": "0.2.4",
|
|
15
15
|
"react": "18.2.0",
|
|
16
16
|
"react-dom": "18.2.0",
|
|
17
17
|
"styled-components": "6.1.1"
|
|
@@ -10,7 +10,6 @@ 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;
|
|
14
13
|
onBlur?: ((value?: unknown) => void) | ((evt: import("react").FocusEvent<HTMLElement, Element>) => void) | undefined;
|
|
15
14
|
onFocus?: ((value?: unknown) => void) | ((evt: import("react").FocusEvent<HTMLElement, Element>) => void) | undefined;
|
|
16
15
|
} & {
|
|
@@ -19,5 +18,6 @@ export declare const DropdownWithHeaders: import("react").ForwardRefExoticCompon
|
|
|
19
18
|
urlFilterOptions?: string | undefined;
|
|
20
19
|
onChange: (selectedOption?: OptionType | undefined) => void | import("react").Dispatch<import("react").SetStateAction<OptionType>>;
|
|
21
20
|
value?: string | undefined;
|
|
21
|
+
asyncOptionList?: boolean | undefined;
|
|
22
22
|
} & import("react").RefAttributes<HTMLElement>>;
|
|
23
23
|
export default DropdownWithHeaders;
|
|
@@ -10,7 +10,6 @@ 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;
|
|
14
13
|
onBlur?: ((value?: unknown) => void) | ((evt: import("react").FocusEvent<HTMLElement, Element>) => void) | undefined;
|
|
15
14
|
onFocus?: ((value?: unknown) => void) | ((evt: import("react").FocusEvent<HTMLElement, Element>) => void) | undefined;
|
|
16
15
|
} & {
|
|
@@ -19,5 +18,6 @@ export declare const Dropdown: import("react").ForwardRefExoticComponent<Pick<im
|
|
|
19
18
|
urlFilterOptions?: string | undefined;
|
|
20
19
|
onChange: (selectedOption?: OptionType | undefined) => void | import("react").Dispatch<import("react").SetStateAction<OptionType>>;
|
|
21
20
|
value?: string | undefined;
|
|
21
|
+
asyncOptionList?: boolean | undefined;
|
|
22
22
|
} & import("react").RefAttributes<HTMLElement>>;
|
|
23
23
|
export default Dropdown;
|
|
@@ -17,7 +17,6 @@ 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
|
|
21
20
|
*/
|
|
22
21
|
type DefaultDropdownProps = {
|
|
23
22
|
label: string;
|
|
@@ -29,7 +28,6 @@ type DefaultDropdownProps = {
|
|
|
29
28
|
required?: boolean;
|
|
30
29
|
variant?: StyleVariants;
|
|
31
30
|
disableSearch?: boolean;
|
|
32
|
-
selectMaxHeight?: string;
|
|
33
31
|
onBlur?: ((value?: unknown) => void) | ((evt: React.FocusEvent<HTMLElement, Element>) => void);
|
|
34
32
|
onFocus?: ((value?: unknown) => void) | ((evt: React.FocusEvent<HTMLElement, Element>) => void);
|
|
35
33
|
};
|
|
@@ -41,6 +39,7 @@ type DefaultDropdownProps = {
|
|
|
41
39
|
@property urlFilterOptions - An optional string representing the url to fetch options
|
|
42
40
|
@property setSelectedOption - A function to set the selected option
|
|
43
41
|
@property selectedOption - An optional object representing the currently selected option
|
|
42
|
+
@property asyncOptionList - A boolean prop that controls a different behavior when OptionList are set by an API request
|
|
44
43
|
*/
|
|
45
44
|
export type DropdownProps = Pick<DOMAttributes<HTMLInputElement>, 'onKeyUp' | 'onKeyDown'> & DefaultProps & DefaultDropdownProps & {
|
|
46
45
|
optionList?: OptionType[];
|
|
@@ -92,6 +91,10 @@ export type DropdownProps = Pick<DOMAttributes<HTMLInputElement>, 'onKeyUp' | 'o
|
|
|
92
91
|
*/
|
|
93
92
|
onChange: (selectedOption?: OptionType) => void | React.Dispatch<React.SetStateAction<OptionType>>;
|
|
94
93
|
value?: string;
|
|
94
|
+
/**
|
|
95
|
+
* A boolean prop that controls a different behavior when OptionList are set by an API request
|
|
96
|
+
*/
|
|
97
|
+
asyncOptionList?: boolean;
|
|
95
98
|
};
|
|
96
99
|
/**
|
|
97
100
|
Props for DropdownOptionsWithHeaders component
|
|
@@ -101,6 +104,7 @@ export type DropdownProps = Pick<DOMAttributes<HTMLInputElement>, 'onKeyUp' | 'o
|
|
|
101
104
|
@property urlFilterOptions - An optional string representing the url to fetch options
|
|
102
105
|
@property setSelectedOption - A function to set the selected option
|
|
103
106
|
@property selectedOption - An optional object representing the currently selected option
|
|
107
|
+
@property asyncOptionList - A boolean prop that controls a different behavior when OptionList are set by an API request
|
|
104
108
|
*/
|
|
105
109
|
export type DropdownWithHeadersProps = Pick<DOMAttributes<HTMLInputElement>, 'onKeyUp' | 'onKeyDown'> & DefaultProps & DefaultDropdownProps & {
|
|
106
110
|
optionList?: OptionWithHeaderType[];
|
|
@@ -158,6 +162,10 @@ export type DropdownWithHeadersProps = Pick<DOMAttributes<HTMLInputElement>, 'on
|
|
|
158
162
|
*/
|
|
159
163
|
onChange: (selectedOption?: OptionType) => void | React.Dispatch<React.SetStateAction<OptionType>>;
|
|
160
164
|
value?: string;
|
|
165
|
+
/**
|
|
166
|
+
* A boolean prop that controls a different behavior when OptionList are set by an API request
|
|
167
|
+
*/
|
|
168
|
+
asyncOptionList?: boolean;
|
|
161
169
|
};
|
|
162
170
|
/**
|
|
163
171
|
Props for ReusableDropdownComponent component
|
|
@@ -172,7 +180,7 @@ export type DropdownWithHeadersProps = Pick<DOMAttributes<HTMLInputElement>, 'on
|
|
|
172
180
|
@property setSelectedOptionOnInputValue - A function to set the selected option based on the input value
|
|
173
181
|
@property inputRef - A ref to the input element of the dropdown
|
|
174
182
|
*/
|
|
175
|
-
export type ReusableDropdownComponentProps = DefaultProps & Pick<DOMAttributes<HTMLInputElement>, 'onKeyUp' | 'onKeyDown'> &
|
|
183
|
+
export type ReusableDropdownComponentProps = DefaultProps & Pick<DOMAttributes<HTMLInputElement>, 'onKeyUp' | 'onKeyDown'> & DefaultDropdownProps & {
|
|
176
184
|
setShowSelectComponent: React.Dispatch<React.SetStateAction<boolean>>;
|
|
177
185
|
showSelectComponent: boolean;
|
|
178
186
|
onChangeInputValue: React.Dispatch<React.SetStateAction<string>>;
|