Hide character counter for short messages on mobile

This commit is contained in:
Jack Kingsman
2026-02-20 16:42:04 -08:00
parent d08a113fc8
commit 41bf4eb73a
+33 -3
View File
@@ -166,8 +166,10 @@ export const MessageInput = forwardRef<MessageInputHandle, MessageInputProps>(fu
// For repeater mode, always allow submit (empty = guest login) // For repeater mode, always allow submit (empty = guest login)
const canSubmit = isRepeaterMode ? true : text.trim().length > 0; const canSubmit = isRepeaterMode ? true : text.trim().length > 0;
// Show character counter for messages (not repeater mode or raw) // Show counter for messages (not repeater mode or raw).
// Desktop: always visible. Mobile: only show count after 100 characters.
const showCharCounter = !isRepeaterMode && limits !== null; const showCharCounter = !isRepeaterMode && limits !== null;
const showMobileCounterValue = text.length > 100;
return ( return (
<form <form
@@ -206,7 +208,8 @@ export const MessageInput = forwardRef<MessageInputHandle, MessageInputProps>(fu
</Button> </Button>
</div> </div>
{showCharCounter && ( {showCharCounter && (
<div className="flex items-center justify-end gap-2 text-xs"> <>
<div className="hidden sm:flex items-center justify-end gap-2 text-xs">
<span <span
className={cn( className={cn(
'tabular-nums', 'tabular-nums',
@@ -217,7 +220,8 @@ export const MessageInput = forwardRef<MessageInputHandle, MessageInputProps>(fu
: 'text-muted-foreground' : 'text-muted-foreground'
)} )}
> >
{textByteLen}/{limits!.hardLimit}b{remaining < 0 && ` (${remaining})`} {textByteLen}/{limits!.hardLimit}
{remaining < 0 && ` (${remaining})`}
</span> </span>
{warningMessage && ( {warningMessage && (
<span className={cn(limitState === 'error' ? 'text-red-500' : 'text-yellow-500')}> <span className={cn(limitState === 'error' ? 'text-red-500' : 'text-yellow-500')}>
@@ -225,6 +229,32 @@ export const MessageInput = forwardRef<MessageInputHandle, MessageInputProps>(fu
</span> </span>
)} )}
</div> </div>
{(showMobileCounterValue || warningMessage) && (
<div className="flex sm:hidden items-center justify-end gap-2 text-xs">
{showMobileCounterValue && (
<span
className={cn(
'tabular-nums',
limitState === 'error' || limitState === 'danger'
? 'text-red-500 font-medium'
: limitState === 'warning'
? 'text-yellow-500'
: 'text-muted-foreground'
)}
>
{textByteLen}/{limits!.hardLimit}
{remaining < 0 && ` (${remaining})`}
</span>
)}
{warningMessage && (
<span className={cn(limitState === 'error' ? 'text-red-500' : 'text-yellow-500')}>
{warningMessage}
</span>
)}
</div>
)}
</>
)} )}
</form> </form>
); );