@bolttech/molecules-dropdown 0.19.0 → 0.20.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
@@ -22,7 +22,7 @@ You can utilize the **Dropdown** component by importing it and including it in y
22
22
 
23
23
  ```jsx
24
24
  import React from 'react';
25
- import {Dropdown} from '@bolttech/molecules-dropdown'; // Adjust the path to your component
25
+ import { Dropdown } from '@bolttech/molecules-dropdown'; // Adjust the path to your component
26
26
 
27
27
  const options = [
28
28
  { id: '1', label: 'Option 1', value: 'option1' },
@@ -37,12 +37,7 @@ function App() {
37
37
 
38
38
  return (
39
39
  <div>
40
- <Dropdown
41
- label="Select an option"
42
- optionList={options}
43
- value="option2"
44
- onChange={handleOptionChange}
45
- />
40
+ <Dropdown label="Select an option" optionList={options} value="option2" onChange={handleOptionChange} />
46
41
  </div>
47
42
  );
48
43
  }
@@ -54,23 +49,24 @@ export default App;
54
49
 
55
50
  The **Dropdown** component accepts the following props:
56
51
 
57
- | Prop | Type | Description |
58
- | --------------------- | ---------------- | ------------------------------------------------------------------------------------------------------- |
59
- | `label` | `string` | Label for the dropdown. |
60
- | `variant` | `string` | Variant style of the dropdown. Defaults to `'grey'`. |
61
- | `required` | `boolean` | Whether the dropdown is required or not. |
62
- | `optionList` | `OptionType[]` | Array of selectable options for the dropdown. |
63
- | `disabled` | `boolean` | Whether the dropdown is disabled or not. |
64
- | `errorMessage` | `string` | Error message to display when there's an error with the dropdown. |
65
- | `urlFilterOptions` | `string` | URL for fetching filtered options based on input. |
66
- | `id` | `string` | Component identification. |
67
- | `dataTestId` | `string` | The data-testid attribute for testing purposes. |
68
- | `filterOptionsParam` | `function` | Function to filter options based on input and URL. |
69
- | `value` | `string` | Currently selected value. |
70
- | `onChange` | `function` | Callback function triggered when the selected option changes. |
71
- | `onBlur` | `function` | Callback function triggered when the dropdown loses focus. |
72
- | `onFocus` | `function` | Callback function triggered when the dropdown is focused. |
73
- | `placeholder` | `string` | Placeholder text for the input. |
52
+ | Prop | Type | Description |
53
+ | -------------------- | -------------- | --------------------------------------------------------------------------------------------- |
54
+ | `label` | `string` | Label for the dropdown. |
55
+ | `variant` | `string` | Variant style of the dropdown. Defaults to `'grey'`. |
56
+ | `required` | `boolean` | Whether the dropdown is required or not. |
57
+ | `optionList` | `OptionType[]` | Array of selectable options for the dropdown. |
58
+ | `disabled` | `boolean` | Whether the dropdown is disabled or not. |
59
+ | `errorMessage` | `string` | Error message to display when there's an error with the dropdown. |
60
+ | `urlFilterOptions` | `string` | URL for fetching filtered options based on input. |
61
+ | `id` | `string` | Component identification. |
62
+ | `dataTestId` | `string` | The data-testid attribute for testing purposes. |
63
+ | `filterOptionsParam` | `function` | Function to filter options based on input and URL. |
64
+ | `value` | `string` | Currently selected value. |
65
+ | `onChange` | `function` | Callback function triggered when the selected option changes. |
66
+ | `onBlur` | `function` | Callback function triggered when the dropdown loses focus. |
67
+ | `onFocus` | `function` | Callback function triggered when the dropdown is focused. |
68
+ | `placeholder` | `string` | Placeholder text for the input. |
69
+ | `disableSearch` | `boolean` | Boolean that represent if we should disable user searching on the dropdown. Defaults to false |
74
70
 
75
71
  ## Functionality
76
72
 
package/index.cjs CHANGED
@@ -2455,12 +2455,13 @@ const ReusableDropdownComponent = _a => {
2455
2455
  setShowSelectComponent,
2456
2456
  showSelectComponent,
2457
2457
  setSelectedOptionOnInputValue,
2458
+ disableSearch = false,
2458
2459
  inputRef,
2459
2460
  placeholder,
2460
2461
  onBlur,
2461
2462
  onFocus
2462
2463
  } = _a,
2463
- props = __rest(_a, ["id", "dataTestId", "label", "variant", "required", "inputValue", "inputLabel", "disabled", "errorMessage", "onChangeInputValue", "onChangeInputLabel", "setShowSelectComponent", "showSelectComponent", "setSelectedOptionOnInputValue", "inputRef", "placeholder", "onBlur", "onFocus"]);
2464
+ props = __rest(_a, ["id", "dataTestId", "label", "variant", "required", "inputValue", "inputLabel", "disabled", "errorMessage", "onChangeInputValue", "onChangeInputLabel", "setShowSelectComponent", "showSelectComponent", "setSelectedOptionOnInputValue", "disableSearch", "inputRef", "placeholder", "onBlur", "onFocus"]);
2464
2465
  const hasError = !!errorMessage;
2465
2466
  // we have to type cast because of jest. when testing it sets the type of useTheme to DefaultTheme
2466
2467
  const theme = /*#__PURE__*/styled.useTheme();
@@ -2497,6 +2498,8 @@ const ReusableDropdownComponent = _a => {
2497
2498
  "$variant": variant,
2498
2499
  placeholder: placeholder,
2499
2500
  autoComplete: "off",
2501
+ inputMode: disableSearch ? 'none' : 'text',
2502
+ readOnly: disableSearch,
2500
2503
  onChange: e => {
2501
2504
  var _a, _b;
2502
2505
  onChangeInputValue(((_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.value) || '');
@@ -2518,7 +2521,9 @@ const ReusableDropdownComponent = _a => {
2518
2521
  })]
2519
2522
  }), jsxRuntime.jsx(ClickableElement, {
2520
2523
  onClick: () => {
2521
- if (!disabled) setShowSelectComponent(!showSelectComponent);
2524
+ if (!disabled) {
2525
+ setShowSelectComponent(!showSelectComponent);
2526
+ }
2522
2527
  },
2523
2528
  children: jsxRuntime.jsx(atomsIcon.Icon, {
2524
2529
  dataTestId: `${dataTestId}-icon`,
@@ -2688,11 +2693,17 @@ const Dropdown = /*#__PURE__*/react.forwardRef((_a, ref) => {
2688
2693
  const [internalSelectedOption, setInternalSelectedOption] = react.useState();
2689
2694
  const inputRef = react.useRef(null);
2690
2695
  react.useEffect(() => {
2691
- const normalizeOptionList = () => __awaiter(void 0, void 0, void 0, function* () {
2692
- return yield filterOptionsParam(inputValue, optionList, urlFilterOptions);
2693
- });
2694
- normalizeOptionList().then(optionsResponse => setCurrentOptionList([...optionsResponse])).catch(error => console.error('An error happens when trying to normalize options', error));
2695
- }, [filterOptionsParam, optionList, urlFilterOptions, inputValue]);
2696
+ if ((internalSelectedOption === null || internalSelectedOption === void 0 ? void 0 : internalSelectedOption.value) === inputValue) {
2697
+ setCurrentOptionList([]);
2698
+ } else {
2699
+ const normalizeOptionList = () => __awaiter(void 0, void 0, void 0, function* () {
2700
+ return yield filterOptionsParam(inputValue, optionList, urlFilterOptions);
2701
+ });
2702
+ normalizeOptionList().then(optionsResponse => {
2703
+ setCurrentOptionList([...optionsResponse]);
2704
+ }).catch(error => console.error('An error happens when trying to normalize options', error));
2705
+ }
2706
+ }, [filterOptionsParam, optionList, urlFilterOptions, inputValue, internalSelectedOption === null || internalSelectedOption === void 0 ? void 0 : internalSelectedOption.value]);
2696
2707
  const setSelectedOptionOnInputValue = react.useCallback(() => {
2697
2708
  if (!inputValue && internalSelectedOption) {
2698
2709
  setInputValue((internalSelectedOption === null || internalSelectedOption === void 0 ? void 0 : internalSelectedOption.value) || '');
@@ -2723,17 +2734,17 @@ const Dropdown = /*#__PURE__*/react.forwardRef((_a, ref) => {
2723
2734
  setIsFirstRender(false);
2724
2735
  }, [currentOptionList, setSelectedOptionOnInputValue, value, internalSelectedOption, optionList, isFirstRender]);
2725
2736
  return jsxRuntime.jsxs(SectionContainer, Object.assign({
2726
- onClick: () => {
2727
- var _a;
2728
- return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
2729
- },
2730
2737
  "$variant": variant,
2731
2738
  id: `${id}-container`,
2732
2739
  "data-testid": `${dataTestId}-container`,
2733
2740
  style: {
2734
2741
  maxWidth: (_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.style.width
2735
2742
  },
2736
- ref: ref
2743
+ ref: ref,
2744
+ onClick: () => {
2745
+ var _a;
2746
+ return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
2747
+ }
2737
2748
  }, uiUtils.applyDataAttributes(props), {
2738
2749
  children: [jsxRuntime.jsx(ReusableDropdownComponent, Object.assign({
2739
2750
  id: id,
@@ -2801,11 +2812,15 @@ const DropdownWithHeaders = /*#__PURE__*/react.forwardRef((_a, ref) => {
2801
2812
  const [internalSelectedOption, setInternalSelectedOption] = react.useState();
2802
2813
  const inputRef = react.useRef(null);
2803
2814
  react.useEffect(() => {
2804
- const normalizeOptionList = () => __awaiter(void 0, void 0, void 0, function* () {
2805
- return yield filterOptionsParam(inputValue, optionList, urlFilterOptions);
2806
- });
2807
- normalizeOptionList().then(optionsResponse => setCurrentOptionList([...optionsResponse])).catch(error => console.error('An error happens when trying to normalize options', error));
2808
- }, [filterOptionsParam, optionList, urlFilterOptions, inputValue]);
2815
+ if ((internalSelectedOption === null || internalSelectedOption === void 0 ? void 0 : internalSelectedOption.value) === inputValue) {
2816
+ setCurrentOptionList([]);
2817
+ } else {
2818
+ const normalizeOptionList = () => __awaiter(void 0, void 0, void 0, function* () {
2819
+ return yield filterOptionsParam(inputValue, optionList, urlFilterOptions);
2820
+ });
2821
+ normalizeOptionList().then(optionsResponse => setCurrentOptionList([...optionsResponse])).catch(error => console.error('An error happens when trying to normalize options', error));
2822
+ }
2823
+ }, [filterOptionsParam, optionList, urlFilterOptions, inputValue, internalSelectedOption === null || internalSelectedOption === void 0 ? void 0 : internalSelectedOption.value]);
2809
2824
  const setSelectedOptionOnInputValue = react.useCallback(() => {
2810
2825
  if (!inputValue && internalSelectedOption) {
2811
2826
  setInputValue((internalSelectedOption === null || internalSelectedOption === void 0 ? void 0 : internalSelectedOption.value) || '');
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@bolttech/molecules-dropdown",
3
- "version": "0.19.0",
3
+ "version": "0.20.1",
4
4
  "main": "./index.cjs",
5
5
  "type": "commonjs",
6
6
  "types": "./src/index.d.ts",
7
7
  "dependencies": {
8
- "@bolttech/atoms-icon": "0.22.0",
9
- "@bolttech/atoms-input": "0.21.0",
10
- "@bolttech/atoms-select": "0.19.1",
11
- "@bolttech/default-theme": "0.1.0",
8
+ "@bolttech/atoms-icon": "0.22.1",
9
+ "@bolttech/atoms-input": "0.0.1",
10
+ "@bolttech/atoms-select": "0.19.3",
11
+ "@bolttech/default-theme": "0.1.1",
12
12
  "@bolttech/form-engine": "0.5.0",
13
- "@bolttech/frontend-foundations": "0.2.1",
14
- "@bolttech/ui-utils": "0.2.0",
13
+ "@bolttech/frontend-foundations": "0.3.1",
14
+ "@bolttech/ui-utils": "0.2.2",
15
15
  "react": "18.2.0",
16
16
  "react-dom": "18.2.0",
17
17
  "styled-components": "6.1.1"
@@ -9,6 +9,7 @@ export declare const DropdownWithHeaders: import("react").ForwardRefExoticCompon
9
9
  errorMessage?: string | undefined;
10
10
  required?: boolean | undefined;
11
11
  variant?: import("./molecules-dropdown.type").StyleVariants | undefined;
12
+ disableSearch?: boolean | undefined;
12
13
  onBlur?: ((value?: unknown) => void) | ((evt: import("react").FocusEvent<HTMLElement, Element>) => void) | undefined;
13
14
  onFocus?: ((value?: unknown) => void) | ((evt: import("react").FocusEvent<HTMLElement, Element>) => void) | undefined;
14
15
  } & {
@@ -9,6 +9,7 @@ export declare const Dropdown: import("react").ForwardRefExoticComponent<import(
9
9
  errorMessage?: string | undefined;
10
10
  required?: boolean | undefined;
11
11
  variant?: import("./molecules-dropdown.type").StyleVariants | undefined;
12
+ disableSearch?: boolean | undefined;
12
13
  onBlur?: ((value?: unknown) => void) | ((evt: import("react").FocusEvent<HTMLElement, Element>) => void) | undefined;
13
14
  onFocus?: ((value?: unknown) => void) | ((evt: import("react").FocusEvent<HTMLElement, Element>) => void) | undefined;
14
15
  } & {
@@ -16,6 +16,7 @@ Default props for Dropdown component
16
16
  @property errorMessage - An optional string to display as an error message for the dropdown
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
+ @property disableSearch - An optional boolean representing if the user can type and mobile phones should show the keyboard
19
20
  */
20
21
  type DefaultDropdownProps = {
21
22
  label: string;
@@ -26,6 +27,7 @@ type DefaultDropdownProps = {
26
27
  errorMessage?: string;
27
28
  required?: boolean;
28
29
  variant?: StyleVariants;
30
+ disableSearch?: boolean;
29
31
  onBlur?: ((value?: unknown) => void) | ((evt: React.FocusEvent<HTMLElement, Element>) => void);
30
32
  onFocus?: ((value?: unknown) => void) | ((evt: React.FocusEvent<HTMLElement, Element>) => void);
31
33
  };
@@ -1,2 +1,2 @@
1
1
  import { ReusableDropdownComponentProps } from './molecules-dropdown.type';
2
- export declare const ReusableDropdownComponent: ({ id, dataTestId, label, variant, required, inputValue, inputLabel, disabled, errorMessage, onChangeInputValue, onChangeInputLabel, setShowSelectComponent, showSelectComponent, setSelectedOptionOnInputValue, inputRef, placeholder, onBlur, onFocus, ...props }: ReusableDropdownComponentProps) => import("react/jsx-runtime").JSX.Element;
2
+ export declare const ReusableDropdownComponent: ({ id, dataTestId, label, variant, required, inputValue, inputLabel, disabled, errorMessage, onChangeInputValue, onChangeInputLabel, setShowSelectComponent, showSelectComponent, setSelectedOptionOnInputValue, disableSearch, inputRef, placeholder, onBlur, onFocus, ...props }: ReusableDropdownComponentProps) => import("react/jsx-runtime").JSX.Element;