@axinom/mosaic-ui 0.55.0-rc.8 → 0.55.0-rc.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axinom/mosaic-ui",
3
- "version": "0.55.0-rc.8",
3
+ "version": "0.55.0-rc.9",
4
4
  "description": "UI components for building Axinom Mosaic applications",
5
5
  "author": "Axinom",
6
6
  "license": "PROPRIETARY",
@@ -32,7 +32,7 @@
32
32
  "build-storybook": "storybook build"
33
33
  },
34
34
  "dependencies": {
35
- "@axinom/mosaic-core": "^0.4.28-rc.8",
35
+ "@axinom/mosaic-core": "^0.4.28-rc.9",
36
36
  "@faker-js/faker": "^7.4.0",
37
37
  "@geoffcox/react-splitter": "^2.1.2",
38
38
  "@mui/base": "5.0.0-beta.40",
@@ -107,5 +107,5 @@
107
107
  "publishConfig": {
108
108
  "access": "public"
109
109
  },
110
- "gitHead": "ecc3d56b36e323942ecff8e598c3323edd62bcb6"
110
+ "gitHead": "cdb30d7d017d4b90bda8669d35374c9c9c81325f"
111
111
  }
@@ -1,5 +1,10 @@
1
1
  import clsx from 'clsx';
2
- import React, { ChangeEvent, InputHTMLAttributes, useEffect } from 'react';
2
+ import React, {
3
+ ChangeEvent,
4
+ InputHTMLAttributes,
5
+ useEffect,
6
+ useRef,
7
+ } from 'react';
3
8
  import { executeIfRefAvailable } from '../../../helpers/utils';
4
9
  import { BaseFormControl, BaseInputEvents } from '../Form.models';
5
10
  import { FormElementContainer } from '../FormElementContainer';
@@ -50,7 +55,7 @@ export const SingleLineText: React.FC<SingleLineTextProps> = ({
50
55
  error,
51
56
  autoFocus = false,
52
57
  autoComplete,
53
- innerRef = React.createRef(),
58
+ innerRef: refFromParent,
54
59
  defaultValue,
55
60
  onChange,
56
61
  onBlur,
@@ -59,9 +64,13 @@ export const SingleLineText: React.FC<SingleLineTextProps> = ({
59
64
  inputProps,
60
65
  ...rest
61
66
  }) => {
67
+ // Create a local ref if no ref is passed from the parent
68
+ const localRef = useRef<HTMLInputElement>(null);
69
+ const innerRef = refFromParent || localRef;
70
+
62
71
  const errorMsg: string | undefined = error;
63
72
  const DUMMY_PWD = '0000000000';
64
- const isPasswordField = type === 'password' ? true : false;
73
+ const isPasswordField = type === 'password';
65
74
 
66
75
  useEffect(() => {
67
76
  if (innerRef.current) {
@@ -70,15 +79,22 @@ export const SingleLineText: React.FC<SingleLineTextProps> = ({
70
79
  }, [innerRef, value]);
71
80
 
72
81
  useEffect(() => {
73
- if (isPasswordField && isSet) {
82
+ // Only set the dummy password if the field is a password field and the value is not set
83
+ // and the field is not focused
84
+ if (
85
+ isPasswordField &&
86
+ isSet &&
87
+ !value &&
88
+ document.activeElement !== innerRef.current
89
+ ) {
74
90
  executeIfRefAvailable(innerRef, (input) => {
75
91
  input.value = DUMMY_PWD;
76
92
  });
77
93
  }
78
- }, [innerRef, isPasswordField, isSet]);
94
+ }, [innerRef, isPasswordField, isSet, value]);
79
95
 
80
96
  const onFocusWrapper = (e: ChangeEvent<HTMLInputElement>): void => {
81
- if (type === 'password' && isSet && !value) {
97
+ if (isPasswordField && isSet && !value) {
82
98
  executeIfRefAvailable(innerRef, (input) => {
83
99
  input.value = '';
84
100
  });
@@ -86,7 +102,7 @@ export const SingleLineText: React.FC<SingleLineTextProps> = ({
86
102
  onFocus?.(e);
87
103
  };
88
104
  const onBlurWrapper = (e: ChangeEvent<HTMLInputElement>): void => {
89
- if (type === 'password' && isSet && !value) {
105
+ if (isPasswordField && isSet && !value) {
90
106
  executeIfRefAvailable(innerRef, (input) => {
91
107
  input.value = DUMMY_PWD;
92
108
  });