Skip to content
This repository was archived by the owner on Sep 26, 2022. It is now read-only.

Commit db5854d

Browse files
Merge pull request #248 from V-ed/patch-2
fix(Textarea): Fix label not being reactive (#247)
2 parents 21e9b4a + 752e556 commit db5854d

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

packages/svelte-materialify/src/components/Textarea/Textarea.svelte

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,42 @@
3030
export let style = null;
3131
export let textarea = null;
3232
33-
let labelActive = !!placeholder || value;
33+
let focused = false;
34+
$: labelActive = !!placeholder || value || focused;
3435
let errorMessages = [];
3536
36-
function checkRules() {
37+
export function validate() {
3738
errorMessages = rules.map((r) => r(value)).filter((r) => typeof r === 'string');
3839
if (errorMessages.length) error = true;
3940
else {
4041
error = false;
4142
}
43+
return error;
4244
}
4345
4446
function onFocus() {
45-
labelActive = true;
47+
focused = true;
4648
}
4749
4850
function onBlur() {
49-
if (!value && !placeholder) labelActive = false;
50-
if (validateOnBlur) checkRules();
51+
focused = false;
52+
if (validateOnBlur) validate();
5153
}
5254
5355
function clear() {
5456
value = '';
55-
if (!placeholder) labelActive = false;
5657
}
5758
5859
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`;
6466
}
67+
68+
$: if (textarea && autogrow) updateTextareaHeight(value);
6569
</script>
6670

6771
<Input

0 commit comments

Comments
 (0)