fix: improve token formatting and aria-label in TokenUsageIndicator

Remove trailing .0 from compact number formatting (1.0K -> 1K, 2.0M -> 2M).
Include total token count in the aria-label when max context is unavailable,
improving screen reader experience.
This commit is contained in:
Marco Beretta 2026-02-08 17:37:47 +01:00
parent dd8da3986a
commit cb6ce42815
No known key found for this signature in database
GPG key ID: D918033D8E74CC11
2 changed files with 5 additions and 2 deletions

View file

@ -4,10 +4,12 @@ import { useLocalize, useTokenUsage } from '~/hooks';
import { cn } from '~/utils';
function formatTokens(n: number): string {
return new Intl.NumberFormat(undefined, {
const formatted = new Intl.NumberFormat(undefined, {
notation: 'compact',
maximumFractionDigits: 1,
}).format(n);
// Remove trailing .0 before suffix (e.g., "1.0K" -> "1K", "2.0M" -> "2M")
return formatted.replace(/\.0(?=[A-Za-z]|$)/, '');
}
interface ProgressBarProps {
@ -209,6 +211,7 @@ const TokenUsageIndicator = memo(function TokenUsageIndicator() {
: localize('com_ui_token_usage_aria_no_max', {
0: formatTokens(inputTokens),
1: formatTokens(outputTokens),
2: formatTokens(totalUsed),
});
// Color based on percentage