@@ -27,7 +27,8 @@ $: valueLength = value?.toString()?.length
27
27
$: hasExceededMaxLength = maxlength && valueLength > maxlength
28
28
$: hasExceededMaxValue = maxValue && internalValue > maxValue
29
29
$: isLowerThanMinValue = minValue && internalValue < minValue
30
- $: error = hasExceededMaxValue || isLowerThanMinValue || hasExceededMaxLength || valueNotDivisibleByStep
30
+ $: showErrorIcon = hasExceededMaxValue || isLowerThanMinValue || hasExceededMaxLength || valueNotDivisibleByStep
31
+ $: error = showErrorIcon || (hasFocused && required && ! internalValue)
31
32
$: showCounter = maxlength && valueLength / maxlength > 0.85
32
33
$: valueNotDivisibleByStep = internalValue && (internalValue / Number (step)) % 1 !== 0
33
34
$: internalValue = Number (value) || ' '
@@ -64,7 +65,7 @@ const focus = (node) => autofocus && node.focus()
64
65
class:mdc-text-field--invalid ={error }
65
66
bind:this ={element }
66
67
>
67
- <i class =" material-icons" aria-hidden =" true" >attach_money</i >
68
+ <i class =" material-icons" class:error aria-hidden =" true" >attach_money</i >
68
69
<input
69
70
{step }
70
71
type =" number"
@@ -86,7 +87,7 @@ const focus = (node) => autofocus && node.focus()
86
87
{disabled }
87
88
{placeholder }
88
89
/>
89
- {#if error }
90
+ {#if showErrorIcon }
90
91
<span class =" mdc-text-field__affix mdc-text-field__affix--suffix"
91
92
><i class =" material-icons error" aria-hidden =" true" >error</i ></span
92
93
>
@@ -107,8 +108,7 @@ const focus = (node) => autofocus && node.focus()
107
108
<div class ="mdc-text-field-helper-text" class:opacity 1={required } id =" {labelID }-helper-id" aria-hidden =" true" >
108
109
{#if required && ! internalValue }
109
110
<span class ="required" class:error ={hasFocused }>*Required</span >
110
- {/if }
111
- {#if hasExceededMaxValue }
111
+ {:else if hasExceededMaxValue }
112
112
<span class ="error" >Maximum value allowed is {maxValue }</span >
113
113
{:else if isLowerThanMinValue }
114
114
<span class ="error" >Minimun value allowed is ({minValue })</span >
0 commit comments