@dartech/arsenal-ui 1.3.84 → 1.3.85

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.js CHANGED
@@ -709,9 +709,10 @@ const ControlAutocomplete = _a => {
709
709
  options = [],
710
710
  multiple,
711
711
  textFieldProps = {},
712
- disableCloseOnSelect
712
+ disableCloseOnSelect,
713
+ useStringValue
713
714
  } = _a,
714
- autocompleteProps = __rest(_a, ["control", "validate", "name", "label", "required", "defaultValue", "disabled", "hideErrorMessage", "onChange", "labelKey", "valueKey", "options", "multiple", "textFieldProps", "disableCloseOnSelect"]);
715
+ autocompleteProps = __rest(_a, ["control", "validate", "name", "label", "required", "defaultValue", "disabled", "hideErrorMessage", "onChange", "labelKey", "valueKey", "options", "multiple", "textFieldProps", "disableCloseOnSelect", "useStringValue"]);
715
716
  const _b = useController({
716
717
  name,
717
718
  control,
@@ -724,14 +725,16 @@ const ControlAutocomplete = _a => {
724
725
  _c = _b.field,
725
726
  {
726
727
  ref,
727
- onChange
728
+ onChange,
729
+ value
728
730
  } = _c,
729
- fieldProps = __rest(_c, ["ref", "onChange"]),
731
+ fieldProps = __rest(_c, ["ref", "onChange", "value"]),
730
732
  {
731
733
  fieldState: {
732
734
  error
733
735
  }
734
736
  } = _b;
737
+ const [localValue, setLocalValue] = useState();
735
738
  const {
736
739
  getOptionLabel,
737
740
  isOptionEqualToValue,
@@ -741,9 +744,16 @@ const ControlAutocomplete = _a => {
741
744
  labelKey
742
745
  });
743
746
  const handleChange = (_, value) => {
744
- onChange(value);
747
+ onChange(useStringValue ? value[valueKey] : value);
748
+ setLocalValue(value);
745
749
  };
750
+ useEffect(() => {
751
+ if (typeof value === 'string' && valueKey && useStringValue && !localValue && options.length && !!options[0] && typeof options[0] === 'object') {
752
+ setLocalValue(options.find(el => el[valueKey] === value));
753
+ }
754
+ }, [localValue, options, useStringValue, value, valueKey]);
746
755
  return jsx(Autocomplete, Object.assign({}, fieldProps, {
756
+ value: useStringValue ? localValue !== null && localValue !== void 0 ? localValue : null : value,
747
757
  fullWidth: true,
748
758
  disablePortal: true,
749
759
  size: "small",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dartech/arsenal-ui",
3
- "version": "1.3.84",
3
+ "version": "1.3.85",
4
4
  "author": "DAR",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -60,10 +60,11 @@ export type ControlAutocompleteProps = Omit<AutocompleteProps<unknown, boolean,
60
60
  */
61
61
  options: string[] | unknown[];
62
62
  textFieldProps?: TextFieldProps;
63
+ useStringValue?: boolean;
63
64
  };
64
65
  /**
65
66
  * Material UI `Autocomplete` controlled component. Used with react-hook-form
66
67
  * @category Forms
67
68
  */
68
- export declare const ControlAutocomplete: ({ control, validate, name, label, required, defaultValue, disabled, hideErrorMessage, onChange: customOnChange, labelKey, valueKey, options, multiple, textFieldProps, disableCloseOnSelect, ...autocompleteProps }: ControlAutocompleteProps) => JSX.Element;
69
+ export declare const ControlAutocomplete: ({ control, validate, name, label, required, defaultValue, disabled, hideErrorMessage, onChange: customOnChange, labelKey, valueKey, options, multiple, textFieldProps, disableCloseOnSelect, useStringValue, ...autocompleteProps }: ControlAutocompleteProps) => JSX.Element;
69
70
  export default ControlAutocomplete;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  type Props = {
2
3
  name: string;
3
4
  label?: string;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  type Props = {
2
3
  name: string;
3
4
  label?: string;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  type Props = {
2
3
  name: string;
3
4
  format: string;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  type Props = {
2
3
  name: string;
3
4
  label?: string;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  type Props = {
2
3
  name: string;
3
4
  label?: string;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { PropertyUnion } from '../../../interfaces';
2
3
  type PropertyItemProps = {
3
4
  property: PropertyUnion;