@ssplib/react-components 0.0.264 → 0.0.266

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.
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- export declare function FixedAutoComplete({ name, title, required, list, defaultValue, onChange, xs, sm, watchValue, md, }: {
2
+ export declare function FixedAutoComplete({ name, title, required, list, defaultValue, onChange, xs, sm, watchValue, forceUpdate, md, }: {
3
3
  name: string;
4
4
  title: string;
5
5
  watchValue?: {
@@ -12,6 +12,7 @@ export declare function FixedAutoComplete({ name, title, required, list, default
12
12
  required?: boolean;
13
13
  onChange?: (id: number | undefined) => void;
14
14
  shouldRefetch?: boolean;
15
+ forceUpdate?: boolean;
15
16
  xs?: number;
16
17
  sm?: number;
17
18
  md?: number;
@@ -32,7 +32,7 @@ const lodash_get_1 = __importDefault(require("lodash.get"));
32
32
  const react_1 = __importStar(require("react"));
33
33
  const form_1 = require("../../../context/form");
34
34
  let useDefault = true;
35
- function FixedAutoComplete({ name, title, required = false, list, defaultValue, onChange = () => { }, xs = 12, sm, watchValue, md, }) {
35
+ function FixedAutoComplete({ name, title, required = false, list, defaultValue, onChange = () => { }, xs = 12, sm, watchValue, forceUpdate = false, md, }) {
36
36
  const context = (0, react_1.useContext)(form_1.FormContext);
37
37
  const [value, setValue] = (0, react_1.useState)(null);
38
38
  (0, react_1.useEffect)(() => {
@@ -40,11 +40,16 @@ function FixedAutoComplete({ name, title, required = false, list, defaultValue,
40
40
  context === null || context === void 0 ? void 0 : context.formSetValue(name, defaultValue.id);
41
41
  }, []);
42
42
  (0, react_1.useEffect)(() => {
43
- if (watchValue && useDefault) {
43
+ if (watchValue && (useDefault || forceUpdate)) {
44
44
  setValue(watchValue);
45
45
  context.formSetValue(name, watchValue.id);
46
46
  onChange(watchValue.id);
47
47
  }
48
+ else if (watchValue === undefined && (useDefault || forceUpdate)) {
49
+ setValue(null);
50
+ context.formSetValue(name, undefined);
51
+ onChange(undefined);
52
+ }
48
53
  }, [watchValue]);
49
54
  function handleAutoCompleteChange(value) {
50
55
  useDefault = false;
@@ -55,7 +60,7 @@ function FixedAutoComplete({ name, title, required = false, list, defaultValue,
55
60
  return;
56
61
  }
57
62
  setValue(null);
58
- context.formSetValue(name, '');
63
+ context.formSetValue(name, undefined);
59
64
  onChange(undefined);
60
65
  }
61
66
  return (react_1.default.createElement(material_1.Grid, Object.assign({ item: true }, { xs, sm, md }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ssplib/react-components",
3
- "version": "0.0.264",
3
+ "version": "0.0.266",
4
4
  "description": "SSP React Components",
5
5
  "main": "index.js",
6
6
  "author": "Pedro Henrique <sr.hudrick@gmail.com>",