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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user