@etsoo/materialui 1.3.80 → 1.3.82

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.
@@ -8,6 +8,10 @@ export type TextFieldExProps = TextFieldProps & {
8
8
  * Change delay (ms) to avoid repeatly dispatch onChange
9
9
  */
10
10
  changeDelay?: number;
11
+ /**
12
+ * Click clear button callback, return false to prevent the clear action
13
+ */
14
+ onClear?: () => boolean | void;
11
15
  /**
12
16
  * On enter click
13
17
  */
@@ -46,6 +50,10 @@ export declare const TextFieldEx: React.ForwardRefExoticComponent<(Omit<import("
46
50
  * Change delay (ms) to avoid repeatly dispatch onChange
47
51
  */
48
52
  changeDelay?: number;
53
+ /**
54
+ * Click clear button callback, return false to prevent the clear action
55
+ */
56
+ onClear?: () => boolean | void;
49
57
  /**
50
58
  * On enter click
51
59
  */
@@ -73,6 +81,10 @@ export declare const TextFieldEx: React.ForwardRefExoticComponent<(Omit<import("
73
81
  * Change delay (ms) to avoid repeatly dispatch onChange
74
82
  */
75
83
  changeDelay?: number;
84
+ /**
85
+ * Click clear button callback, return false to prevent the clear action
86
+ */
87
+ onClear?: () => boolean | void;
76
88
  /**
77
89
  * On enter click
78
90
  */
@@ -100,6 +112,10 @@ export declare const TextFieldEx: React.ForwardRefExoticComponent<(Omit<import("
100
112
  * Change delay (ms) to avoid repeatly dispatch onChange
101
113
  */
102
114
  changeDelay?: number;
115
+ /**
116
+ * Click clear button callback, return false to prevent the clear action
117
+ */
118
+ onClear?: () => boolean | void;
103
119
  /**
104
120
  * On enter click
105
121
  */
@@ -7,7 +7,7 @@ import { Keyboard } from "@etsoo/shared";
7
7
  import { ReactUtils, useCombinedRefs, useDelayedExecutor } from "@etsoo/react";
8
8
  export const TextFieldEx = React.forwardRef((props, ref) => {
9
9
  // Destructure
10
- const { changeDelay, error, fullWidth = true, helperText, InputLabelProps = {}, InputProps = {}, onChange, onKeyDown, onEnter, onVisibility, inputRef, readOnly, showClear, showPassword, type, variant = MUGlobal.textFieldVariant, ...rest } = props;
10
+ const { changeDelay, error, fullWidth = true, helperText, InputLabelProps = {}, InputProps = {}, onChange, onClear, onKeyDown, onEnter, onVisibility, inputRef, readOnly, showClear, showPassword, type, variant = MUGlobal.textFieldVariant, ...rest } = props;
11
11
  // Shrink
12
12
  InputLabelProps.shrink ?? (InputLabelProps.shrink = MUGlobal.searchFieldShrink);
13
13
  // State
@@ -32,10 +32,14 @@ export const TextFieldEx = React.forwardRef((props, ref) => {
32
32
  }
33
33
  };
34
34
  const clearClick = () => {
35
- if (input != null) {
36
- ReactUtils.triggerChange(input, "", false);
37
- input.focus();
35
+ if (input == null)
36
+ return;
37
+ if (onClear) {
38
+ if (onClear() === false)
39
+ return;
38
40
  }
41
+ ReactUtils.triggerChange(input, "", false);
42
+ input.focus();
39
43
  };
40
44
  const preventDefault = (e) => {
41
45
  // Prevent long press
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.3.80",
3
+ "version": "1.3.82",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -50,9 +50,9 @@
50
50
  "@emotion/css": "^11.13.0",
51
51
  "@emotion/react": "^11.13.0",
52
52
  "@emotion/styled": "^11.13.0",
53
- "@etsoo/appscript": "^1.5.4",
54
- "@etsoo/notificationbase": "^1.1.46",
55
- "@etsoo/react": "^1.7.61",
53
+ "@etsoo/appscript": "^1.5.5",
54
+ "@etsoo/notificationbase": "^1.1.47",
55
+ "@etsoo/react": "^1.7.62",
56
56
  "@etsoo/shared": "^1.2.44",
57
57
  "@mui/icons-material": "^5.16.6",
58
58
  "@mui/material": "^5.16.6",
@@ -19,6 +19,11 @@ export type TextFieldExProps = TextFieldProps & {
19
19
  */
20
20
  changeDelay?: number;
21
21
 
22
+ /**
23
+ * Click clear button callback, return false to prevent the clear action
24
+ */
25
+ onClear?: () => boolean | void;
26
+
22
27
  /**
23
28
  * On enter click
24
29
  */
@@ -71,6 +76,7 @@ export const TextFieldEx = React.forwardRef<
71
76
  InputLabelProps = {},
72
77
  InputProps = {},
73
78
  onChange,
79
+ onClear,
74
80
  onKeyDown,
75
81
  onEnter,
76
82
  onVisibility,
@@ -113,10 +119,14 @@ export const TextFieldEx = React.forwardRef<
113
119
  };
114
120
 
115
121
  const clearClick = () => {
116
- if (input != null) {
117
- ReactUtils.triggerChange(input, "", false);
118
- input.focus();
122
+ if (input == null) return;
123
+
124
+ if (onClear) {
125
+ if (onClear() === false) return;
119
126
  }
127
+
128
+ ReactUtils.triggerChange(input, "", false);
129
+ input.focus();
120
130
  };
121
131
 
122
132
  const preventDefault = (e: React.TouchEvent | React.MouseEvent) => {