@etsoo/materialui 1.4.42 → 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/SearchBar.js +17 -12
- package/package.json +1 -1
- package/src/SearchBar.tsx +21 -15
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
|
|
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
|
|
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();
|
package/package.json
CHANGED
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
|
|
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
|
|
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
|
|