@etsoo/materialui 1.4.41 → 1.4.43

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/lib/InputField.js CHANGED
@@ -10,12 +10,14 @@ import { MUGlobal } from "./MUGlobal";
10
10
  */
11
11
  export const InputField = React.forwardRef((props, ref) => {
12
12
  // Destruct
13
- const { changeDelay, InputLabelProps = {}, InputProps = {}, onChange, onChangeDelay, readOnly, size = MUGlobal.inputFieldSize, variant = MUGlobal.inputFieldVariant, minChars = 0, ...rest } = props;
13
+ const { changeDelay, InputLabelProps = {}, InputProps = {}, inputProps = {}, onChange, onChangeDelay, readOnly, size = MUGlobal.inputFieldSize, variant = MUGlobal.inputFieldVariant, minChars = 0, ...rest } = props;
14
14
  // Shrink
15
15
  InputLabelProps.shrink ??= MUGlobal.searchFieldShrink;
16
16
  // Read only
17
17
  if (readOnly != null)
18
18
  InputProps.readOnly = readOnly;
19
+ // Min characters
20
+ inputProps["data-min-chars"] = minChars;
19
21
  const isMounted = React.useRef(true);
20
22
  const createDelayed = () => {
21
23
  if (changeDelay != null && changeDelay >= 1) {
@@ -42,5 +44,5 @@ export const InputField = React.forwardRef((props, ref) => {
42
44
  };
43
45
  }, []);
44
46
  // Layout
45
- return (_jsx(TextField, { ref: ref, InputLabelProps: InputLabelProps, InputProps: InputProps, onChange: onChangeEx, size: size, variant: variant, ...rest }));
47
+ return (_jsx(TextField, { ref: ref, InputLabelProps: InputLabelProps, InputProps: InputProps, inputProps: inputProps, onChange: onChangeEx, size: size, variant: variant, ...rest }));
46
48
  });
package/lib/SearchBar.js CHANGED
@@ -47,6 +47,21 @@ const setChildState = (child, enabled) => {
47
47
  input.disabled = !enabled;
48
48
  }
49
49
  };
50
+ function checkFormEvent(event) {
51
+ if (event.nativeEvent.cancelable && !event.nativeEvent.composed)
52
+ return true;
53
+ if (event.target instanceof HTMLInputElement ||
54
+ event.target instanceof HTMLTextAreaElement) {
55
+ const minChars = NumberUtils.parse(event.target.dataset.minChars);
56
+ if (minChars != null && minChars > 0) {
57
+ const len = event.target.value.length;
58
+ if (len > 0 && len < minChars) {
59
+ return true;
60
+ }
61
+ }
62
+ }
63
+ return false;
64
+ }
50
65
  /**
51
66
  * Search bar
52
67
  * @param props Props
@@ -172,7 +187,7 @@ export function SearchBar(props) {
172
187
  const hasMoreItems = moreItems.length > 0;
173
188
  // Handle main form
174
189
  const handleForm = (event) => {
175
- if (event.nativeEvent.cancelable && !event.nativeEvent.composed)
190
+ if (checkFormEvent(event))
176
191
  return;
177
192
  if (state.form == null)
178
193
  state.form = event.currentTarget;
@@ -184,18 +199,8 @@ export function SearchBar(props) {
184
199
  };
185
200
  // More form change
186
201
  const moreFormChange = (event) => {
187
- if (event.nativeEvent.cancelable && !event.nativeEvent.composed)
202
+ if (checkFormEvent(event))
188
203
  return;
189
- if (event.target instanceof HTMLInputElement ||
190
- event.target instanceof HTMLTextAreaElement) {
191
- const minChars = NumberUtils.parse(event.target.dataset.minChars);
192
- if (minChars != null && minChars > 0) {
193
- const len = event.target.value.length;
194
- if (len > 0 && len < minChars) {
195
- return;
196
- }
197
- }
198
- }
199
204
  if (state.moreForm == null)
200
205
  state.moreForm = event.currentTarget;
201
206
  delayed.call();
@@ -10,12 +10,14 @@ import { MUGlobal } from "./MUGlobal";
10
10
  */
11
11
  export function SearchField(props) {
12
12
  // Destruct
13
- const { changeDelay, InputLabelProps = {}, InputProps = {}, onChange, readOnly, size = MUGlobal.searchFieldSize, variant = MUGlobal.searchFieldVariant, minChars = 0, ...rest } = props;
13
+ const { changeDelay, InputLabelProps = {}, InputProps = {}, inputProps = {}, onChange, readOnly, size = MUGlobal.searchFieldSize, variant = MUGlobal.searchFieldVariant, minChars = 0, ...rest } = props;
14
14
  // Shrink
15
15
  InputLabelProps.shrink ??= MUGlobal.searchFieldShrink;
16
16
  // Read only
17
17
  if (readOnly != null)
18
18
  InputProps.readOnly = readOnly;
19
+ // Min characters
20
+ inputProps["data-min-chars"] = minChars;
19
21
  const isMounted = React.useRef(true);
20
22
  const delayed = onChange != null && changeDelay != null && changeDelay >= 1
21
23
  ? useDelayedExecutor(onChange, changeDelay)
@@ -40,5 +42,5 @@ export function SearchField(props) {
40
42
  };
41
43
  }, []);
