@greghowe79/the-lib 0.8.0 → 0.8.2

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.
@@ -32,8 +32,12 @@ const Input = qwik.component$(({ id, type, placeholder, value, error, onValidate
32
32
  const showError = error ?? internalError;
33
33
  const inputHandler = qwik.$(async (_, elem) => {
34
34
  if (type === "tel") {
35
- if (!/^[0-9]*$/.test(elem.value)) return;
36
- if (value) value.value = elem.value;
35
+ if (!/^[0-9]*$/.test(elem.value)) {
36
+ if (value) {
37
+ elem.value = value.value;
38
+ }
39
+ return;
40
+ }
37
41
  }
38
42
  if (value) value.value = elem.value;
39
43
  if (onInput$) {
@@ -44,6 +48,12 @@ const Input = qwik.component$(({ id, type, placeholder, value, error, onValidate
44
48
  if (!error) internalError.value = result;
45
49
  }
46
50
  });
51
+ const beforeInputHandler = qwik.$((event) => {
52
+ const data = event.data;
53
+ if (data && /[^0-9]/.test(data)) {
54
+ event.preventDefault();
55
+ }
56
+ });
47
57
  return /* @__PURE__ */ jsxRuntime.jsxs("div", {
48
58
  class: "input-container",
49
59
  children: [
@@ -103,7 +113,8 @@ const Input = qwik.component$(({ id, type, placeholder, value, error, onValidate
103
113
  placeholder,
104
114
  "bind:value": value,
105
115
  onInput$: inputHandler,
106
- onBlur$: inputHandler
116
+ onBlur$: inputHandler,
117
+ onBeforeInput$: beforeInputHandler
107
118
  })
108
119
  ]
109
120
  })
@@ -30,8 +30,12 @@ const Input = component$(({ id, type, placeholder, value, error, onValidate$, on
30
30
  const showError = error ?? internalError;
31
31
  const inputHandler = $(async (_, elem) => {
32
32
  if (type === "tel") {
33
- if (!/^[0-9]*$/.test(elem.value)) return;
34
- if (value) value.value = elem.value;
33
+ if (!/^[0-9]*$/.test(elem.value)) {
34
+ if (value) {
35
+ elem.value = value.value;
36
+ }
37
+ return;
38
+ }
35
39
  }
36
40
  if (value) value.value = elem.value;
37
41
  if (onInput$) {
@@ -42,6 +46,12 @@ const Input = component$(({ id, type, placeholder, value, error, onValidate$, on
42
46
  if (!error) internalError.value = result;
43
47
  }
44
48
  });
49
+ const beforeInputHandler = $((event) => {
50
+ const data = event.data;
51
+ if (data && /[^0-9]/.test(data)) {
52
+ event.preventDefault();
53
+ }
54
+ });
45
55
  return /* @__PURE__ */ jsxs("div", {
46
56
  class: "input-container",
47
57
  children: [
@@ -101,7 +111,8 @@ const Input = component$(({ id, type, placeholder, value, error, onValidate$, on
101
111
  placeholder,
102
112
  "bind:value": value,
103
113
  onInput$: inputHandler,
104
- onBlur$: inputHandler
114
+ onBlur$: inputHandler,
115
+ onBeforeInput$: beforeInputHandler
105
116
  })
106
117
  ]
107
118
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@greghowe79/the-lib",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
4
4
  "description": "Collection of fast components for Qwik",
5
5
  "main": "./lib/index.qwik.mjs",
6
6
  "qwik": "./lib/index.qwik.mjs",