Skip to content

Commit 925a6ac

Browse files
committed
fix(TextInput): show appropriate icons/colors
1 parent b84548a commit 925a6ac

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

Diff for: components/mdc/TextInput/MoneyInput.svelte

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ $: valueLength = value?.toString()?.length
2727
$: hasExceededMaxLength = maxlength && valueLength > maxlength
2828
$: hasExceededMaxValue = maxValue && internalValue > maxValue
2929
$: isLowerThanMinValue = minValue && internalValue < minValue
30-
$: error = hasExceededMaxValue || isLowerThanMinValue || hasExceededMaxLength || valueNotDivisibleByStep
30+
$: showErrorIcon = hasExceededMaxValue || isLowerThanMinValue || hasExceededMaxLength || valueNotDivisibleByStep
31+
$: error = showErrorIcon || (hasFocused && required && !internalValue)
3132
$: showCounter = maxlength && valueLength / maxlength > 0.85
3233
$: valueNotDivisibleByStep = internalValue && (internalValue / Number(step)) % 1 !== 0
3334
$: internalValue = Number(value) || ''
@@ -64,7 +65,7 @@ const focus = (node) => autofocus && node.focus()
6465
class:mdc-text-field--invalid={error}
6566
bind:this={element}
6667
>
67-
<i class="material-icons" aria-hidden="true">attach_money</i>
68+
<i class="material-icons" class:error aria-hidden="true">attach_money</i>
6869
<input
6970
{step}
7071
type="number"
@@ -86,7 +87,7 @@ const focus = (node) => autofocus && node.focus()
8687
{disabled}
8788
{placeholder}
8889
/>
89-
{#if error}
90+
{#if showErrorIcon}
9091
<span class="mdc-text-field__affix mdc-text-field__affix--suffix"
9192
><i class="material-icons error" aria-hidden="true">error</i></span
9293
>
@@ -107,8 +108,7 @@ const focus = (node) => autofocus && node.focus()
107108
<div class="mdc-text-field-helper-text" class:opacity1={required} id="{labelID}-helper-id" aria-hidden="true">
108109
{#if required && !internalValue}
109110
<span class="required" class:error={hasFocused}>*Required</span>
110-
{/if}
111-
{#if hasExceededMaxValue}
111+
{:else if hasExceededMaxValue}
112112
<span class="error">Maximum value allowed is {maxValue}</span>
113113
{:else if isLowerThanMinValue}
114114
<span class="error">Minimun value allowed is ({minValue})</span>

Diff for: components/mdc/TextInput/TextArea.svelte

+1-2
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ label {
117117
<div class="mdc-text-field-helper-text" class:opacity1={required} id="{labelID}-helper-id" aria-hidden="true">
118118
{#if required && valueIsEmpty}
119119
<span class="required" class:error={hasFocused}>*Required</span>
120-
{/if}
121-
{#if hasExceededMaxLength}
120+
{:else if hasExceededMaxLength}
122121
<span class="error">Maximum {maxlength} characters</span>
123122
{/if}
124123
</div>

Diff for: components/mdc/TextInput/TextField.svelte

+4-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ let hasFocused = false
2323
2424
$: mdcTextField.value = value
2525
$: hasExceededMaxLength = maxlength && value.length > maxlength
26-
$: error = hasExceededMaxLength
26+
$: error = hasExceededMaxLength || (hasFocused && required && !value)
2727
$: showCounter = maxlength && value.length / maxlength > 0.85
2828
$: value && addOrRemoveInvalidClass(error, element)
2929
@@ -60,7 +60,7 @@ const focus = (node) => autofocus && node.focus()
6060
class:mdc-text-field--disabled={disabled}
6161
bind:this={element}
6262
>
63-
<i class="material-icons" aria-hidden="true">{icon}</i>
63+
<i class="material-icons" class:error aria-hidden="true">{icon}</i>
6464
<input
6565
type="text"
6666
class="mdc-text-field__input"
@@ -79,7 +79,7 @@ const focus = (node) => autofocus && node.focus()
7979
maxlength="524288"
8080
{placeholder}
8181
/>
82-
{#if error}
82+
{#if hasExceededMaxLength}
8383
<span class="mdc-text-field__affix mdc-text-field__affix--suffix"
8484
><i class="material-icons error" aria-hidden="true">error</i></span
8585
>
@@ -101,8 +101,7 @@ const focus = (node) => autofocus && node.focus()
101101
<div class="mdc-text-field-helper-text" class:opacity1={required} id="{labelID}-helper-id" aria-hidden="true">
102102
{#if required && !value}
103103
<span class="required" class:error={hasFocused}>*Required</span>
104-
{/if}
105-
{#if error}
104+
{:else if hasExceededMaxLength}
106105
<span class="error">Maximum {maxlength} characters</span>
107106
{/if}
108107
</div>

0 commit comments

Comments
 (0)