noph-ui 0.13.2 → 0.13.4
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.
|
@@ -17,29 +17,51 @@
|
|
|
17
17
|
variant = 'filled',
|
|
18
18
|
placeholder = ' ',
|
|
19
19
|
element = $bindable(),
|
|
20
|
+
inputElement = $bindable(),
|
|
21
|
+
reportValidity = $bindable(),
|
|
22
|
+
checkValidity = $bindable(),
|
|
20
23
|
...attributes
|
|
21
24
|
}: TextFieldProps = $props()
|
|
22
25
|
|
|
23
26
|
let errorRaw: boolean = $state(error)
|
|
24
27
|
let errorTextRaw: string = $state(errorText)
|
|
25
28
|
let focusOnInvalid = $state(true)
|
|
26
|
-
let
|
|
29
|
+
let doValidity = $state(false)
|
|
30
|
+
|
|
31
|
+
reportValidity = () => {
|
|
32
|
+
if (inputElement) {
|
|
33
|
+
const valid = inputElement.reportValidity()
|
|
34
|
+
if (valid) {
|
|
35
|
+
errorRaw = error
|
|
36
|
+
errorTextRaw = errorText
|
|
37
|
+
}
|
|
38
|
+
return valid
|
|
39
|
+
}
|
|
40
|
+
return false
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
checkValidity = () => {
|
|
44
|
+
if (inputElement) {
|
|
45
|
+
return inputElement.checkValidity()
|
|
46
|
+
}
|
|
47
|
+
return false
|
|
48
|
+
}
|
|
49
|
+
|
|
27
50
|
$effect(() => {
|
|
28
51
|
errorRaw = error
|
|
29
52
|
errorTextRaw = errorText
|
|
30
53
|
})
|
|
31
|
-
let textElement: HTMLInputElement | HTMLTextAreaElement | undefined = $state()
|
|
32
54
|
|
|
33
55
|
$effect(() => {
|
|
34
|
-
if (
|
|
35
|
-
|
|
56
|
+
if (inputElement) {
|
|
57
|
+
inputElement.form?.addEventListener('reset', () => {
|
|
36
58
|
errorRaw = error
|
|
37
59
|
value = ''
|
|
38
60
|
})
|
|
39
|
-
|
|
40
|
-
|
|
61
|
+
inputElement.addEventListener('input', () => {
|
|
62
|
+
doValidity = true
|
|
41
63
|
})
|
|
42
|
-
|
|
64
|
+
inputElement.addEventListener('invalid', (event) => {
|
|
43
65
|
event.preventDefault()
|
|
44
66
|
const { currentTarget } = event as Event & {
|
|
45
67
|
currentTarget: HTMLInputElement | HTMLTextAreaElement
|
|
@@ -53,13 +75,10 @@
|
|
|
53
75
|
}
|
|
54
76
|
})
|
|
55
77
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
currentTarget: HTMLInputElement | HTMLTextAreaElement
|
|
59
|
-
}
|
|
60
|
-
if (checkValidity) {
|
|
78
|
+
inputElement.addEventListener('blur', () => {
|
|
79
|
+
if (doValidity) {
|
|
61
80
|
focusOnInvalid = false
|
|
62
|
-
if (
|
|
81
|
+
if (checkValidity()) {
|
|
63
82
|
errorRaw = error
|
|
64
83
|
errorTextRaw = errorText
|
|
65
84
|
}
|
|
@@ -131,7 +150,7 @@
|
|
|
131
150
|
aria-label={label}
|
|
132
151
|
{...attributes}
|
|
133
152
|
bind:value
|
|
134
|
-
bind:this={
|
|
153
|
+
bind:this={inputElement}
|
|
135
154
|
class="input"
|
|
136
155
|
{placeholder}
|
|
137
156
|
rows={attributes.rows || 2}
|
|
@@ -147,7 +166,7 @@
|
|
|
147
166
|
aria-label={label}
|
|
148
167
|
{...attributes}
|
|
149
168
|
bind:value
|
|
150
|
-
bind:this={
|
|
169
|
+
bind:this={inputElement}
|
|
151
170
|
class="input"
|
|
152
171
|
{placeholder}
|
|
153
172
|
aria-invalid={errorRaw}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { TextFieldProps } from './types.ts';
|
|
2
|
-
declare const TextField: import("svelte").Component<TextFieldProps, {}, "element" | "value">;
|
|
2
|
+
declare const TextField: import("svelte").Component<TextFieldProps, {}, "element" | "value" | "inputElement" | "reportValidity" | "checkValidity">;
|
|
3
3
|
type TextField = ReturnType<typeof TextField>;
|
|
4
4
|
export default TextField;
|
|
@@ -12,6 +12,9 @@ interface FieldProps {
|
|
|
12
12
|
end?: Snippet;
|
|
13
13
|
noAsterisk?: boolean;
|
|
14
14
|
element?: HTMLSpanElement;
|
|
15
|
+
inputElement?: HTMLInputElement | HTMLTextAreaElement;
|
|
16
|
+
reportValidity?: () => boolean;
|
|
17
|
+
checkValidity?: () => boolean;
|
|
15
18
|
}
|
|
16
19
|
export interface InputFieldProps extends HTMLInputAttributes, FieldProps {
|
|
17
20
|
type?: 'text' | 'password' | 'email' | 'number' | 'search' | 'tel' | 'url' | 'datetime-local';
|