Skip to content

Commit 364ddba

Browse files
committed
feat(textinput): use error color on counter and label for maxlength
1 parent 70d3920 commit 364ddba

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

components/mdc/TextInput/TextArea.svelte

+6-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ let textarea = {}
1919
let height = ''
2020
2121
$: hasReachedMaxLength = maxlength && value.length >= maxlength
22+
$: error = hasReachedMaxLength
2223
2324
onMount(() => {
2425
resize()
@@ -52,6 +53,9 @@ const focus = async (node) => {
5253
label {
5354
width: 100%;
5455
}
56+
.error {
57+
color: var(--mdc-theme-status-error, var(--mdc-theme-error)) !important;
58+
}
5559
</style>
5660

5761
<label
@@ -79,14 +83,14 @@ label {
7983
on:blur
8084
/>
8185
{#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>
8387
{/if}
8488
<span class="mdc-notched-outline">
8589
<span class="mdc-notched-outline__leading" />
8690

8791
{#if label}
8892
<span class="mdc-notched-outline__notch">
89-
<span class="mdc-floating-label" id={labelID}>
93+
<span class="mdc-floating-label" class:error id={labelID}>
9094
{label}
9195
</span>
9296
</span>

components/mdc/TextInput/TextField.svelte

+10-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ let mdcTextField = {}
2121
$: mdcTextField.value = value
2222
$: width = `${element.offsetWidth}px`
2323
$: hasReachedMaxLength = maxlength && value.length >= maxlength
24+
$: error = hasReachedMaxLength
25+
$: showCounter = maxlength && value.length / maxlength > 0.85
2426
2527
onMount(() => {
2628
mdcTextField = new MDCTextField(element)
@@ -53,6 +55,9 @@ const focus = (node) => autofocus && node.focus()
5355
float: right;
5456
padding-right: 1rem;
5557
}
58+
.error {
59+
color: var(--mdc-theme-status-error, var(--mdc-theme-error));
60+
}
5661
</style>
5762

5863
<label
@@ -82,7 +87,7 @@ const focus = (node) => autofocus && node.focus()
8287
<span class="mdc-notched-outline__leading" />
8388
{#if label}
8489
<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}>
8691
{label}
8792
</span>
8893
</span>
@@ -94,9 +99,11 @@ const focus = (node) => autofocus && node.focus()
9499
{#if required && !value}
95100
<div class="required d-inline">*Required</div>
96101
{/if}
97-
{#if maxlength}
102+
{#if showCounter}
98103
<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>
100107
</div>
101108
{/if}
102109
</div>

0 commit comments

Comments
 (0)