42
44
  // Layout
43
- return (_jsx(TextField, { InputLabelProps: InputLabelProps, InputProps: InputProps, onChange: onChangeEx, size: size, variant: variant, ...rest }));
45
+ return (_jsx(TextField, { InputLabelProps: InputLabelProps, InputProps: InputProps, inputProps: inputProps, onChange: onChangeEx, size: size, variant: variant, ...rest }));
44
46
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.4.41",
3
+ "version": "1.4.43",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",
@@ -42,6 +42,7 @@ export const InputField = React.forwardRef<HTMLDivElement, InputFieldProps>(
42
42
  changeDelay,
43
43
  InputLabelProps = {},
44
44
  InputProps = {},
45
+ inputProps = {},
45
46
  onChange,
46
47
  onChangeDelay,
47
48
  readOnly,
@@ -57,6 +58,9 @@ export const InputField = React.forwardRef<HTMLDivElement, InputFieldProps>(
57
58
  // Read only
58
59
  if (readOnly != null) InputProps.readOnly = readOnly;
59
60
 
61
+ // Min characters
62
+ inputProps["data-min-chars"] = minChars;
63
+
60
64
  const isMounted = React.useRef(true);
61
65
  const createDelayed = () => {
62
66
  if (changeDelay != null && changeDelay >= 1) {
@@ -93,6 +97,7 @@ export const InputField = React.forwardRef<HTMLDivElement, InputFieldProps>(
93
97
  ref={ref}
94
98
  InputLabelProps={InputLabelProps}
95
99
  InputProps={InputProps}
100
+ inputProps={inputProps}
96
101
  onChange={onChangeEx}
97
102
  size={size}
98
103
  variant={variant}
package/src/SearchBar.tsx CHANGED
@@ -81,6 +81,25 @@ const setChildState = (child: Element, enabled: boolean) => {
81
81
  }
82
82
  };
83
83
 
84
+ function checkFormEvent(event: React.FormEvent<HTMLFormElement>) {
85
+ if (event.nativeEvent.cancelable && !event.nativeEvent.composed) return true;
86
+
87
+ if (
88
+ event.target instanceof HTMLInputElement ||
89
+ event.target instanceof HTMLTextAreaElement
90
+ ) {
91
+ const minChars = NumberUtils.parse(event.target.dataset.minChars);
92
+ if (minChars != null && minChars > 0) {
93
+ const len = event.target.value.length;
94
+ if (len > 0 && len < minChars) {
95
+ return true;
96
+ }
97
+ }
98
+ }
99
+
100
+ return false;
101
+ }
102
+
84
103
  /**
85
104
  * Search bar
86
105
  * @param props Props
@@ -243,7 +262,7 @@ export function SearchBar(props: SearchBarProps) {
243
262
 
244
263
  // Handle main form
245
264
  const handleForm = (event: React.FormEvent<HTMLFormElement>) => {
246
- if (event.nativeEvent.cancelable && !event.nativeEvent.composed) return;
265
+ if (checkFormEvent(event)) return;
247
266
 
248
267
  if (state.form == null) state.form = event.currentTarget;
249
268
 
@@ -257,20 +276,7 @@ export function SearchBar(props: SearchBarProps) {
257
276
 
258
277
  // More form change
259
278
  const moreFormChange = (event: React.FormEvent<HTMLFormElement>) => {
260
- if (event.nativeEvent.cancelable && !event.nativeEvent.composed) return;
261
-
262
- if (
263
- event.target instanceof HTMLInputElement ||
264
- event.target instanceof HTMLTextAreaElement
265
- ) {
266
- const minChars = NumberUtils.parse(event.target.dataset.minChars);
267
- if (minChars != null && minChars > 0) {
268
- const len = event.target.value.length;
269
- if (len > 0 && len < minChars) {
270
- return;
271
- }
272
- }
273
- }
279
+ if (checkFormEvent(event)) return;
274
280
 
275
281
  if (state.moreForm == null) state.moreForm = event.currentTarget;
276
282
 
@@ -34,6 +34,7 @@ export function SearchField(props: SearchFieldProps) {
34
34
  changeDelay,
35
35
  InputLabelProps = {},
36
36
  InputProps = {},
37
+ inputProps = {},
37
38
  onChange,
38
39
  readOnly,
39
40
  size = MUGlobal.searchFieldSize,
@@ -48,6 +49,9 @@ export function SearchField(props: SearchFieldProps) {
48
49
  // Read only
49
50
  if (readOnly != null) InputProps.readOnly = readOnly;
50
51
 
52
+ // Min characters
53
+ inputProps["data-min-chars"] = minChars;
54
+
51
55
  const isMounted = React.useRef(true);
52
56
  const delayed =
53
57
  onChange != null && changeDelay != null && changeDelay >= 1
@@ -83,6 +87,7 @@ export function SearchField(props: SearchFieldProps) {
83
87
  <TextField
84
88
  InputLabelProps={InputLabelProps}
85
89
  InputProps={InputProps}
90
+ inputProps={inputProps}
86
91
  onChange={onChangeEx}
87
92
  size={size}
88
93
  variant={variant}