Skip to content

Commit 44b52dc

Browse files
committed
feat(TextField): make outline red on maxlength
1 parent eba6321 commit 44b52dc

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

components/mdc/TextInput/TextField.svelte

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ let mdcTextField = {}
2020
2121
$: mdcTextField.value = value
2222
$: width = `${element.offsetWidth}px`
23+
$: hasReachedMaxLength = maxlength && value.length >= maxlength
2324
2425
onMount(() => {
2526
mdcTextField = new MDCTextField(element)
@@ -58,6 +59,7 @@ const focus = (node) => autofocus && node.focus()
5859
class="mdc-text-field mdc-text-field--outlined {$$props.class} textfield-radius"
5960
class:mdc-text-field--no-label={!label}
6061
class:mdc-text-field--disabled={disabled}
62+
class:mdc-text-field--invalid={hasReachedMaxLength}
6163
bind:this={element}
6264
>
6365
<i class="material-icons" aria-hidden="true">{icon}</i>
@@ -94,7 +96,7 @@ const focus = (node) => autofocus && node.focus()
9496
{/if}
9597
{#if maxlength}
9698
<div class="mdc-text-field-helper-line">
97-
<div class="mdc-text-field-character-counter">0 / {maxlength}</div>
99+
<div class="mdc-text-field-character-counter">{value.length} / {maxlength}</div>
98100
</div>
99101
{/if}
100102
</div>

0 commit comments

Comments
 (0)