This repository was archived by the owner on Sep 26, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +15
-11
lines changed
packages/svelte-materialify/src/components/Textarea Expand file tree Collapse file tree 1 file changed +15
-11
lines changed Original file line number Diff line number Diff line change 30
30
export let style = null ;
31
31
export let textarea = null ;
32
32
33
- let labelActive = !! placeholder || value;
33
+ let focused = false ;
34
+ $: labelActive = !! placeholder || value || focused;
34
35
let errorMessages = [];
35
36
36
- function checkRules () {
37
+ export function validate () {
37
38
errorMessages = rules .map ((r ) => r (value)).filter ((r ) => typeof r === ' string' );
38
39
if (errorMessages .length ) error = true ;
39
40
else {
40
41
error = false ;
41
42
}
43
+ return error;
42
44
}
43
45
44
46
function onFocus () {
45
- labelActive = true ;
47
+ focused = true ;
46
48
}
47
49
48
50
function onBlur () {
49
- if ( ! value && ! placeholder) labelActive = false ;
50
- if (validateOnBlur) checkRules ();
51
+ focused = false ;
52
+ if (validateOnBlur) validate ();
51
53
}
52
54
53
55
function clear () {
54
56
value = ' ' ;
55
- if (! placeholder) labelActive = false ;
56
57
}
57
58
58
59
function onInput () {
59
- if (! validateOnBlur) checkRules ();
60
- if (autogrow) {
61
- textarea .style .height = ' auto' ;
62
- textarea .style .height = ` ${ textarea .scrollHeight } px` ;
63
- }
60
+ if (! validateOnBlur) validate ();
61
+ }
62
+
63
+ function updateTextareaHeight () {
64
+ textarea .style .height = ' auto' ;
65
+ textarea .style .height = ` ${ textarea .scrollHeight } px` ;
64
66
}
67
+
68
+ $: if (textarea && autogrow) updateTextareaHeight (value);
65
69
</script >
66
70
67
71
<Input
You can’t perform that action at this time.
0 commit comments