feat(ui): add character counter to controlled Input and Textarea components

Co-authored-by: ragusa-it <196988693+ragusa-it@users.noreply.github.com>
This commit is contained in:
google-labs-jules[bot]
2026-01-30 01:56:58 +00:00
parent f3866fc2de
commit a27a54843e
3 changed files with 21 additions and 0 deletions

View File

@@ -61,3 +61,10 @@
font-size: 0.8125rem;
color: var(--md-sys-color-error);
}
.charCount {
font-size: 0.75rem;
color: var(--md-sys-color-outline);
text-align: right;
font-variant-numeric: tabular-nums;
}

View File

@@ -30,6 +30,11 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(
{...props}
/>
{error && <span id={errorId} className={styles.error}>{error}</span>}
{props.maxLength !== undefined && props.value !== undefined && (
<div className={styles.charCount} aria-hidden="true">
{String(props.value).length} / {props.maxLength}
</div>
)}
</div>
);
}
@@ -66,6 +71,11 @@ export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(
{...props}
/>
{error && <span id={errorId} className={styles.error}>{error}</span>}
{props.maxLength !== undefined && props.value !== undefined && (
<div className={styles.charCount} aria-hidden="true">
{String(props.value).length} / {props.maxLength}
</div>
)}
</div>
);
}