@nr1e/qwik-ui 2.0.6 → 2.0.7

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.
@@ -91,16 +91,22 @@ const TextField = qwik.component$((props) => {
91
91
  return;
92
92
  }
93
93
  }
94
+ if (value.value !== result.output) {
95
+ value.value = result.output;
96
+ }
94
97
  }
95
98
  if (props.validate$) {
96
99
  const result = await props.validate$(value.value);
97
- if (result) {
100
+ if (!result.success) {
98
101
  if (props.valid) {
99
102
  props.valid.value = false;
100
103
  }
101
- error.value = result;
104
+ error.value = result.error;
102
105
  return;
103
106
  }
107
+ if (value.value !== result.output) {
108
+ value.value = result.output;
109
+ }
104
110
  }
105
111
  if (props.valid) {
106
112
  props.valid.value = true;
@@ -134,7 +140,7 @@ const TextField = qwik.component$((props) => {
134
140
  name: "left"
135
141
  }),
136
142
  /* @__PURE__ */ jsxRuntime.jsx("input", {
137
- type: "text",
143
+ type: props.type || "text",
138
144
  ...props.id && {
139
145
  id: props.id
140
146
  },
@@ -153,6 +159,7 @@ const TextField = qwik.component$((props) => {
153
159
  touched.value = true;
154
160
  value.value = target.value;
155
161
  await validate();
162
+ target.value = value.value ?? "";
156
163
  if (props.onBlur$) {
157
164
  props.onBlur$(e, target.value, error);
158
165
  }
@@ -89,16 +89,22 @@ const TextField = component$((props) => {
89
89
  return;
90
90
  }
91
91
  }
92
+ if (value.value !== result.output) {
93
+ value.value = result.output;
94
+ }
92
95
  }
93
96
  if (props.validate$) {
94
97
  const result = await props.validate$(value.value);
95
- if (result) {
98
+ if (!result.success) {
96
99
  if (props.valid) {
97
100
  props.valid.value = false;
98
101
  }
99
- error.value = result;
102
+ error.value = result.error;
100
103
  return;
101
104
  }
105
+ if (value.value !== result.output) {
106
+ value.value = result.output;
107
+ }
102
108
  }
103
109
  if (props.valid) {
104
110
  props.valid.value = true;
@@ -132,7 +138,7 @@ const TextField = component$((props) => {
132
138
  name: "left"
133
139
  }),
134
140
  /* @__PURE__ */ jsx("input", {
135
- type: "text",
141
+ type: props.type || "text",
136
142
  ...props.id && {
137
143
  id: props.id
138
144
  },
@@ -151,6 +157,7 @@ const TextField = component$((props) => {
151
157
  touched.value = true;
152
158
  value.value = target.value;
153
159
  await validate();
160
+ target.value = value.value ?? "";
154
161
  if (props.onBlur$) {
155
162
  props.onBlur$(e, target.value, error);
156
163
  }
@@ -1,7 +1,32 @@
1
1
  import { QRL, Signal } from '@builder.io/qwik';
2
2
  import * as v from 'valibot';
3
+ /**
4
+ * The type of the input field.
5
+ */
6
+ export type TextFieldType = 'text' | 'date' | 'email' | 'number' | 'tel' | 'url';
7
+ /**
8
+ * The result of validating a form input.
9
+ */
10
+ export type TextFieldValidationResult = {
11
+ /**
12
+ * True if validation was successful. False if validation failed.
13
+ */
14
+ success: boolean;
15
+ /**
16
+ * The error message if validation failed.
17
+ */
18
+ error?: string;
19
+ /**
20
+ * The normalized value of the input after successful validation.
21
+ */
22
+ output: string | null | undefined;
23
+ };
24
+ /**
25
+ * Properties for the TextField component.
26
+ */
3
27
  export interface TextFieldProps {
4
28
  id?: string;
29
+ type?: TextFieldType;
5
30
  label?: string;
6
31
  name?: string;
7
32
  value?: string | null | Signal<string | null | undefined>;
@@ -10,19 +35,47 @@ export interface TextFieldProps {
10
35
  maxLength?: number;
11
36
  required?: boolean;
12
37
  disabled?: boolean | Signal<boolean>;
38
+ /**
39
+ * Called when the input loses focus.
40
+ */
13
41
  onBlur$?: QRL<(event: FocusEvent, value: string, error: Signal<string | undefined>) => void>;
42
+ /**
43
+ * Called when the input value changes.
44
+ */
14
45
  onInput$?: QRL<(event: InputEvent, value: string, error: Signal<string | undefined>) => void>;
46
+ /**
47
+ * Called on blur or input events
48
+ */
15
49
  onEvent$?: QRL<(type: 'blur' | 'input', event: FocusEvent | InputEvent, value: string, error: Signal<string | undefined>) => void>;
16
- validate$?: QRL<(value: string | null | undefined) => string | undefined>;
50
+ /**
51
+ * Validates the form input. This is called on input and blur events.
52
+ */
53
+ validate$?: QRL<(value: string | null | undefined) => TextFieldValidationResult>;
54
+ /**
55
+ * Called to validate the form input. This is called on input and blur events
56
+ * and is an alternative to the validate$ prop.
57
+ */
17
58
  schema$?: QRL<() => v.BaseSchema<any, any, any>>;
59
+ /**
60
+ * An optional signal that indicates whether the input is valid.
61
+ */
18
62
  valid?: Signal<undefined | boolean>;
19
63
  /**
20
64
  * Increment the value of this signal to reset the input to its original value.
21
65
  */
22
66
  triggerReset?: Signal<number>;
23
67
  /**
24
- * Increment the value of this signal to force validation to execute.
68
+ * Increment the value of this signal to force validation to execute. Be
69
+ * aware that this will also cause the input to be touched, which will
70
+ * display the error message if one exists.
25
71
  */
26
72
  triggerValidation?: Signal<number>;
27
73
  }
74
+ /**
75
+ * A standardized text input field meant to be used independently or with Qwik
76
+ * Modular Forms.
77
+ *
78
+ * Be aware that the normalized value of the input from validation is reflected
79
+ * back into the text field automatically on blur.
80
+ */
28
81
  export declare const TextField: import("@builder.io/qwik").Component<TextFieldProps>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nr1e/qwik-ui",
3
- "version": "2.0.6",
3
+ "version": "2.0.7",
4
4
  "description": "NR1E Qwik UI Library",
5
5
  "author": "NR1E, Inc.",
6
6
  "publishConfig": {