File tree 2 files changed +16
-5
lines changed
2 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ let textarea = {}
19
19
let height = ' '
20
20
21
21
$: hasReachedMaxLength = maxlength && value .length >= maxlength
22
+ $: error = hasReachedMaxLength
22
23
23
24
onMount (() => {
24
25
resize ()
@@ -52,6 +53,9 @@ const focus = async (node) => {
52
53
label {
53
54
width : 100% ;
54
55
}
56
+ .error {
57
+ color : var (--mdc-theme-status-error , var (--mdc-theme-error )) !important ;
58
+ }
55
59
</style >
56
60
57
61
<label
@@ -79,14 +83,14 @@ label {
79
83
on:blur
80
84
/>
81
85
{#if maxlength }
82
- <span class ="mdc-text-field-character-counter" >0 / {maxlength }</span >
86
+ <span class ="mdc-text-field-character-counter" class:error >0 / {maxlength }</span >
83
87
{/if }
84
88
<span class =" mdc-notched-outline" >
85
89
<span class =" mdc-notched-outline__leading" />
86
90
87
91
{#if label }
88
92
<span class =" mdc-notched-outline__notch" >
89
- <span class ="mdc-floating-label" id ={labelID }>
93
+ <span class ="mdc-floating-label" class:error id ={labelID }>
90
94
{label }
91
95
</span >
92
96
</span >
Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ let mdcTextField = {}
21
21
$: mdcTextField .value = value
22
22
$: width = ` ${ element .offsetWidth } px`
23
23
$: hasReachedMaxLength = maxlength && value .length >= maxlength
24
+ $: error = hasReachedMaxLength
25
+ $: showCounter = maxlength && value .length / maxlength > 0.85
24
26
25
27
onMount (() => {
26
28
mdcTextField = new MDCTextField (element)
@@ -53,6 +55,9 @@ const focus = (node) => autofocus && node.focus()
53
55
float : right ;
54
56
padding-right : 1rem ;
55
57
}
58
+ .error {
59
+ color : var (--mdc-theme-status-error , var (--mdc-theme-error ));
60
+ }
56
61
</style >
57
62
58
63
<label
@@ -82,7 +87,7 @@ const focus = (node) => autofocus && node.focus()
82
87
<span class =" mdc-notched-outline__leading" />
83
88
{#if label }
84
89
<span class =" mdc-notched-outline__notch" >
85
- <span class ="mdc-floating-label" class:label-margin ={icon } id ={labelID }>
90
+ <span class ="mdc-floating-label" class:label-margin ={icon } class:error id ={labelID }>
86
91
{label }
87
92
</span >
88
93
</span >
@@ -94,9 +99,11 @@ const focus = (node) => autofocus && node.focus()
94
99
{#if required && ! value }
95
100
<div class =" required d-inline" >*Required</div >
96
101
{/if }
97
- {#if maxlength }
102
+ {#if showCounter }
98
103
<div class =" mdc-text-field-helper-line" >
99
- <div class ="mdc-text-field-character-counter" >{value .length } / {maxlength }</div >
104
+ <div class =" mdc-text-field-character-counter" class:error >
105
+ {value .length } / {maxlength }
106
+ </div >
100
107
</div >
101
108
{/if }
102
109
</div >
You can’t perform that action at this time.
0 commit comments